Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Matlab Commands
If Wn is a two-element vector, Wn = [W1 W2], fir1 returns an order N bandpass filter with
passband W1 < W < W2.
For filters with a passband near Fs/2, e.g., highpass and bandstop filters, N must be even.
By default fir1 uses a Hamming window. Other available windows, including Boxcar, Hanning,
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.
By default, the filter is scaled so the center of the first pass band has magnitude exactly one after
windowing. Use a trailing 'noscale'
B = fir1(N,Wn,'high','noscale'), B = FIR1(N,Wn,wind,'noscale').
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.
1
a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na)
Note that in the example M-file of Listing 1, we must set the pole coefficient array, A, equal to 1,
which implies that a1 = 1, and all the other coefficients, a2, a3, a4,. = 0, since an FIR filter has no
poles.
Listing. Example MATLAB M-file illustrating FIR filter design and evaluation.
f1=500;
f2=1800;
f3=2000;
f4=3200;
y = filter(B,A,x);
2
ylabel('Filtered Sig');
pause;
Enter listing into a Matlab M-file and save as filename.m. Execute the file and verify that it does
what you expect.
(Q1)
a) Explain how the input is generated and which lines of the code do this.
b) Explain the Magnitude and Phase response graphs and what effects these will have on the
signals applied.
c) Explain how the coefficients for the impulse response are achieved.
d) Why have we used a Hamming Window and what effect has this had on the shape of the
output?
e) Compare the differences between the input and output spectra and comment on their shapes.
(Q2) Now modify this M-file to obtain the 16 FIR filter coefficients that correspond to a:
a) 16th order band-pass filter with a pass-band between 800Hz and 2.4 kHz, and a sampling
frequency of 8kHz.
b) 16th order high pass FIR filter with a unity gain pass-band above 2.0kHz, and a sampling
frequency of 8kHz.
Include a printout of each of these sets of FIR coefficients and the graphs it generates in your lab
report.