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


Frequency Response Plots: plotfr.m

Figure J.4 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.4: 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


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 © 2024-09-03 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA