Mercurial > hg > octave-lyh
comparison scripts/signal/freqz_plot.m @ 3942:2ca2d23a49a7
[project @ 2002-05-16 20:27:59 by jwe]
author | jwe |
---|---|
date | Thu, 16 May 2002 20:28:17 +0000 |
parents | |
children | 8aa604426d35 |
comparison
equal
deleted
inserted
replaced
3941:fab8337340a1 | 3942:2ca2d23a49a7 |
---|---|
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 | |
44 if (gnuplot_has_multiplot) | |
45 subplot (311); | |
46 gset lmargin 10; | |
47 axis ("labely"); | |
48 xlabel (""); | |
49 endif | |
50 grid ("on"); | |
51 axis ([ w(1), w(n), maxmag-3, maxmag ]); | |
52 plot (w, mag, ";Pass band (dB);"); | |
53 | |
54 if (gnuplot_has_multiplot) | |
55 subplot (312); | |
56 axis ("labely"); | |
57 title (""); | |
58 xlabel (""); | |
59 gset tmargin 0; | |
60 else | |
61 input ("press any key for the next plot: "); | |
62 endif | |
63 grid ("on"); | |
64 if (maxmag - min (mag) > 100) | |
65 axis ([ w(1), w(n), maxmag-100, maxmag ]); | |
66 else | |
67 axis ("autoy"); | |
68 endif | |
69 plot (w, mag, ";Stop band (dB);"); | |
70 | |
71 if (gnuplot_has_multiplot) | |
72 subplot (313); | |
73 axis ("label"); | |
74 title (""); | |
75 else | |
76 input ("press any key for the next plot: "); | |
77 endif | |
78 grid ("on"); | |
79 axis ("autoy"); | |
80 xlabel ("Frequency"); | |
81 axis ([ w(1), w(n) ]); | |
82 plot (w, phase/(2*pi), ";Phase (radians/2pi);"); | |
83 | |
84 unwind_protect_cleanup | |
85 | |
86 ## Restore graph state. | |
87 | |
88 ## XXX FIXME XXX -- if automatic_replot is non-zero, this will | |
89 ## mess up the graph, however if we don't do it here then the user | |
90 ## will have to do it themselves. | |
91 | |
92 grid ("off"); | |
93 axis ("auto", "label"); | |
94 gset lmargin; | |
95 gset tmargin; | |
96 oneplot (); | |
97 | |
98 end_unwind_protect | |
99 | |
100 endfunction |