Emaan Ishtiaq DSP Lab 6
Emaan Ishtiaq DSP Lab 6
Lab Report: 06
SUBMITTED TO:
Ma’am Sundas
SUBMITTED BY:
Task:
Task no:1
Code:
%1
a = 5;
f = 5;
t = 0:(1/5000):1;
y =a*cos(2*pi*f*t);
subplot(4, 2, 1); plot(t, y); title("Cosine signal");
%2
noisy_signal = awgn(y, 10);
subplot(4, 2, 2); plot(t, noisy_signal); title("Noisy signal");
%3
fft_y = abs(fft(y));
fft_noisy = abs(fft(noisy_signal));
subplot(4, 2, 3);
plot(fft_y);
xlim([-1000 10000]);
title("Cosine fft");
subplot(4, 2, 4);
plot(fft_noisy);
xlim([-1000 10000]);
title("Fft noisy signal");
subplot(4, 2, 5);
plot(fft_y);
xlim([0 100]);
title("Cosine fft: 100 Samples");
subplot(4, 2, 6);
plot(fft_noisy);
xlim([0 100]);
title("Fft noisy signal: 100 Samples");
%4
% Low Pass Filter
Fs=5000;
Rp1=0.5;
Rs1=30;
Fp1=0.1e2/(Fs/2);
Fs1=0.5e2/(Fs/2);
n1=cheb1ord(Fp1,Fs1,Rp1,Rs1);
[a,b]=cheby1(n1,Rp1,Fp1,'low');
h = filter(a,b,y);
subplot(4, 2, 7:8); plot(t, h);
title("Filtered Signal")
Output:
Task no:2
Code:
clc
%1
h = [zeros(1, 6) 1 2 3 2 1 zeros(1, 6)];
n = -8:8;
subplot(4, 1, 1);
stem(n, h);
ylabel("h[n]");
xlabel("n");
[f, w] = freqz(h);
subplot(4, 1, 2);
plot(w, real(f));
title("Frequency Response");
subplot(4, 1, 3);
plot(w/pi,20*log10(abs(f)));
title("Magnitude Response");
ylabel("Magnitude")
subplot(4, 1, 4);
plot(w, unwrap(angle(f))*180/pi);
title("Phase Response");
ylabel("Phase")
%2
figure
h = [zeros(1, 8) 1 2 3 2 1 zeros(1, 4)];
n = -8:8;
subplot(4, 1, 1);
stem(n, h);
ylabel("h[n]");
xlabel("n")
[f, w] = freqz(h);
subplot(4, 1, 2);
plot(w, real(f));
title("Frequency Response");
subplot(4, 1, 3);
plot(w/pi,20*log10(abs(f)));
title("Magnitude Response");
ylabel("Magnitude")
subplot(4, 1, 4);
plot(w, unwrap(angle(f))*180/pi);
title("Phase Response");
ylabel("Phase")
Output:
Task no:3
Code:
clc
% M = 5
figure
filter = lowpass_filter(wc, 5);
filtered_signal = double(subs(filter, w, interval));
inverse = ifft(filtered_signal);
freqz(inverse)
% M = 9
figure
filter = lowpass_filter(wc, 9);
filtered_signal = double(subs(filter, w, interval));
inverse = ifft(filtered_signal);
freqz(inverse)
% M = 15
figure
filter = lowpass_filter(wc, 15);
filtered_signal = double(subs(filter, w, interval));
inverse = ifft(filtered_signal);
freqz(inverse)
% M = 35
figure
filter = lowpass_filter(wc, 35);
filtered_signal = double(subs(filter, w, interval));
inverse = ifft(filtered_signal);
freqz(inverse)
for n = -M:M
if n == 0
f = f + wc/pi;
continue
else
f = f + sin(wc * n) * exp(-1i * w * n)/(n * pi);
end
end
end
Output: