Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search


Example LPF Frequency Response Using freqz

Figure 7.2 lists a short matlab program illustrating usage of freqz in Octave (as found in the octave-forge package). The same code should also run in Matlab, provided the Signal Processing Toolbox is available. The lines of code not pertaining to plots are the following:

  [B,A] = ellip(4,1,20,0.5); % Design lowpass filter B(z)/A(z)
  [H,w] = freqz(B,A);        % Compute frequency response H(w)
The filter example is a recursive fourth-order elliptic function lowpass filter cutting off at half the Nyquist limit (``$ 0.5\pi$ '' in the fourth argument to ellip). The maximum passband ripple8.2is 1 dB (2nd argument), and the maximum stopband ripple is 20 dB (3rd arg). The sampled frequency response is returned in the H array, and the specific radian frequency samples corresponding to H are returned in the w (``omega'') array. An immediate plot can be obtained in either Matlab or Octave by simply typing
  plot(w,abs(H));
  plot(w,angle(H));
However, the example of Fig.7.2 uses more detailed ``compatibility'' functions listed in Appendix J. In particular, the freqplot utility is a simple compatibility wrapper for plot with label and title support (see §J.2 for Octave and Matlab version listings), and saveplot is a trivial compatibility wrapper for the print function, which saves the current plot to a disk file (§J.3). The saved freqplot plots are shown in Fig.7.3(a) and Fig.7.3(b).8.3

Figure: Illustration of using freqz from octave-forge (version 2006-07-09) to produce Fig.7.3 (using Octave version = 2.9.7). Also illustrated are a few plotting and plot-saving utilities from Appendix J.

 
[B,A] = ellip(4,1,20,0.5); % Design the lowpass filter
[H,w] = freqz(B,A);        % Compute its frequency response

% Plot the frequency response H(w):
%
figure(1);
freqplot(w,abs(H),'-k','Amplitude Response',...
         'Frequency (rad/sample)', 'Gain');
saveplot('../eps/freqzdemo1.eps');

figure(2);
freqplot(w,angle(H),'-k','Phase Response',...
         'Frequency (rad/sample)', 'Phase (rad)');
saveplot('../eps/freqzdemo2.eps');

% Plot frequency response in a "multiplot" like Matlab uses:
%
figure(3);
plotfr(H,w/(2*pi));
if exist('OCTAVE_VERSION')
  disp('Cannot save multiplots to disk in Octave')
else
  saveplot('../eps/freqzdemo3.eps');
end

Figure: Frequency response of an order 4 elliptic function lowpass filter computed using the matlab listing in Fig.7.2.

\includegraphics{eps/freqzdemo1}
Amplitude Response


\includegraphics{eps/freqzdemo2}
Phase Response


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]  [Comment on this page via email]

``Introduction to Digital Filters with Audio Applications'', by Julius O. Smith III, (September 2007 Edition).
Copyright © 2014-03-23 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA