Debian Codegraph @

Octave/measure_filter.m

raw
1 function [stop_atten stop_band_start minus_3db] = measure_filter (f, atten)
2
3
4 spec_len = 400000 ;
5
6 # Calculate the spectrum.
7
8 spec = 20 * log10 (abs (fft ([f zeros(1, spec_len - length (f))]))) ;
9
10 spec = spec (1:spec_len/2) ;
11
12 #-------------------------------------------------------------------------------
13 # Find the first null which starts off the stop band.
14
15 first_null = 0 ;
16 for k = 2:length (spec) - 1,
17 if spec (k) < -0.8 * atten && spec (k-1) > spec (k) && spec (k) < spec (k + 1),
18 first_null = k ;
19 break
20 endif
21 endfor
22
23 #-------------------------------------------------------------------------------
24 # Find the stop band minimum attenuation.
25
26 stop_atten = max (spec (first_null:length (spec))) ;
27
28 #-------------------------------------------------------------------------------
29 # Find the x position on the transition band which has the same attenuation.
30
31 atten_start = 0 ;
32 for k = 1:first_null,
33 if spec (k) > stop_atten && spec (k + 1) < stop_atten,
34 atten_start = k ;
35 break ;
36 endif
37 endfor
38
39 atten_start = atten_start - 1 ; # Arrays are 1 based so subtract 1.
40
41 stop_band_start = atten_start + (stop_atten - spec (atten_start)) / (spec (atten_start+1) - spec (atten_start)) ;
42
43
44 stop_band_start = stop_band_start / spec_len ;
45
46 #-------------------------------------------------------------------------------
47 # Find -3db point.
48
49 minus_3db = 0 ;
50 for k = 1:first_null,
51 if spec (k) > -3.0 && spec (k + 1) < -3.0,
52 minus_3db = k ;
53 break ;
54 endif
55 endfor
56
57 minus_3db = minus_3db - 1 ; # Arrays are 1 based so subtract 1.
58
59 minus_3db = minus_3db + (stop_atten - spec (minus_3db)) / (spec (minus_3db+1) - spec (minus_3db)) ;
60
61 minus_3db = minus_3db / spec_len ;
62
63 endfunction
64
65 # Do not edit or modify anything in this comment block.
66 # The arch-tag line is a file identity tag for the GNU Arch
67 # revision control system.
68 #
69 # arch-tag: cc2bc9a2-d387-4fed-aa0a-570e91f17c99
70