3942
|
1 ## Copyright (C) 2002 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 2, or (at your option) |
|
8 ## 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, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
3942
|
19 |
|
20 ## -*- texinfo -*- |
5610
|
21 ## @deftypefn {Function File} {} freqz_plot (@var{w}, @var{h}) |
3942
|
22 ## Plot the pass band, stop band and phase response of @var{h}. |
|
23 ## @end deftypefn |
|
24 |
|
25 ## Author: Paul Kienzle <pkienzle@users.sf.net> |
|
26 |
6448
|
27 function freqz_plot (w, h) |
3942
|
28 |
|
29 n = length (w); |
|
30 |
|
31 ## ## exclude zero-frequency |
|
32 ## h = h (2 : length (h)); |
|
33 ## w = w (2 : length (w)); |
|
34 ## n = n-1; |
|
35 |
|
36 mag = 20 * log10 (abs (h)); |
|
37 phase = unwrap (arg (h)); |
|
38 maxmag = max (mag); |
|
39 |
6448
|
40 subplot (3, 1, 1); |
6746
|
41 plot (w, mag); |
6448
|
42 grid ("on"); |
6746
|
43 legend("Pass band (dB)"); |
6448
|
44 axis ([w(1), w(n), maxmag-3, maxmag], "labely"); |
3942
|
45 |
6448
|
46 subplot (3, 1, 2); |
6746
|
47 plot (w, mag); |
6448
|
48 grid ("on"); |
6746
|
49 legend ("Stop band (dB)"); |
6448
|
50 if (maxmag - min (mag) > 100) |
|
51 axis ([w(1), w(n), maxmag-100, maxmag], "labely"); |
|
52 else |
|
53 axis ("autoy", "labely"); |
|
54 endif |
3942
|
55 |
6448
|
56 subplot (3, 1, 3); |
6746
|
57 plot (w, phase*360/(2*pi)); |
6448
|
58 grid ("on"); |
6746
|
59 legend ("Phase (degrees)"); |
6448
|
60 xlabel ("Frequency"); |
|
61 axis ([w(1), w(n)], "autoy", "label"); |
3942
|
62 |
|
63 endfunction |