def find_frequency(self, v, si): # voltages, samplimg interval is seconds
from numpy import fft
NP = len(v)
v = v -v.mean() # remove DC component
frq = fft.fftfreq(NP, si)[:NP/2] # take only the +ive half of the frequncy array
amp = abs(fft.fft(v)[:NP/2])/NP # and the fft result
index = amp.argmax() # search for the tallest peak, the fundamental
return frq[index]
评论列表
文章目录