comparison scripts/signal/freqz_plot.m @ 7125:f084ba47812b

[project @ 2007-11-08 02:29:23 by jwe]
author jwe
date Thu, 08 Nov 2007 02:29:24 +0000
parents a1dbe9d80eee
children cadc73247d65
comparison
equal deleted inserted replaced
7124:d07cb867891b 7125:f084ba47812b
23 23
24 ## Author: Paul Kienzle <pkienzle@users.sf.net> 24 ## Author: Paul Kienzle <pkienzle@users.sf.net>
25 25
26 function freqz_plot (w, h) 26 function freqz_plot (w, h)
27 27
28 n = length (w); 28 if (nargin != 2)
29 print_usage ();
30 endif
29 31
30 ## ## exclude zero-frequency 32 n = length (w);
31 ## h = h (2 : length (h));
32 ## w = w (2 : length (w));
33 ## n = n-1;
34 33
35 mag = 20 * log10 (abs (h)); 34 ## ## exclude zero-frequency
36 phase = unwrap (arg (h)); 35 ## h = h (2 : length (h));
37 maxmag = max (mag); 36 ## w = w (2 : length (w));
37 ## n = n-1;
38 38
39 subplot (3, 1, 1); 39 mag = 20 * log10 (abs (h));
40 plot (w, mag); 40 phase = unwrap (arg (h));
41 grid ("on"); 41 maxmag = max (mag);
42 legend("Pass band (dB)");
43 axis ([w(1), w(n), maxmag-3, maxmag], "labely");
44 42
45 subplot (3, 1, 2); 43 subplot (3, 1, 1);
46 plot (w, mag); 44 plot (w, mag);
47 grid ("on"); 45 grid ("on");
48 legend ("Stop band (dB)"); 46 legend("Pass band (dB)");
49 if (maxmag - min (mag) > 100) 47 axis ([w(1), w(n), maxmag-3, maxmag], "labely");
50 axis ([w(1), w(n), maxmag-100, maxmag], "labely");
51 else
52 axis ("autoy", "labely");
53 endif
54 48
55 subplot (3, 1, 3); 49 subplot (3, 1, 2);
56 plot (w, phase*360/(2*pi)); 50 plot (w, mag);
57 grid ("on"); 51 grid ("on");
58 legend ("Phase (degrees)"); 52 legend ("Stop band (dB)");
59 xlabel ("Frequency"); 53 if (maxmag - min (mag) > 100)
60 axis ([w(1), w(n)], "autoy", "label"); 54 axis ([w(1), w(n), maxmag-100, maxmag], "labely");
55 else
56 axis ("autoy", "labely");
57 endif
58
59 subplot (3, 1, 3);
60 plot (w, phase*360/(2*pi));
61 grid ("on");
62 legend ("Phase (degrees)");
63 xlabel ("Frequency");
64 axis ([w(1), w(n)], "autoy", "label");
61 65
62 endfunction 66 endfunction