2 # Copyright 2004,2005 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
23 Routines for designing window functions.
27 from gnuradio import gr
39 if u >= IzeroEPSILON*sum:
44 return (fft_size - 1)/2
50 return 2.0*math.pi/fft_size
53 return 1.0/(fft_size >> 1)
56 math.log(2.0)/(midn(fft_size) + 1.0)
58 def hamming(fft_size):
60 for index in xrange(fft_size):
61 window.append(0.54 - 0.46 * math.cos (2 * math.pi / fft_size * index)) # Hamming window
64 def hanning(fft_size):
66 for index in xrange(fft_size):
67 window.append(0.5 - 0.5 * math.cos (2 * math.pi / fft_size * index)) # von Hann window
71 window = [0 for i in range(fft_size)]
73 for index in xrange(midn(fft_size)+1):
74 window[j] = window[index] = (1.0 - math.sqrt((index - midm1(fft_size)) / midp1(fft_size)))
79 window = [0 for i in range(fft_size)]
81 for index in xrange(midn(fft_size)+1):
82 window[j] = window[index] = (1.0 - math.abs((index - midm1(fft_size)) / midp1(fft_size)))
86 def bartlett(fft_size):
89 window = [0 for i in range(fft_size)]
91 for index in xrange(midn(fft_size)+1):
92 window[j] = window[index] = angle
97 def blackman2(fft_size):
100 window = [0 for i in range(fft_size)]
102 for index in xrange(midn(fft_size)+1):
104 window[j] = window[index] = (.34401 + (cx * (-.49755 + (cx * .15844))))
109 def blackman3(fft_size):
110 mfrq = freq(fft_size)
112 window = [0 for i in range(fft_size)]
114 for index in xrange(midn(fft_size)+1):
116 window[j] = window[index] = (.21747 + (cx * (-.45325 + (cx * (.28256 - (cx * .04672))))))
121 def blackman4(fft_size):
122 mfrq = freq(fft_size)
124 window = [0 for i in range(fft_size)]
126 for index in xrange(midn(fft_size)+1):
128 window[j] = window[index] = (.084037 + (cx * (-.29145 + (cx * (.375696 + (cx * (-.20762 + (cx * .041194))))))))
133 def exponential(fft_size):
135 window = [0 for i in range(fft_size)]
137 for index in xrange(midn(fft_size)+1):
138 window[j] = window[i] = (expsum - 1.0)
139 expsum *= expn(fft_size)
143 def riemann(fft_size):
145 window = [0 for i in range(fft_size)]
147 for index in xrange(midn(fft_size)):
148 if index == midn(fft_size):
149 window[index] = window[j] = 1.0
151 cx = sr1*midn(fft_size) - index
152 window[index] = window[j] = math.sin(cx)/cx
156 def blackmanharris(fft_size):
161 window = [0 for i in range(fft_size)]
162 for index in xrange(fft_size):
164 window[index] -= a1*math.cos(2.0*math.pi*(index+0.5)/(fft_size - 1))
165 window[index] += a2*math.cos(4.0*math.pi*(index+0.5)/(fft_size - 1))
166 window[index] -= a3*math.cos(6.0*math.pi*(index+0.5)/(fft_size - 1))
169 def nuttall(fft_size):
174 window = [0 for i in range(fft_size)]
175 for index in xrange(fft_size):
177 window[index] -= a1*math.cos(2.0*math.pi*(index+0.5)/(fft_size - 1))
178 window[index] += a2*math.cos(4.0*math.pi*(index+0.5)/(fft_size - 1))
179 window[index] -= a3*math.cos(6.0*math.pi*(index+0.5)/(fft_size - 1))
182 def kaiser(fft_size,beta):
183 ibeta = 1.0/izero(beta)
184 inm1 = 1.0/(fft_size)
185 window = [0 for i in range(fft_size)]
186 for index in xrange(fft_size):
187 window[index] = izero(beta*math.sqrt(1.0 - (index * inm1)*(index * inm1))) * ibeta