Mercurial > hg > octave-nkf
comparison scripts/signal/freqz_plot.m @ 18518:694e8f0b3862 stable
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.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Thu, 13 Feb 2014 00:00:10 -0500 |
parents | d63878346099 |
children | 9d59bc3dc12d |
comparison
equal
deleted
inserted
replaced
18515:ff7e7928f160 | 18518:694e8f0b3862 |
---|---|
15 ## You should have received a copy of the GNU General Public License | 15 ## You should have received a copy of the GNU General Public License |
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h}) | 20 ## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h}) |
21 ## Plot the pass band, stop band and phase response of @var{h}. | 21 ## @deftypefnx {Function File} {} freqz_plot (@var{w}, @var{h}, @var{freq_hz}) |
22 ## Plot the pass band, stop band and phase response of @var{h}. If the | |
23 ## optional @var{freq_norm} argument is true, the frequency vector @var{w} | |
24 ## is in units of normalized radians and the x-axis is labeled as such. | |
22 ## @end deftypefn | 25 ## @end deftypefn |
23 | 26 |
24 ## Author: Paul Kienzle <pkienzle@users.sf.net> | 27 ## Author: Paul Kienzle <pkienzle@users.sf.net> |
25 | 28 |
26 function freqz_plot (w, h) | 29 function freqz_plot (w, h, freq_norm = false) |
27 | 30 |
28 if (nargin != 2) | 31 if (nargin < 2 || nargin > 3) |
29 print_usage (); | 32 print_usage (); |
30 endif | 33 endif |
31 | 34 |
32 n = length (w); | 35 n = length (w); |
33 | 36 |
36 ## w = w (2 : length (w)); | 39 ## w = w (2 : length (w)); |
37 ## n = n-1; | 40 ## n = n-1; |
38 | 41 |
39 mag = 20 * log10 (abs (h)); | 42 mag = 20 * log10 (abs (h)); |
40 phase = unwrap (arg (h)); | 43 phase = unwrap (arg (h)); |
41 maxmag = max (mag); | |
42 | 44 |
43 subplot (3, 1, 1); | 45 if (freq_norm) |
46 x_label = "Normalized Frequency (\\times\\pi rad/sample)"; | |
47 else | |
48 x_label = "Frequency (Hz)"; | |
49 endif | |
50 | |
51 subplot (2, 1, 1); | |
44 plot (w, mag); | 52 plot (w, mag); |
45 grid ("on"); | 53 grid ("on"); |
46 legend ("Pass band (dB)"); | 54 axis ([w(1), w(n)], "autoy"); |
47 axis ([w(1), w(n), maxmag-3, maxmag], "labely"); | 55 xlabel (x_label); |
56 ylabel ("Magnitude (dB)"); | |
48 | 57 |
49 subplot (3, 1, 2); | 58 subplot (2, 1, 2); |
50 plot (w, mag); | |
51 grid ("on"); | |
52 legend ("Stop band (dB)"); | |
53 if (maxmag - min (mag) > 100) | |
54 axis ([w(1), w(n), maxmag-100, maxmag], "labely"); | |
55 else | |
56 axis ("autoy", "labely"); | |
57 endif | |
58 | |
59 subplot (3, 1, 3); | |
60 plot (w, phase*360/(2*pi)); | 59 plot (w, phase*360/(2*pi)); |
61 grid ("on"); | 60 grid ("on"); |
62 legend ("Phase (degrees)"); | 61 axis ([w(1), w(n)], "autoy"); |
63 xlabel ("Frequency"); | 62 xlabel (x_label); |
64 axis ([w(1), w(n)], "autoy", "label"); | 63 ylabel ("Phase (degrees)"); |
65 | 64 |
66 endfunction | 65 endfunction |
67 | 66 |