Mercurial > octave-nkf
comparison scripts/signal/freqz_plot.m @ 6448:2110cc251779
[project @ 2007-03-24 02:47:36 by jwe]
author | jwe |
---|---|
date | Sat, 24 Mar 2007 02:47:36 +0000 |
parents | ddfe04062467 |
children | a8105a726e68 |
comparison
equal
deleted
inserted
replaced
6447:3f79532415b5 | 6448:2110cc251779 |
---|---|
22 ## Plot the pass band, stop band and phase response of @var{h}. | 22 ## Plot the pass band, stop band and phase response of @var{h}. |
23 ## @end deftypefn | 23 ## @end deftypefn |
24 | 24 |
25 ## Author: Paul Kienzle <pkienzle@users.sf.net> | 25 ## Author: Paul Kienzle <pkienzle@users.sf.net> |
26 | 26 |
27 function freqz_plot(w,h) | 27 function freqz_plot (w, h) |
28 | 28 |
29 n = length (w); | 29 n = length (w); |
30 | 30 |
31 ## ## exclude zero-frequency | 31 ## ## exclude zero-frequency |
32 ## h = h (2 : length (h)); | 32 ## h = h (2 : length (h)); |
35 | 35 |
36 mag = 20 * log10 (abs (h)); | 36 mag = 20 * log10 (abs (h)); |
37 phase = unwrap (arg (h)); | 37 phase = unwrap (arg (h)); |
38 maxmag = max (mag); | 38 maxmag = max (mag); |
39 | 39 |
40 unwind_protect | 40 subplot (3, 1, 1); |
41 plot (w, mag, ";Pass band (dB);"); | |
42 grid ("on"); | |
43 axis ([w(1), w(n), maxmag-3, maxmag], "labely"); | |
41 | 44 |
42 ## Protect graph state. | 45 subplot (3, 1, 2); |
46 plot (w, mag, ";Stop band (dB);"); | |
47 grid ("on"); | |
48 if (maxmag - min (mag) > 100) | |
49 axis ([w(1), w(n), maxmag-100, maxmag], "labely"); | |
50 else | |
51 axis ("autoy", "labely"); | |
52 endif | |
43 | 53 |
44 replot_state = automatic_replot; | 54 subplot (3, 1, 3); |
45 automatic_replot(0); | 55 plot (w, phase*360/(2*pi), ";Phase (degrees);"); |
46 | 56 grid ("on"); |
47 subplot (311); | 57 xlabel ("Frequency"); |
48 __gnuplot_set__ lmargin 10; | 58 axis ([w(1), w(n)], "autoy", "label"); |
49 axis ("labely"); | |
50 xlabel (""); | |
51 grid ("on"); | |
52 axis ([ w(1), w(n), maxmag-3, maxmag ]); | |
53 plot (w, mag, ";Pass band (dB);"); | |
54 | |
55 subplot (312); | |
56 axis ("labely"); | |
57 title (""); | |
58 xlabel (""); | |
59 __gnuplot_set__ tmargin 0; | |
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 | |
68 subplot (313); | |
69 axis ("label"); | |
70 title (""); | |
71 grid ("on"); | |
72 axis ("autoy"); | |
73 xlabel ("Frequency"); | |
74 axis ([ w(1), w(n) ]); | |
75 plot (w, phase*360/(2*pi), ";Phase (degrees);"); | |
76 | |
77 unwind_protect_cleanup | |
78 | |
79 ## Restore graph state. | |
80 | |
81 ## FIXME -- 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"); | |
87 __gnuplot_set__ lmargin; | |
88 __gnuplot_set__ tmargin; | |
89 oneplot (); | |
90 | |
91 automatic_replot(replot_state); | |
92 | |
93 end_unwind_protect | |
94 | 59 |
95 endfunction | 60 endfunction |