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
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:
%Suppose the target is to pass all frequencies below 1200 Hz
fs=8000; % sampling frequency
n=50; % order of the filter
b=fir1(n,w,'low'); % Zeros of the filter
freqz(b,1,128,8000); % Magnitude and Phase Plot of the filter figure(2)
plot(w,abs(h));% Normalized Magnitude Plot
title('Normalized Magnitude Plot');
zplane(b,1); % the plot in lab
Designing High Pass Filter:
%Now the target is to pass all frequencies above 1200 Hz
freqz(b,1,128,8000); % this function plots the phase(degree)and magnitude in db