You are on page 1of 5

LAB ASSIGNMENT 5

SUBMITTED
TO

Prof. Rajesh
Neelakandan
BY

Name: Adhiraj Saxena


Registration Number: 20BEC0298
Course Code: ECE2006
Slot: L29+L30

Adhiraj Saxena
20BEC0298
Aim:Gain response of a FIR Lowpass Filter with different windows .

Program:
clc;clear all; close all;
% Design of a FIR lowpass filter using hamming window
Fp=2000; Fs=2500; dp=0.005; ds=0.005; FT=10000;
% Estimate the Filter Order
N = kaiord(Fp, Fs, dp, ds, FT)
% Design the Filter

[num2,den2] = fir1(N,2250/10000,hamming(N+1));
% Display the transfer function
% disp('Numerator coefficients are ');disp(num);
% disp('Denominator coefficients are ');disp(den);

% Compute the gain response


w = 0:pi/511:pi;
h2 = freqz(num2,den2,w);
g2 = 20*log10(abs(h2));

% Plot the gain response


plot(w/pi,g2,'linewidth',2);grid
legend('hamming');
xlabel('\omega /\pi'); ylabel('Gain, dB');
title('Gain Response of a FIR lowpass filter with different windows');

For Function N:
function N = kaiord(Fp, Fs, dp, ds, FT)
% Computation of the length of a linear-phase
% FIR multiband filter using Kaiser’s formula
% dp is the passband ripple
% ds is the stopband ripple
% Fp is the passband edge in Hz
% Fs is the stopband edge in Hz
% FT is the sampling frequency in Hz.
% If none specified default value is 2
% N is the estimated FIR filter order
if nargin == 4,
FT = 2;
end
if length(Fp) > 1,
TBW = min(abs(Fp(1) - Fs(1)), abs(Fp(2) - Fs(2)));
else
TBW = abs(Fp - Fs);
end

Adhiraj Saxena
20BEC0298
clc;clear all; close all;
% Design of a FIR lowpass filter using hamming window
Fp=2000; Fs=2500; dp=0.005; ds=0.005; FT=10000;
% Estimate the Filter Order
%N = kaiord(Fp, Fs, dp, ds, FT)
N=46;
% Design the Filter

[num2,den2] = fir1(N,2250/10000,hamming(N+1));
% Display the transfer function
% disp('Numerator coefficients are ');disp(num);
% disp('Denominator coefficients are ');disp(den);

% Compute the gain response


w = 0:pi/511:pi;
h2 = freqz(num2,den2,w);
g2 = 20*log10(abs(h2));

% Plot the gain response


plot(w/pi,g2,'linewidth',2);grid
legend('hamming');
xlabel('\omega /\pi'); ylabel('Gain, dB');
title('Gain Response of a FIR lowpass filter with different windows');

Output:

Adhiraj Saxena
20BEC0298
Adhiraj Saxena
20BEC0298
Conclusion: We wrote the MATLAB code to show the gain response of a FIR
Lowpass filter with different windows.

END

Adhiraj Saxena
20BEC0298

You might also like