add windowing computations and window definitions

parent 9d3daa44
from numpy import *
class FFTSignal(object):
"""a representation of a frequency-domain signal
"""
WINDOW_TYPES = [
'RECTANGULAR',
'HANN',
'HAMMING',
'TUKEY',
'COSINE',
'LANCZOS',
'BARTLETT_HANN'
]
window_function = {
'No window' : ones,
'BARTLETT' : bartlett,
'BLACKMAN' : blackman,
'HAMMING' : hamming,
'HANNING' : hanning,
'KAISER' : kaiser,
}
WINDOW_TYPES = window_function.keys()
def __init__(self, fft, dB = None, time_domain = None):
"""initialize an FFTSignal object
......
......@@ -118,7 +118,7 @@ class Signal(object):
inl = cumsum(dnl)
return inl, max(abs(inl))
def FFT(self, navg, window):
def FFT(self, navg=1, window='No window'):
"""Compute the amplitudes (in dB) of the FFT of signal, averaging navg
slices of it and applying window to it
......@@ -127,7 +127,10 @@ class Signal(object):
returns: an FFTSignal object
"""
return FFTSignal(self.data, 1, 1)
print 'using window ', window
win = FFTSignal.window_function[window](self.nsamples)
dft = 10*log10(abs(fft.rfft(self.data * win)))
return FFTSignal(dft, dB=True, time_domain=self.data)
def makesine(samples, periods, bits, amplitude=1, noise=0):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment