Dear Python users,
I am trying to use a piece of coding for FFT filtering, but I haven't
figure out how to implement the definitions. The Python tutorials
mention something about it, but it is not working for me. The piece
of code that I want to use is posted below. Now, I am interested in
using the function defined as filter (def filter). It seemed to me,
that something like this should work (but it does not):
myFilter = Filter() # This is to call the class.
y_filtered = myFilter.filter(y_raw) # To filter the raw signal.
Thank you all for your kind attention.
Best Regards, Peter
###############################################
class Filter:
def set_cutoff(self,cutoff):
self.cutoff = cutoff
def set_band(self,f1, f2):
self.f1 = f1
self.f2 = f2
def filter(self,x,y):
self.delta = x[1] - x[0]
self.f_Nyquist = 1.0 / 2.0 / self.delta
self.N = len(x)
self.fft = fft(y)
self.freqs = array(range(len(self.fft))) / self.delta / len
(self.fft)
N = len(self.freqs)
for i in range(N/2):
self.freqs[N/2+i] = - self.freqs[N/2-i]
self.calculate_condition()
for i in range(len(self.freqs)):
print '%10d %10f %2d' % ( i, self.freqs[i], self.cond[i] )
self.filtered_fft = self.cond * self.fft
self.filtered_y = inverse_fft(self.filtered_fft)
return self.filtered_y
def calculate_condition(self):
pass
################################################