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?

  

Frequency Response Plots: plotfr.m

Figure J.7 lists a Matlab function for plotting frequency-response magnitude and phase. (See also Fig.7.1.) Since Octave does not yet support saving multiple ``subplots'' to disk for later printing, we do not have an Octave-compatible version here. At present, Matlab's graphics support is much more extensive and robust than that in Octave's (which is based on a shaky and Matlab-incompatible interface to gnuplot). Another free alternative to consider for making nice Matlab-style 2D plots is matplotlib.

Figure J.7: Matlab function for plotting frequency-response magnitude and phase.

 
function [plothandle] = plotfr(X,f);
% PLOTFR - Plot frequency-response magnitude & phase.
%          Requires Mathworks Matlab.
%
% X = frequency response
% f = vector of corresponding frequency values

Xm = abs(X);         % Amplitude response
Xmdb = 20*log10(Xm); % Prefer dB for audio work
Xp = angle(X);       % Phase response

if nargin<2, N=length(X); f=(0:N-1)/(2*(N-1)); end
subplot(2,1,1);
plot(f,Xmdb,'-k'); grid;
ylabel('Gain (dB)');
xlabel('Normalized Frequency (cycles/sample)');
axis tight;
text(-0.07,max(Xmdb),'(a)');

subplot(2,1,2);
plot(f,Xp,'-k'); grid;
ylabel('Phase Shift (radians)');
xlabel('Normalized Frequency (cycles/sample)');
axis tight;
text(-0.07,max(Xp),'(b)');

if exist('OCTAVE_VERSION')
  plothandle = 0; % gcf undefined in Octave
else
  plothandle = gcf;
end


Previous: Saving Plots to Disk: saveplot.m
Next: Partial Fraction Expansion: residuez.m

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? )