Digital Signal Processing
Digital Signal Processing
Table of Contents
Prelab ................................................................................................................................
Question:1(a) ......................................................................................................................
Question:1(b) ......................................................................................................................
Question:2 ..........................................................................................................................
Question:3 ..........................................................................................................................
Submitted by: Pinaki Ranjan Sarkar
Sc Code: SC13B110
Roll No: 036
Prelab
f1 = 500;
f2 = 3000;
f3 = 7000;
fs = 8000;
n = 0:4095;
x = 5*cos(2*pi*(f1/fs).*n) + 3*cos(2*pi*(f2/fs).*n) + 4*cos(2*pi*(f3/
fs).*n);
y = fft(x,4096);
t = 8000*linspace(0,1,4096);
stem(t,y);
xlabel('Frequency');
ylabel('Magnitude');
title('Spectrum for Sampled Signal');
Warning: Using only the real component of complex data.
1
2
4
5
7
Question:1(a)
close all
wp = 0.2*pi; ws = 0.35*pi;
tr_width = ws - wp
M = ceil(8*pi/tr_width) + 1
n=[0:1:M-1];
wc = (ws+wp)/2;
hd = ideal_lp(wc,M);
w_ham = (hamming(M))';
h = hd .* w_ham;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
Rp = -(min(db(1:1:wp/delta_w+1)))
As = -round(max(db(ws/delta_w+1:1:501)))
subplot(1,1,1)
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2); stem(n,w_ham);title('Hamming Window')
axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Actual Impulse Response')
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)')
subplot(2,2,4); plot(w/pi,db);title('Magnitude Response in dB');grid
axis([0 1 -100 10]); xlabel('frequency in pi units');
ylabel('Decibels')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[-50,0])
set(gca,'YTickLabelMode','manual','YTickLabels',['50';' 0'])
tr_width =
0.4712
M =
55
Rp =
0.0302
As =
55
Warning: The YTickLabels property will be removed in a future
release.
Warning: The YTickLabels property will be removed in a future
release.
Question:1(b)
With fir1 command
N = 53;
wn = 0.275;
b = fir1(N,wn,'low');
freqz(b)
Question:2
w1 = hanning(31);
e=fir1(30,2*2500/8000,'high',w1);
figure;
freqz(e,1,512);
title('Hanning Window');
e_fix = round (e/max(abs(e)) * (2^(10-1)-1));
w2 = hamming(31);
f=fir1(30,2*2500/8000,'high',w2);
figure;
freqz(f,1,512);
title('Hamming Window');
f_fix = round (f/max(abs(f)) * (2^(10-1)-1));
w3 = blackman(31);
g=fir1(30,2*2500/8000,'high',w3);
figure;
freqz(g,1,512);
title('Blackman Window');
g_fix = round (g/max(abs(g)) * (2^(10-1)-1));
Question:3
clear all;
Fs = 10000;
n = 1:1000;
N = length(n);
x = 5*cos(2*pi*500/Fs.*n)+ 3*cos(2*pi*3000/Fs.*n) + 4*cos(2*pi*7000/
Fs.*n);
xf = abs(fft(x))/N;
w = linspace(0,2*pi,N);
figure;
stem(w,xf);
xlabel('Normalized Frequency');
ylabel('Amplitude');
title('Ampiitude Spectrum');
n1=0:54;
wn = 0.54 - 0.46*cos(2*pi.*n1/54);
hdn = sin(0.7*pi.*(27-n1))./(pi.*(27-n1));
for i=1:55
if(i==28)
hn(i)=0.7;
else
hn(i) = wn(i)*hdn(i);
end
end
figure;
freqz(hn,[1]);
[b,c]=filter(hn,[1],x);
figure;
d=abs(fft(b))/N;
stem(w,d);
xlabel('Normalized Frequency');
ylabel('Amplitude');
title('Ampiitude Spectrum');
10