Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books

Sponsor

Industry's highest performing at the lowest power DSPs now as low as $5.00*
Start development today!
*volume pricing for 10ku

Chapters

See Also

Embedded SystemsFPGAElectronics
Chapter Contents:

Search Introduction to Digital Filters

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

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


Previous: Frequency Response in Matlab
Next: Phase and Group Delay

Order a Hardcopy of Introduction to Digital Filters


About the Author: Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See http://ccrma.stanford.edu/~jos/ for details.


Comments


No comments yet for this page


Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )