# HG changeset patch # User Mike Miller # Date 1392267610 18000 # Node ID 694e8f0b3862c53c84af76529950358796fcdcc4 # Parent ff7e7928f1608025db396f471ab070859edad76c freqz: Make frequency response plot visually compatible with Matlab (bug #41464) * freqz_plot.m: Eliminate the extraneous "pass band" subplot for visual compatibility with Matlab. Use y-axis labels instead of legends. Always autoscale the y-axis. Label the frequency axis in units of normalized radians or Hz depending on a new optional argument. * freqz.m: Tell freqz_plot whether the frequency vector is in normalized radians or Hz. diff -r ff7e7928f160 -r 694e8f0b3862 scripts/signal/freqz.m --- a/scripts/signal/freqz.m Mon Feb 10 13:00:44 2014 -0200 +++ b/scripts/signal/freqz.m Thu Feb 13 00:00:10 2014 -0500 @@ -109,11 +109,14 @@ endif endif if (isempty (Fs)) + freq_norm = true; if (nargout == 0) Fs = 2; else Fs = 2*pi; endif + else + freq_norm = false; endif a = a(:); @@ -171,7 +174,7 @@ f_r = f; else ## Plot and don't return values. - freqz_plot (f, h); + freqz_plot (f, h, freq_norm); endif endfunction diff -r ff7e7928f160 -r 694e8f0b3862 scripts/signal/freqz_plot.m --- a/scripts/signal/freqz_plot.m Mon Feb 10 13:00:44 2014 -0200 +++ b/scripts/signal/freqz_plot.m Thu Feb 13 00:00:10 2014 -0500 @@ -17,15 +17,18 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h}) -## Plot the pass band, stop band and phase response of @var{h}. +## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h}) +## @deftypefnx {Function File} {} freqz_plot (@var{w}, @var{h}, @var{freq_hz}) +## Plot the pass band, stop band and phase response of @var{h}. If the +## optional @var{freq_norm} argument is true, the frequency vector @var{w} +## is in units of normalized radians and the x-axis is labeled as such. ## @end deftypefn ## Author: Paul Kienzle -function freqz_plot (w, h) +function freqz_plot (w, h, freq_norm = false) - if (nargin != 2) + if (nargin < 2 || nargin > 3) print_usage (); endif @@ -38,30 +41,26 @@ mag = 20 * log10 (abs (h)); phase = unwrap (arg (h)); - maxmag = max (mag); - subplot (3, 1, 1); - plot (w, mag); - grid ("on"); - legend ("Pass band (dB)"); - axis ([w(1), w(n), maxmag-3, maxmag], "labely"); + if (freq_norm) + x_label = "Normalized Frequency (\\times\\pi rad/sample)"; + else + x_label = "Frequency (Hz)"; + endif - subplot (3, 1, 2); + subplot (2, 1, 1); plot (w, mag); grid ("on"); - legend ("Stop band (dB)"); - if (maxmag - min (mag) > 100) - axis ([w(1), w(n), maxmag-100, maxmag], "labely"); - else - axis ("autoy", "labely"); - endif + axis ([w(1), w(n)], "autoy"); + xlabel (x_label); + ylabel ("Magnitude (dB)"); - subplot (3, 1, 3); + subplot (2, 1, 2); plot (w, phase*360/(2*pi)); grid ("on"); - legend ("Phase (degrees)"); - xlabel ("Frequency"); - axis ([w(1), w(n)], "autoy", "label"); + axis ([w(1), w(n)], "autoy"); + xlabel (x_label); + ylabel ("Phase (degrees)"); endfunction