DSP Lab Report
DSP Lab Report
Lab-6
Digital Signal Processing
noise = rand(size(x));
xnoise = x + noise;
y1 = maf(x,3);
y2 = maf(x,11);
y3 = maf(x,31);
y4 = maf(x,51);
figure;
subplot(3,2,1);plot(x); title("original signal");
subplot(3,2,2);plot(xnoise); title("signal with noise");
subplot(3,2,3);plot(y1); title("filtered signal with M=3");
subplot(3,2,4);plot(y2); title("filtered signal with M=11");
subplot(3,2,5);plot(y3); title("filtered signal with M=31");
subplot(3,2,6);plot(y4); title("filtered signal with M=51");
n = size(x,2);
y = zeros(1,n);
p = (M-1)/2;
q = p+1;
y_1 = 0;
x_i_p = 0;
x_i_q = 0;
for i = 1:n
if i>1
y_1 = y(1,i-1);
end
if i+p<=n
x_i_p = x(1,i+p);
end
if i-q>=1
x_i_q = x(1,i-q);
end
end
y = y/M;
end
Task 2:
CODE:
y3 = freqResMAF(3);
y11 = freqResMAF(11);
y31 = freqResMAF(31);
y51 = freqResMAF(51);
figure;
plot(y3);
hold on;
plot(y11);
hold on;
plot(y31);
hold on;
plot(y51);
x = linspace(0,.5,200);
y = zeros(size(x));
for i =1:size(x,2)
if x(1,i)~=0
y(1,i) = abs(sin(pi*x(1,i)*M) / (M*sin(pi*x(1,i)))) ;
end
end
end
using a 4x4 subplot. With a suitable MAF kernel, I used convolution to generate 2 pass and 4 pass
kernels.
I have also shown their step responses and Frequency responses in dB.
CODE:
x = zeros(1,24);
x(1,8:16) = 1;
subplot(2,2,1);
y1 = maf(x,9); y2= maf(y1,9);
plot(x,'.-'); hold on;
plot(y1, '.-'); hold on;
plot(y2, '.-'); title("Filter kernel");
x_freq = linspace(0,.5,200);
Y1 = freqResMAF(9);
Y2 = Y1 .* Y1;
Y3 = Y2 .* Y1;
subplot(2,2,2);
plot(x_freq,Y1,'.-'); hold on;
plot(x_freq,Y2, '.-'); hold on;
plot(x_freq,Y3, '.-'); title("Frequency Response");
step_y1 = cumsum(y1);
step_y2 = cumsum(y2);
step_y3 = cumsum(y3);
subplot(2,2,3);
plot(step_y1,'.-'); hold on;
plot(step_y2,'.-'); hold on;
plot(step_y3,'.-'); title("Step Response");
log_Y1 = 20*log(Y1);
log_Y2 = 20*log(Y2);
log_Y3 = 20*log(Y3);
subplot(2,2,4);
plot(x_freq, log_Y1,'.-'); hold on;
plot(x_freq, log_Y2,'.-'); hold on;
plot(x_freq, log_Y3,'.-'); title("Step Response");
Fig : analysis of one pass two pass and four pass MAF kernels.
We can see that, applying the moving average filter multiple times
increases the smoothing or averaging. The stopband attenuation
increases.
Task 4:
I wrote a sinc function and generated a signal x. Then I applied sinc
on x and got y. I plotted x and y.
CODE:
x = linspace(-50,50);
y = sinc(x, .1);
figure;
subplot(1,2,1);plot(x);
subplot(1,2,2);plot(y);
for i =1:size(x,2)
if x(1,i)~=0
y(1,i) = sin(2*pi*f*x(1,i)) / (x(1,i)*pi ) ;
end
end
end
Task 5:
I took the sinc function. And truncated it to the length M. Then I
smoothed it out using the hamming() function. It could have been done
using hamming too.
CODE:
x = linspace(-50,50);
f = .1;
y = sinc(x,f);
%y =[y_(1,:), zeros(1,50)];
Y = abs(fft(y));
x_freq = linspace(0,.5,50);
figure;
subplot(3,2,1);plot(y);
subplot(3,2,2);plot(x_freq,Y(1,1:50));
M = 40;
y_trunc = y;
y_trunc(1,70:100) = 0;
y_trunc = [y_trunc(1,30:100),zeros(1,20)];
Y_trunc = abs(fft(y_trunc));
subplot(3,2,3);plot(y_trunc);
subplot(3,2,4);plot(x_freq,Y_trunc(1,1:50));
CODE:
b = blackman(50);
h = hamming(50);
x = linspace(-50,50);
f = .1;
y = sinc(x,f);
y_h = conv(y, h);
y_b = conv(y,b);
B = abs(fft(y_b));
H = abs(fft(y_h)) ;
x_freq = linspace(0,.5,50);
subplot(2,2,1);plot(h); hold on; plot(b); legend('hamming', 'blackman');
subplot(2,2,2);plot(y_h); hold on; plot(y_b);title('multiplication with
hamming and blackman');
subplot(2,2,3);plot(x_freq,H(1,1:50)); title('frequency response of
hamming');
subplot(2,2,4);plot(x_freq,B(1,1:50)); title('frequency response of
blackman');