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 |
|
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 |
4637
|
44 replot_state = automatic_replot; |
|
45 automatic_replot = 0; |
|
46 |
4422
|
47 subplot (311); |
5215
|
48 __gnuplot_set__ lmargin 10; |
4422
|
49 axis ("labely"); |
|
50 xlabel (""); |
3942
|
51 grid ("on"); |
|
52 axis ([ w(1), w(n), maxmag-3, maxmag ]); |
|
53 plot (w, mag, ";Pass band (dB);"); |
|
54 |
4422
|
55 subplot (312); |
|
56 axis ("labely"); |
|
57 title (""); |
|
58 xlabel (""); |
5215
|
59 __gnuplot_set__ tmargin 0; |
3942
|
60 grid ("on"); |
|
61 if (maxmag - min (mag) > 100) |
|
62 axis ([ w(1), w(n), maxmag-100, maxmag ]); |
|
63 else |
|
64 axis ("autoy"); |
|
65 endif |
|
66 plot (w, mag, ";Stop band (dB);"); |
|
67 |
4422
|
68 subplot (313); |
|
69 axis ("label"); |
|
70 title (""); |
3942
|
71 grid ("on"); |
|
72 axis ("autoy"); |
|
73 xlabel ("Frequency"); |
|
74 axis ([ w(1), w(n) ]); |
4340
|
75 plot (w, phase*360/(2*pi), ";Phase (degrees);"); |
3942
|
76 |
|
77 unwind_protect_cleanup |
|
78 |
|
79 ## Restore graph state. |
|
80 |
|
81 ## XXX FIXME XXX -- if automatic_replot is non-zero, this will |
|
82 ## mess up the graph, however if we don't do it here then the user |
|
83 ## will have to do it themselves. |
|
84 |
|
85 grid ("off"); |
|
86 axis ("auto", "label"); |
5215
|
87 __gnuplot_set__ lmargin; |
|
88 __gnuplot_set__ tmargin; |
3942
|
89 oneplot (); |
|
90 |
4637
|
91 automatic_replot = replot_state; |
|
92 |
3942
|
93 end_unwind_protect |
|
94 |
|
95 endfunction |