-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectral_window.pro
75 lines (63 loc) · 3.11 KB
/
spectral_window.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;; set the periodic keyword for cases in which n_samples is even but
;; there is a single maximum (ie k=0 exists) -- this implies an asymmetric window
;; function and is correct for FFTs with even numbers of samples
function spectral_window, n_samples, type = type, periodic = periodic, $
fractional_size = fractional_size
type_list = ['Hann', 'Hamming', 'Blackman', 'Nutall', 'Blackman-Nutall', $
'Blackman-Harris', 'Blackman-Harris^2', 'Kaiser3', 'Tukey']
if n_elements(type) eq 0 then type = 'Blackman-Harris'
wh_type = where(strlowcase(type_list) eq strlowcase(type), count_type)
if count_type eq 0 then begin
message, 'Spectral window type not recognized.'
endif else begin
type = type_list[wh_type[0]]
endelse
if n_samples lt 2 then message, 'n_samples must be greater than 2'
if n_samples mod 2 eq 0 and keyword_set(periodic) then begin
n_use = n_samples + 1
endif else begin
n_use = n_samples
endelse
cos_term1 = cos(2.*!pi*dindgen(n_use)/(n_use-1))
cos_term2 = cos(4.*!pi*dindgen(n_use)/(n_use-1))
cos_term3 = cos(6.*!pi*dindgen(n_use)/(n_use-1))
cos_term4 = cos(8.*!pi*dindgen(n_use)/(n_use-1))
case type of
'Hann': window = 0.5 * (1-cos_term1)
'Hamming': window = 0.54 - 0.46 * cos_term1
'Blackman': window = (1-0.16)/2. - 0.5 * cos_term1 + (0.16/2.) * cos_term2
'Nutall': window = 0.355768 - 0.487396 * cos_term1 + 0.144232 * cos_term2 - 0.012604 * cos_term3
'Blackman-Nutall': window = 0.3635819 - 0.4891775 * cos_term1 + 0.1365995 * cos_term2 - 0.0106411 * cos_term3
'Blackman-Harris': window = 0.35875 - 0.48829 * cos_term1 + 0.14128 * cos_term2 - 0.01168 * cos_term3
'Blackman-Harris^2': window = (0.35875 - 0.48829 * cos_term1 + 0.14128 * cos_term2 - 0.01168 * cos_term3)^2.
'Kaiser3': begin
window = BESELI( !pi*3. * sqrt( 1-( (2*(dindgen(n_use)-n_use/2) /n_use)^2. ) ),0,/DOUBLE) / BESELI(!pi*3.,0,/DOUBLE)
end
'Tukey': begin
if n_elements(fractional_size) then begin
alpha = 1.-fractional_size
endif else begin
alpha = 0.5
endelse
window = DBLARR(n_samples) + 1
edge_length = round(alpha*(n_use-1)/2.)
if edge_length gt 0 then begin
n_region_1 = dindgen(edge_length)
n_region_3 = n_samples - 1 - reverse(dindgen(edge_length))
center_length = n_samples - 2*edge_length
if center_length gt 0 then begin
n_region_2 = dindgen(center_length) + 1 + max(n_region_1)
window[0:edge_length-1]=(1./2.) * (1 + cos( !pi*( (2*n_region_1) / (alpha*(n_use-1)) - 1) ))
window[edge_length:edge_length+center_length-1]=1
window[edge_length+center_length:edge_length*2+center_length-1] $
=(1./2.) * (1 + cos( !pi*( (2*n_region_3) / (alpha*(n_use-1)) - (2./alpha) + 1) ))
endif else begin
window[0:edge_length-1]=(1./2.) * (1 + cos( !pi*( (2*n_region_1) / (alpha*(n_use-1)) - 1) ))
window[edge_length:edge_length*2-1] $
=(1./2.) * (1 + cos( !pi*( (2*n_region_3) / (alpha*(n_use-1)) - (2./alpha) + 1) ))
endelse
endif
end
endcase
return, window[0:n_samples-1]
end