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 |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} freqz_plot (@var{w}, @var{h}) |
|
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 |
|
27 function freqz_plot(w,h) |
|
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 |
|
40 unwind_protect |
|
41 |
|
42 ## Protect graph state. |
|
43 |
4422
|
44 subplot (311); |
|
45 gset lmargin 10; |
|
46 axis ("labely"); |
|
47 xlabel (""); |
3942
|
48 grid ("on"); |
|
49 axis ([ w(1), w(n), maxmag-3, maxmag ]); |
|
50 plot (w, mag, ";Pass band (dB);"); |
|
51 |
4422
|
52 subplot (312); |
|
53 axis ("labely"); |
|
54 title (""); |
|
55 xlabel (""); |
|
56 gset tmargin 0; |
3942
|
57 grid ("on"); |
|
58 if (maxmag - min (mag) > 100) |
|
59 axis ([ w(1), w(n), maxmag-100, maxmag ]); |
|
60 else |
|
61 axis ("autoy"); |
|
62 endif |
|
63 plot (w, mag, ";Stop band (dB);"); |
|
64 |
4422
|
65 subplot (313); |
|
66 axis ("label"); |
|
67 title (""); |
3942
|
68 grid ("on"); |
|
69 axis ("autoy"); |
|
70 xlabel ("Frequency"); |
|
71 axis ([ w(1), w(n) ]); |
4340
|
72 plot (w, phase*360/(2*pi), ";Phase (degrees);"); |
3942
|
73 |
|
74 unwind_protect_cleanup |
|
75 |
|
76 ## Restore graph state. |
|
77 |
|
78 ## XXX FIXME XXX -- if automatic_replot is non-zero, this will |
|
79 ## mess up the graph, however if we don't do it here then the user |
|
80 ## will have to do it themselves. |
|
81 |
|
82 grid ("off"); |
|
83 axis ("auto", "label"); |
|
84 gset lmargin; |
|
85 gset tmargin; |
|
86 oneplot (); |
|
87 |
|
88 end_unwind_protect |
|
89 |
|
90 endfunction |