Sujatha Mam Lab Manual 2
Sujatha Mam Lab Manual 2
Niveddita J
2018105572
Aim:
To design FIR filters such as low pass filter, high pass filter, band
pass filter and band stop filter and to plot the magnitude and phase
response using MATLAB software for the following specifications.
Software Required:
MATLAB
MATLAB CODE:
m=1
for i=(round((1-M)/2)):1:(ceil((M-1)/2));
if i==0
hd(m)=wc/pi
else
hd(m)=(wc*sin(wc*i))/(wc*i*pi)
end
w(m)=1
m=m+1;
end
figure(1);
subplot(411)
stem(n,hd);
xlabel('n')
ylabel('Amplitude')
title('hd[n]-Desired Response')
subplot(412)
stem(n,w);
xlabel('n')
ylabel('Amplitude')
ylim([0 2])
title('w[n]-Rectangular Window')
h=hd.*w
subplot(413)
stem(n,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Non-Causal)')
subplot(414)
stem(k,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Causal)')
figure(2);
freqz(h)
title('Magnitude and Phase Response of the filter')
2. Design a FIR high pass filter for the following
specifications using Hamming window:
Pass band edge frequency=150Hz
Stop band edge frequency=100Hz
Sampling frequency=1000Hz
Pass band attenuation= 0.25 dB
Stop band ripple≤ 𝟓𝟎
m=1
for i=(round((1-M)/2)):1:(ceil((M-1)/2));
if i==0
hd(m)=1-wc/pi
else
hd(m)=-1*(wc*sin(wc*i))/(wc*i*pi)
end
w(m)=0.54+0.46*cos((2*pi*i)/(M-1))
m=m+1;
end
figure(1);
subplot(411)
stem(n,hd);
xlabel('n')
ylabel('Amplitude')
title('hd[n]-Desired Response')
subplot(412)
stem(n,w);
xlabel('n')
ylabel('Amplitude')
ylim([0 2])
title('w[n]-Hamming Window')
h=hd.*w
subplot(413)
stem(n,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Non-Causal)')
subplot(414)
stem(k,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Causal)')
figure(2);
freqz(h)
title('Magnitude and Phase Response of the filter')
3. Design a FIR band pass filter for the following
specifications using Hanning window:
Lower stopband =0-300Hz
Passband range=400-600Hz
Upper stopband =800-1000Hz
Sampling frequency=2000Hz
Stopband attenuation=40 dB
Passband ripple=3 dB
figure(1);
subplot(411)
stem(n,hd);
xlabel('n')
ylabel('Amplitude')
title('hd[n]-Desired Response')
subplot(412)
stem(n,w);
xlabel('n')
ylabel('Amplitude')
ylim([0 2])
title('w[n]-Hanning Window')
h=hd.*w
subplot(413)
stem(n,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Non-Causal)')
subplot(414)
stem(k,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Causal)')
figure(2);
freqz(h)
title('Magnitude and Phase Response of the filter')
4. Design a FIR band stop filter for the following
specifications using Blackman window:
Lower stopband edge frequency=800Hz
Upper stopband edge frequency=1100Hz
Lower passband edge frequency=700Hz
Upper passband edge frequency=1250Hz
Sampling frequency=3200Hz
Stopband attenuation=60 dB
Passband ripple=3 dB
figure(1);
subplot(411)
stem(n,hd);
xlabel('n')
ylabel('Amplitude')
title('hd[n]-Desired Response')
subplot(412)
stem(n,w);
xlabel('n')
ylabel('Amplitude')
ylim([0 2])
title('w[n]-Blackman Window')
h=hd.*w
subplot(413)
stem(n,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Non-Causal)')
subplot(414)
stem(k,h)
xlabel('n')
ylabel('Amplitude')
title('h[n](Causal)')
figure(2);
freqz(h)
title('Magnitude and Phase Response of the filter')
5. Multitone signal is given as input to FIR filter. Multitone signal
is given as input to FIR low pass filter and FIR high pass filter.
Specifications:
Multitone signal, x(t)=asin(2ϖf1t)+bsin(2ϖf2t)
f1=70Hz
f2=200Hz
F sampling=1200Hz
Filter specifications:
LPF:
ꞷp=0.1ϖ rad/sample
ꞷs=0.3ϖ rad/sample
αp=1 dB
αs=20 dB
HPF:
ꞷp=0.3ϖ rad/sample
ꞷs=0.1ϖ rad/sample
αp=1 dB
αs=20 dB
H1=fir1(int8(M1-1),wc/pi,'low',rectwin(M1))
H2=fir1(int8(M2-1),wc/pi,'low',hann(M2))
H3=fir1(int8(M3-1),wc/pi,'low',hamming(M3))
H4=fir1(int8(M4-1),wc/pi,'low',blackman(M4))
%Filtered Output
y1=filter(H1,1,xn)
Y1=fft(y1)
y2=filter(H2,1,xn)
Y2=fft(y2)
y3=filter(H3,1,xn)
Y3=fft(y3)
y4=filter(H4,1,xn)
Y4=fft(y4)
%Magnitude and Phase response of the filter
figure(1);
freqz(H1)
title('Magnitude and Phase Response of FIR LPF-Rectangular
Window')
figure(2);
freqz(H2)
title('Magnitude and Phase Response of FIR LPF-Hanning
Window')
figure(3);
freqz(H3)
title('Magnitude and Phase Response of FIR LPF-Hamming
Window')
figure(4)
freqz(H4)
title('Magnitude and Phase Response of FIR LPF-Blackman
Window')
figure(5)
subplot(4,3,1)
plot(t,x)
xlabel('Time')
ylabel('Amplitude')
title('x(t)=Asin(2*pi*f1*t)+Bsin(2*pi*f2*t)');
subplot(4,3,2)
stem(n,xn)
xlabel('n')
ylabel('Amplitude')
title('x(n)=Asin((2*pi*f1*n)/Fs)+Bsin((2*pi*f2*n)/Fs)');
subplot(4,3,3)
stem(n,abs(X))
xlabel('k')
ylabel('Amplitude')
title('X(K)=FFT of x[n]');
subplot(4,3,4)
stem(n,abs(Y1))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using LPF-Rectangular window')
subplot(4,3,5)
plot(y1)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using LPF-Rectangular window');
subplot(4,3,6)
stem(n,abs(Y2))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using LPF-Hanning window')
subplot(4,3,7)
plot(y2)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using LPF-Hanning window');
subplot(4,3,8)
stem(n,abs(Y3))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using LPF-Hamming window')
subplot(4,3,9)
plot(y3)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using LPF-Hamming window');
subplot(4,3,10)
stem(n,abs(Y4))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using LPF-Blackman window')
subplot(4,3,11)
plot(y4)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using LPF-Blackman window');
b) Multitone signal is given as input to FIR high pass filter
H1=fir1(int8(M1-1),wc/pi,'high',rectwin(M1))
H2=fir1(int8(M2-1),wc/pi,'high',hann(M2))
H3=fir1(int8(M3-1),wc/pi,'high',hamming(M3))
H4=fir1(int8(M4-1),wc/pi,'high',blackman(M4))
%Filtered Output
y1=filter(H1,1,xn)
Y1=fft(y1)
y2=filter(H2,1,xn)
Y2=fft(y2)
y3=filter(H3,1,xn)
Y3=fft(y3)
y4=filter(H4,1,xn)
Y4=fft(y4)
%Magnitude and Phase response of the filter
figure(1);
freqz(H1)
title('Magnitude and Phase Response of FIR HPF-Rectangular
Window')
figure(2);
freqz(H2)
title('Magnitude and Phase Response of FIR HPF-Hanning
Window')
figure(3);
freqz(H3)
title('Magnitude and Phase Response of FIR HPF-Hamming
Window')
figure(4)
freqz(H4)
title('Magnitude and Phase Response of FIR HPF-Blackman
Window')
figure(5)
subplot(4,3,1)
plot(t,x)
xlabel('Time')
ylabel('Amplitude')
title('x(t)=Asin(2*pi*f1*t)+Bsin(2*pi*f2*t)');
subplot(4,3,2)
stem(n,xn)
xlabel('n')
ylabel('Amplitude')
title('x(n)=Asin((2*pi*f1*n)/Fs)+Bsin((2*pi*f2*n)/Fs)');
subplot(4,3,3)
stem(n,abs(X))
xlabel('k')
ylabel('Amplitude')
title('X(K)=FFT of x[n]');
subplot(4,3,4)
stem(n,abs(Y1))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using HPF-Rectangular window')
subplot(4,3,5)
plot(y1)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using HPF-Rectangular window');
subplot(4,3,6)
stem(n,abs(Y2))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using HPF-Hanning window')
subplot(4,3,7)
plot(y2)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using HPF-Hanning window');
subplot(4,3,8)
stem(n,abs(Y3))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using HPF-Hamming window')
subplot(4,3,9)
plot(y3)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using HPF-Hamming window');
subplot(4,3,10)
stem(n,abs(Y4))
xlabel('k')
ylabel('Amplitude')
title('Y1(k)=Filtered X(k) using HPF-Blackman window')
subplot(4,3,11)
plot(y4)
xlabel('Time')
ylabel('Amplitude')
title('y1(t)=Filtered x(t) using HPF-Blackman window');
Procedure:
Result:
Design of FIR filters such as low pass filter, high pass filter,
band pass filter and band stop filter is performed for the given
specifications and the magnitude and phase response are plotted using
the MATLAB software.