def amp_spectrum(self, v, si, nhar=8):
# voltages, samplimg interval is seconds, number of harmonics to retain
from numpy import fft
NP = len(v)
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
if index == 0: # DC component is dominating
index = amp[4:].argmax() # skip frequencies close to zero
return frq[:index*nhar], amp[:index*nhar] # restrict to 'nhar' harmonics
评论列表
文章目录