]> Creatis software - CreaPhase.git/blob - octave_packages/m/signal/freqz_plot.m
update packages
[CreaPhase.git] / octave_packages / m / signal / freqz_plot.m
1 ## Copyright (C) 2002-2012 John W. Eaton
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h})
21 ## Plot the pass band, stop band and phase response of @var{h}.
22 ## @end deftypefn
23
24 ## Author: Paul Kienzle <pkienzle@users.sf.net>
25
26 function freqz_plot (w, h)
27
28   if (nargin != 2)
29     print_usage ();
30   endif
31
32   n = length (w);
33
34   ## ## exclude zero-frequency
35   ## h = h (2 : length (h));
36   ## w = w (2 : length (w));
37   ## n = n-1;
38
39   mag = 20 * log10 (abs (h));
40   phase = unwrap (arg (h));
41   maxmag = max (mag);
42
43   subplot (3, 1, 1);
44   plot (w, mag);
45   grid ("on");
46   legend ("Pass band (dB)");
47   axis ([w(1), w(n), maxmag-3, maxmag], "labely");
48
49   subplot (3, 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));
61   grid ("on");
62   legend ("Phase (degrees)");
63   xlabel ("Frequency");
64   axis ([w(1), w(n)], "autoy", "label");
65
66 endfunction