Digital Signal Processing Reference
In-Depth Information
% Show freq magnitude response for an FIR filter's coefficients
% We assume the number of coefficients is less than 128.
%
function freq_mag_resp(h)
% Zero pad so that the results will look nice
x = h;
x(length(h)+1:128) = 0;
% Get the frequency magnitude response of x
X = fft(x);
X_mag = abs(X);
% Display the results
half = ceil(length(X_mag)/2);
plot(1:half, X_mag(1:half), b);
title(frequency magnitude response);
Filter design is discussed in Chapter 10, \Applications." MATLAB provides
some functions to do this in the signal processing toolbox, including fir1 and fir2.
For example, the graph in Figure 3.21 can be made with the following code. Notice
that this code does much the same thing as the above freq mag resp function, but
with more compact code.
% Get bandstop filter coefficients
B2 = fir1(100, [0.3, 0.5], stop);
x = zeros(1, 1000);
x(50) = 1;
Y2 = fft(conv(x,B2));
half = 1:ceil(length(Y2)/2);
plot(half/max(half), abs(Y2(half)), b);
To make a highpass lter like Figure 3.18, modify the above code to use dierent
lter coecients:
B4 = fir1(100, 0.5, high);
Also, Figure 3.23's frequency magnitude response can be found with the following
lter.
B5 = fir1(100, [0.2, 0.4, 0.6, 0.8], bandpass);
Search WWH ::




Custom Search