0% found this document useful (0 votes)
27 views11 pages

Emaan Ishtiaq DSP Lab 6

The document discusses digital signal processing and includes code to generate and analyze signals. It contains code to generate a noisy cosine signal, take the FFT of the noisy and clean signals, and apply a low pass filter. It also contains code to analyze impulse responses and filter designs using different values for filter order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views11 pages

Emaan Ishtiaq DSP Lab 6

The document discusses digital signal processing and includes code to generate and analyze signals. It contains code to generate a noisy cosine signal, take the FFT of the noisy and clean signals, and apply a low pass filter. It also contains code to analyze impulse responses and filter designs using different values for filter order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Digital Signal Processing

Lab Report: 06

SUBMITTED TO:
Ma’am Sundas

SUBMITTED BY:

Student Name: Emaan Ishtiaq


Reg # 00000384604
DE-43 (C&SE)- A
Submission Date: 25-03-2024

DEPARTMENT OF COMPUTER ENGINEERING COLLEGE OF

E&ME, NUST, RAWALPINDI

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

% for an ideal lowpass filter impluse repsponse is sin(n * wc)/(n *


pi)
syms w
wc = pi/3;
interval = -pi:(pi/100):pi;

% 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)

function [f] = lowpass_filter(wc, M)


syms w
f=0;

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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy