0% found this document useful (0 votes)
35 views13 pages

DSP Assignment 3

The document discusses digital signal processing concepts like sampling, aliasing, discrete-time convolution and filtering. It provides instructions for lab exercises on processing input signals through various filters and parameters like filter coefficients and sampling rates and observing the output signals. Filtering of images and music waveforms are also demonstrated.

Uploaded by

gvvvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views13 pages

DSP Assignment 3

The document discusses digital signal processing concepts like sampling, aliasing, discrete-time convolution and filtering. It provides instructions for lab exercises on processing input signals through various filters and parameters like filter coefficients and sampling rates and observing the output signals. Filtering of images and music waveforms are also demonstrated.

Uploaded by

gvvvv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Digital Signal Processing: Assignment 3

1. Pre-Lab
1.4 Sampling and Aliasing DEMO
1.4.a Set the input to x(t)=cos(40πt).
1.4.b Set the sampling rate to fs=24 samples/sec.
1.4.c ω=2π*20/24=5.24.
1.4.d The output frequency is 4Hz.

1.5 Discrete-Time Convolution


1.5.a Click on the Get x[n] button and set the input to a finite-length pulse: x[n]=(u[n]-u[n-10])
1.5.b Set the filter to a three-point averager by using the Get h[n] button to create the correct impulse
response for the three-point averager.
2. Warm-up
2.1 Sampling and Aliasing
2.1.a Input frequency is 12 Hz.
2.1.b Sampling frequency is 15 Hz.
2.1.c The output frequency is 3Hz.
2.1.d ω=2π*12/15=5.

2.1.e Change the sampling frequency to 12 Hz. The output signal is flat line.

2.2 Discrete-Time Convolution


2.2.a Set the input signal to be x[n]=(0.9)^n(u[n]-u[n-10]).
2.2.b Set the impulse response to be h[n]=δ[n]-0.9δ[n-1].
2.2.c Illustrate the output signal y[n] and explain why it is zero for almost all points. Compute the
numerical value of the last point in y[n], i.e., the one that is negative and non-zero.
2.3 Loading Data
bb = 1/5*ones(1,5);
xx = [ones(1,10),zeros(1,5)];
yy = firfilt(bb, xx); %<--Compute the output
nn = 1:length(xx); %--- use first=1 and last=length(xx)
subplot(2,1,1);
stem(nn,xx(nn))
subplot(2,1,2);
stem(nn,yy(nn),'filled') %--Make black dots
xlabel('Time Index (n)')
2.4 Filtering signal
2.4.a
2.4.b

2.4.c 30 points from middle of the signal


2.5 Filtering images: 2-D Convolution
Original image

2.5.a image filtered in horizontal direction:


2.5.b image filtered in vertical direction:

3. FIR Filters
3.1.a

3.1.b
3.1.1.Restoration Filter

3.1.2 Worst-Case Error

3.1.2.b The plot shows consistency almost all throughout except from a range of about 23-33. I
would assume that the quality of restoration, as per the graph is a very good one.

3.1.3 An Echo Filter


y[n]=x[n]+rx[n-P]
fs=8000
for x(t) and x[n] is t=n*Ts.
x[n-P] = x((n-P)*Ts) = x(n*Ts-P*Ts) = x(t-P*Ts)
P*Ts=0.2
P*(1/8000)=0.2
P = 1600
We will assume that the strength of the original signals is A=1, and r = 1*(0.9) = 0.9. Then, the
filter coefficients are bb and length of bb is 1601.
P+1 = 1601
bb = [1,zeros(1,1599),0.9];
length(bb)
3.2.1 Overall Impulse Response
3.2.2 Distorting and Resorting images

Ghosting is caused by convolution calculations in matlab. The resulting image is of course not
the same as the original image. This is because at a specific point it was delayed. The last value
of the process was not equal, so it produced the value for the input.
3.2.3 M=11 M=22 M=33 M=44 M=55 M=66

As M increases, images get focused and stop ghosting.

3.3 Filtering a Music Waveform


clear,clc;
% % % nn = 0:99; %<--Time indices
% % % xx = cos( 0.08*pi*nn ); %<--Input signal
% % % bb = [1/3 1/3 1/3]; %<--Filter coefficients
% % % yy = firfilt(bb, xx); %<--Compute the output
%%
% % 2.4.1
% bb = 1/5*ones(1,5);
% xx = [ones(1,10),zeros(1,5)];
% yy = firfilt(bb, xx); %<--Compute the output
% nn = 1:length(xx); %--- use first=1 and last=length(xx)
% % subplot(2,1,1);
% % stem(nn,xx(nn))
% % subplot(2,1,2);
% % stem(nn,yy(nn),'filled') %--Make black dots
% % xlabel('Time Index (n)')

% % 2.5.a
% data=load('echart.mat');
% bb = 1/5*ones(1,5);
% a=data.echart;
% show_img(a);
% b=firfilt(bb,a);
% % 2.5.b
% bdiffh=[1, -1];
% yy1=conv2(a,bdiffh);
% show_img(yy1);
% yy2=conv2(a,bdiffh');
% show_img(yy2);

% nn = 1:length(a);
% subplot(2,1,1);
% stem(nn,data.x1(nn))
% xlim([35 65])
% subplot(2,1,2);
% stem(nn,b(nn),'filled') %--Make black dots
% xlim([35 65])
% xlabel('Time Index (n)')

% w[n]=x[n]-0.9x[n-1];

% % 3.1
% xx = 256*(rem(0:100,50)<10);
% bb = [1,-0.9];
% nn = [0:75];
% subplot(2,1,1);
% stem(nn,xx(nn+1));
% xlabel('Time Index [n]')
% ylabel('xx Output')
% subplot(2,1,2);
% ww = firfilt(bb,xx);
% stem(nn,ww(nn+1),'Filled');
% xlabel('Time Index [n]');
% ylabel('ww Output');

% % 3.1.1
% xx = 256*(rem(0:100,50)<10);
% bb = [1,-0.9];
% nn = (0:75);
% subplot(2,1,1);
% ww = firfilt(bb,xx);
% stem(nn,ww(nn+1),'filled')
% xlabel('Time Index[n]')
% ylabel('ww Output')
% M = 22;
% r = 0.9;
% l = 0:M;
% yy = firfilt((r.^l),ww);
% subplot(2,1,2);
% stem(nn,yy(nn+1),'Filled');
% xlabel('Time Index[n]')
% ylabel('yy Output')

% % 3.1.2
% xx = 256*(rem(0:100,50)<10);
% bb = [1,-0.9];
% nn = (0:49);
% subplot(3,1,1);
% stem(nn,xx(nn+1))
% xlabel('Time Index(n)')
% ylabel('xx Input')
% ww = firfilt(bb,xx);
% M = 22;
% r = 0.9;
% l = 0:M;
% yy = firfilt((r.^l),ww);
% subplot(3,1,2);
% stem(nn,yy(nn+1),'Filled');
% xlabel('Time Index[n]')
% ylabel('yy Output')
% zz(nn+1)= xx(nn+1)-yy(nn+1);
% subplot(3,1,3);
% plot(nn,zz(nn+1));
% title('Worst case error b/w xx and yy ');
% max(abs(zz(nn+1)))
% bb = [1,zeros(1,1599),0.9];
% length(bb)

% load labdat
% xx = x2;
% bb = [1,zeros(1,1599),0.9];
% nn = [0: length(xx)];
% yy = firfilt(bb,xx);
% subplot(2,1,1);
% stem(xx);
% ylabel('Speech')
% subplot(2,1,2);
% stem(nn,yy(nn+1));
% xlabel('Time Index[n]');
% ylabel('Speech Echo');
% sound(yy(nn+1));

% % 3.2.1.a
% bb1 = [1,-0.9];
% imp = 1;
% M = 22;
% r = 0.9;
% l = 0:M;
% bb2 = r.^l;
% HH = firfilt(bb1,bb2);
% XX = firfilt(HH,imp);
% nn = 0:(length(HH)-1);
% stem(nn,XX(nn+1));
% xlabel('Time Index [n]')
% ylabel('Impulse Response')

% 3.2.2
data=load('echart.mat');
bb = [1,-0.9];
yy = conv2(data.echart,bb);
ech90 = conv2(yy,bb');
% show_img(ech90);

M = 11;
r = 0.9;
l = 0:M;
bb2 = r.^l;
zz = conv2(ech90,bb2);
ech90_filter2 = conv2(zz,bb2');
show_img(ech90_filter2);

You might also like