Anda di halaman 1dari 11

K.J.

Somaiya College of Engineering, Mumbai-77

Batch: B3 Roll No. _____________

Tutorial No.10

Grade: AA / AB / BB / BC / CC / CD /DD

Signature of the Staff In-charge with date

Title: Design of FIR filter using different window.

______________________________________________________________________
Aim and Objective of the Experiment:
1) To Design of FIR filter using different window.
______________________________________________________________________
After successful completion of the course student will able to
CO2:- Design digital FIR filters
______________________________________________________________________

Theory:

The window design method does not produce filters that are optimal (in the sense of
meeting the design specifications in the most computationally-efficient fashion), but the
method is easy to understand and does produce filters that are reasonably good. Of all
the hand-design methods, the window method is the most popular and effective.
In brief, in the window method we develop a causal linear-phase FIR filter by
multipying an ideal filter that has an infinite-duration impulse response (IIR) by a
finite-duration window function

where h[n]is the practical FIR filter, hd[n] is the ideal IIR prototype filter, and w[n] is
the finite-duration window function. An important consequence of this operation is
that the DTFTs of hd[n]and w[n] undergo circular convolution in frequency:

1
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77

ALGORITHM:

1. Input specifications from users


2. Obtain the order of filter.
3. Obtain the transfer functions filter.
4. Analyse the designed filter (Magnitude, phase response, group delay, phase
delay, realization, pole/zero plot)
5. Verify the designs using direct Matlab commands

MATLAB CODE: HAMMING WINDOW


clc;clear all;close all;
M = 7;
tau = (M-1)/2;
n=0:M-1; wc=2;
hd=((sin(pi*(n-tau)))./(pi*(n-tau)))-((sin(wc*(n-tau)))./(pi*(n-
tau)));
hd(tau+1)=0.3634;
whamm=hamming(M)';
h=hd.*whamm;
w=0:0.01:pi;
Hw=freqz(h,1,w);
MagHw=abs(Hw);
HwdB=20*log10(MagHw/max(MagHw));
subplot(221); stem(n,hd,'filled');
axis([-1 M -0.4 0.5]);
xlabel ('n');
ylabel('hd(n)');
title ('ideal impulse response');
subplot(222); stem(n,whamm,'filled');
axis([-1 M -0.1 1.2]);
xlabel ('n');
ylabel('w(n)');
title ('hamming');
subplot(223); stem(n,h, 'filled');
axis([-1 M -0.4 0.5]);
xlabel ('n');
ylabel('h(n)');
title ('actual impulse response');
subplot(224); plot(w,HwdB)
axis([0 pi -80 10]);
xlabel ('frequency');
ylabel('db');
title ('magnitude response');

2
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77

3
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77
FIR FILTER DESIGN USING HANNING WINDOW
CODE:

clc;clear all;close all;


M = 7;
tau = (M-1)/2;
n=0:M-1; wc=2;
hd=((sin(pi*(n-tau)))./(pi*(n-tau)))-((sin(wc*(n-tau)))./(pi*(n-tau)));
hd(tau+1)=0.35;
whan=hann(M)';
h=hd.*whan;
w=0:0.01:pi;
Hw=freqz(h,1,w);
MagHw=abs(Hw);
HwdB=20*log10(MagHw/max(MagHw));
subplot(221); stem(n,hd,'filled');
axis([-1 M -0.15 0.5 ]);
xlabel ('n');
ylabel('hd(n)');
title ('ideal impulse response');
subplot(222); stem(n,whan,'filled');
axis([-1 M -0.1 1.2]);
xlabel ('n');
ylabel('w(n)');
title ('hanning');
subplot(223); stem(n,h,'filled');
axis([-1 M -0.15 0.5]);
xlabel ('n');
ylabel('h(n)');
title ('actual impulse response');
subplot(224); plot(w/pi,HwdB)
axis([0 1 -100 10]);
xlabel ('frequency');
ylabel('db');
title ('magnitude response')

4
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77

OUTPUT:

5
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-

MATLAB CODE: BARTLETT WINDOW


clc;clear all;close all;
M = 7;
tau = (M-1)/2;
n=0:M-1; wc=2;
hd=((sin(pi*(n-tau)))./(pi*(n-tau)))-((sin(wc*(n-tau)))./(pi*(n-
tau)));
hd(tau+1)=0.3634;
wbart=bartlett(M);
h=hd.* wbart;
w=0:0.01:pi;
Hw=freqz(h,1,w);
MagHw=abs(Hw);
HwdB=20*log10(MagHw/max(MagHw));
subplot(221); stem(n,hd,'filled');
axis([-1 M -0.4 0.5]);
xlabel ('n');
ylabel('hd(n)');
title ('ideal impulse response');
subplot(222); stem(n,
wbart,'filled'); axis([-1 M -0.1
1.2]); xlabel ('n');
ylabel('w(n)');
title ('Bartlet Window');
subplot(223); stem(n,h, 'filled');
axis([-1 M -0.4 0.5]);
xlabel ('n');
ylabel('h(n)');
title ('actual impulse response');
subplot(224); plot(w,HwdB)
axis([0 pi -80 10]);
xlabel ('frequency');
ylabel('db');
title ('magnitude response');

6
Department of Electronics Engineering

DSP/Jan May 2018


K.J.Somaiya College of Engineering, Mumbai-77
OUTPUT

7
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77

MATLAB CODE: RECTANGULAR WINDOW

clc;clear all;close all;


tau=3;
M=(tau*2)+1;
n=0:M-1;
wc=pi*2;
hd=((sin(wc*(n -tau)))./(pi*(n-tau)));
hd(tau+1)=0.4;
wrect=rectwin(M)';
h=hd.*wrect;
w=0:0.01:pi;
Hw=freqz(h,1,w);
MagHw=abs(Hw);
HwdB=20*log10(MagHw/max(MagHw));
subplot(221);stem(n,hd,'filled');
axis([-1 M -0.15 0.5]);
xlabel ('n');
ylabel('hd(n)');
title ('ideal impulse response');
subplot(222); stem(n,wrect,'filled');
axis([-1 M -0.1 1.2]);
xlabel ('n');
ylabel('w(n)');
title ('rectangular window');
subplot(223);stem(n,h, 'filled');
axis([-1 M -0.15 0.5]);
xlabel ('n');
ylabel('h(n)');
title ('actual impulse response');
subplot(224);
plot(w/pi,HwdB)
xlabel ('Frequency In Pi Units');
ylabel('dB');
title('Magnitude Response')

8
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77

OUTPUT:

9
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77

Post Lab Questions

1. Compare the various types of


windows:
Window type Normalized Passband Stopband Main lobe Side lobe
transition Ripple(dB) Attenuation(dB) width level(dB)
width

Rectangular 0.9/N 0.7416 21 4L -13.5

Hanning 3.1/N 0.0546 44 8L -32

Hamming 3.3/N 0.0194 53 L -43

Blackman 5.5/N 0.0017 74 12L -57

2. Design low pass, high pass, band pass using Hanning , Hamming window
ANS:

1. Define filter specifications.

2. Specify the window functions according to the filter specifications.

3. Compute the filter order required for a given set of specifications.

4. Compute the window function coefficients.


For Hamming window:
w (n) =0.54 − 0.46cos(2nð/N−1), 0 ≤ n ≤ N − 1

0,otherwise

For Hanning Window

w (n) =0.5 − 0.5cos (2nð/N-1) , 0 ≤ n ≤ N –1

0, otherwise

10
Department of Electronics Engineering

DSP/Jan May2018
K.J.Somaiya College of Engineering, Mumbai-77

5.Compute the ideal filter coefficients according to the filter order.

6.Compute FIR filter coefficients according to the obtained window function and ideal
filter coefficients.

7.If the resulting filter has too wide or too narrow transition region, it is necessary to change
the filter order by increasing or decreasing it according to needs, and after that steps 4, 5 and
6 are iterated as many times as needed.

CONCLUSION: Thus we studied MATLAB code and observed the response


for different windows of FIR filter

Date: _____________ Signature of faculty in-charge

11
Department of Electronics Engineering

DSP/Jan May2018

Anda mungkin juga menyukai