7017
|
1 ## Copyright (C) 2002, 2003, 2005, 2006, 2007 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 -*- |
5610
|
20 ## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h}) |
3942
|
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 |
6448
|
26 function freqz_plot (w, h) |
3942
|
27 |
|
28 n = length (w); |
|
29 |
|
30 ## ## exclude zero-frequency |
|
31 ## h = h (2 : length (h)); |
|
32 ## w = w (2 : length (w)); |
|
33 ## n = n-1; |
|
34 |
|
35 mag = 20 * log10 (abs (h)); |
|
36 phase = unwrap (arg (h)); |
|
37 maxmag = max (mag); |
|
38 |
6448
|
39 subplot (3, 1, 1); |
6746
|
40 plot (w, mag); |
6448
|
41 grid ("on"); |
6746
|
42 legend("Pass band (dB)"); |
6448
|
43 axis ([w(1), w(n), maxmag-3, maxmag], "labely"); |
3942
|
44 |
6448
|
45 subplot (3, 1, 2); |
6746
|
46 plot (w, mag); |
6448
|
47 grid ("on"); |
6746
|
48 legend ("Stop band (dB)"); |
6448
|
49 if (maxmag - min (mag) > 100) |
|
50 axis ([w(1), w(n), maxmag-100, maxmag], "labely"); |
|
51 else |
|
52 axis ("autoy", "labely"); |
|
53 endif |
3942
|
54 |
6448
|
55 subplot (3, 1, 3); |
6746
|
56 plot (w, phase*360/(2*pi)); |
6448
|
57 grid ("on"); |
6746
|
58 legend ("Phase (degrees)"); |
6448
|
59 xlabel ("Frequency"); |
|
60 axis ([w(1), w(n)], "autoy", "label"); |
3942
|
61 |
|
62 endfunction |