# Design of FIR filters of  Low pass and high pass filter  using Matlab commands

AIM : Design of FIR filters of  Low pass and high pass filter  using Matlab commands

EQUIPMENTS:

Operating System - Windows XP

Constructor - Simulator

Software - CCStudio 3 & MATLAB 7.5

Description: Digital filters refers to the hard ware and software implementation of the mathematical algorithm which accepts a digital signal as input and produces another digital signal as output whose wave shape, amplitude and phase response has been modified in a specified manner. Digital filter play very important role in DSP. Compare with analog filters they are preferred in number of application due to following advantages.

? Truly linear phase response

? Better frequency response

? Filtered and unfiltered data remains saved for further use.

There are two type of digital filters.

? FIR (finite impulse response) filter

? IIR (infinite impulse response) filter

Description Of The Commands Used In FIR Filter Design

FIR1: FIR filters design using the window method.

B = FIR1(N,Wn) designs an N'th order low

pass FIR digital filter and returns the filter coefficients in length N+1 vector B. The cut-

off frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the

sample rate.  The filter B is real and has linear phase.  The normalized gain of the filter

at Wn is -6 dB.

B = FIR1(N,Wn,'high') designs an N'th order highpass filter.

You can also use B = FIR1(N,Wn,'low') to design a lowpass filter.

If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with passband  W1 < W < W2.

B = FIR1(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2]. You can also specify If Wn is a multi-element vector, Wn = [W1 W2 W3 W4 W5 ... WN], FIR1 returns an order N multiband filter with bands 0 < W < W1, W1 < W < W2, ..., WN < W < 1.

B = FIR1(N,Wn,'DC-1') makes the first band a passband.

B = FIR1(N,Wn,'DC-0') makes the first band a stopband.

By default FIR1 uses a Hamming window.  Other available windows, including Boxcar, Hann, Bartlett, Blackman, Kaiser and Chebwin can be specified with an optional trailing argument.

For example, B = FIR1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with beta=4.

B = FIR1(N,Wn,'high', chebwin(N+1,R)) uses a Chebyshev window.

For filters with a gain other than zero at Fs/2, e.g., highpass and bandstop filters, N must

be even.  Otherwise, N will be incremented by one.  In this case the window length

should be specified as N+2.

By default, the filter is scaled so the center of the first pass band has magnitude exactly one after windowing. Use a trailing 'noscale' argument to prevent this scaling, e.g.

B = FIR1(N,Wn,'noscale')

B = FIR1(N,Wn,'high','noscale')

B = FIR1(N,Wn,wind,'noscale').

You can also specify the scaling explicitly, e.g. FIR1(N,Wn,'scale'), etc.

FREQZ  Digital  Filter  Frequency  Response.

[H,W] = FREQZ(B,A,N) returns the N-point complex frequency response vector H and

the N-point frequency vector W in radians/sample of the filter: given numerator and

denominator coefficients in vectors B and A. The frequency response is evaluated at N

points equally spaced around the upper half of the unit circle. If N isn't specified, it

defaults to 512.

[H,W] = FREQZ(B,A,N,'whole') uses N points around the whole unit circle.

H = FREQZ(B,A,W) returns the frequency response at frequencies  designated in vector W, in radians/sample (normally between 0 and pi).

[H,F] = FREQZ(B,A,N,Fs) and [H,F] = FREQZ(B,A,N,'whole',Fs) return frequency vector F (in Hz), where Fs is the sampling frequency (in Hz).

H = FREQZ(B,A,F,Fs) returns the complex frequency response at the frequencies designated in vector F (in Hz), where Fs is the sampling frequency (in Hz).

[H,W,S] = FREQZ(...) or [H,F,S] = FREQZ(...) returns plotting information to be used with FREQZPLOT.  S is a structure whose fields can be altered to obtain different frequency response plots.  For more information see the help for FREQZPLOT.

FREQZ(B,A,...) with no output arguments plots the magnitude and unwrapped phase of the filter in the current figure window.

Designing   A Low Pass Filter:

Program:

%Suppose the  target is to pass all frequencies below 1200 Hz

fs=8000; % sampling frequency

n=50;   % order of the filter

w=1200/ (fs/2);

b=fir1(n,w,'low'); % Zeros of the filter

freqz(b,1,128,8000); % Magnitude and Phase Plot of the filter figure(2)

[h,w]=freqz(b,1,128,8000);

subplot(2,1,1);

plot(w,abs(h));% Normalized Magnitude Plot

title('Normalized Magnitude Plot');

grid

subplot(2,1,2);

figure(2)

zplane(b,1);       %  the plot in lab

title('zplane');

Output:

Designing High Pass Filter:

%Now the  target is to pass all frequencies above 1200 Hz

fs=8000;

n=50;

w=1200/ (fs/2);

b=fir1(n,w,'high');

freqz(b,1,128,8000); % this function plots the phase(degree)and magnitude in db

subplot(2,1,2)

figure(2)

[h,w]=freqz(b,1,128,8000);

plot(w,abs(h)); % Normalized Magnitude Plot

title('Magnitude Plot ');

grid

figure(3)

zplane(b,1); % this function plots fiq in zplane

Output:

Designing High Pass Filter:

fs=8000;

n=50;

w=1200/ (fs/2);

b=fir1(n,w,'high');

freqz(b,1,128,8000);

figure(2)

[h,w]=freqz(b,1,128,8000);

plot(w,abs(h)); % Normalized Magnitude Plot

grid

figure(3)

zplane(b,1);

Designing Band Pass Filter:

fs=8000;

n=40;

b=fir1(n,[1200/4000 1800/4000],’bandpass’); freqz(b,1,128,8000)

figure(2)

[h,w]=freqz(b,1,128,8000);

plot(w,abs(h)); % Normalized Magnitude Plot

grid

figure(3)

zplane(b,1);

Designing Notch Filter

fs=8000;

n=40;

b=fir1(n,[1500/4000 1550/4000],'stop'); freqz(b,1,128,8000)

figure(2)

[h,w]=freqz(b,1,128,8000);

plot(w,abs(h)); % Normalized Magnitude Plot

grid

figure(3)

zplane(b,1);

Designing Multi Band Filter

n=50;

w=[0.2 0.4 0.6];

b=fir1(n,w);

freqz(b,1,128,8000) figure(2)

[h,w]=freqz(b,1,128,8000);

plot(w,abs(h)); % Normalized Magnitude Plot

grid

figure(3)

zplane(b,1);

RESULT:  The FIR low pass & high pass filter for    given values   is obtained. Hence the ideal  and  practical response of FIR filter  are proved.

VIVA QUESTION:

1.  What is filter?
2.  What is FIR and IIR filter define, and distinguish between these two?
3.  What is window method? How you will design an FIR filter using window method?
4.  What are low-pass and band-pass filter and what is the difference between these two?
5.  What is the matlab command for Hamming window? Explain.
6.  What do you mean by built in function ‘abs’ and where it is used?
7.  Explain how the FIR filter are stable?
8.  Why is the impulse response "finite"?
9.  What does "FIR" mean?
10.  What are the advantages of FIR Filters (compared to IIR filters)?
11.  What are the disadvantages of FIR Filters (compared to IIR filters)?
12.  What terms are used in describing FIR filters?
13.  What is the delay of a linear-phase FIR?
14.  What is the Z transform of a FIR filter?
15.  What is the frequency response formula for a FIR filter?
16.  How Can I calculate the frequency response of a FIR using the Discrete Fourier Transform (DFT)?
17.  What is the DC gain of a FIR filter?

• Created
Feb 03, 2020
• Updated
Feb 03, 2020
• Views
2,102
You May Like