Mercurial > octave-nkf
annotate scripts/signal/freqz_plot.m @ 18450: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 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17338
diff
changeset
|
1 ## Copyright (C) 2002-2013 John W. Eaton |
3942 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3942 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3942 | 18 |
19 ## -*- texinfo -*- | |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
20 ## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h}) |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
21 ## @deftypefnx {Function File} {} freqz_plot (@var{w}, @var{h}, @var{freq_hz}) |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
22 ## Plot the pass band, stop band and phase response of @var{h}. If the |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
23 ## optional @var{freq_norm} argument is true, the frequency vector @var{w} |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
24 ## is in units of normalized radians and the x-axis is labeled as such. |
3942 | 25 ## @end deftypefn |
26 | |
27 ## Author: Paul Kienzle <pkienzle@users.sf.net> | |
28 | |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
29 function freqz_plot (w, h, freq_norm = false) |
3942 | 30 |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
31 if (nargin < 2 || nargin > 3) |
7125 | 32 print_usage (); |
33 endif | |
3942 | 34 |
7125 | 35 n = length (w); |
3942 | 36 |
7125 | 37 ## ## exclude zero-frequency |
38 ## h = h (2 : length (h)); | |
39 ## w = w (2 : length (w)); | |
40 ## n = n-1; | |
3942 | 41 |
7125 | 42 mag = 20 * log10 (abs (h)); |
43 phase = unwrap (arg (h)); | |
3942 | 44 |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
45 if (freq_norm) |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
46 x_label = "Normalized Frequency (\\times\\pi rad/sample)"; |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
47 else |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
48 x_label = "Frequency (Hz)"; |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
49 endif |
3942 | 50 |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
51 subplot (2, 1, 1); |
7125 | 52 plot (w, mag); |
53 grid ("on"); | |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
54 axis ([w(1), w(n)], "autoy"); |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
55 xlabel (x_label); |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
56 ylabel ("Magnitude (dB)"); |
7125 | 57 |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
58 subplot (2, 1, 2); |
7125 | 59 plot (w, phase*360/(2*pi)); |
60 grid ("on"); | |
18450
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
61 axis ([w(1), w(n)], "autoy"); |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
62 xlabel (x_label); |
694e8f0b3862
freqz: Make frequency response plot visually compatible with Matlab (bug #41464)
Mike Miller <mtmiller@ieee.org>
parents:
17744
diff
changeset
|
63 ylabel ("Phase (degrees)"); |
3942 | 64 |
65 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
66 |