簡體   English   中英

執行 FFT 時提取主頻率返回錯誤頻率

[英]Dominant frequency extraction when doing FFT returns wrong frequency

我將加速度計傳感器數據(時間、x 軸、y 軸和 z 軸)保存在 csv 文件中。 我正在嘗試從每個軸獲取 FFT。 我的圖表如下:

在此處輸入圖片說明

現在,我想從每個 FFT 圖中提取主要頻率並獲得其相應的幅度。 經過一番研究,我想出了代碼:

def Freq(self):
    
    freqs = arange(1, self.N, 1)[:int(self.N/2) - 1]
    Amptsx = (2/self.N)* abs( fft(self.fx)[:int(self.N/2)] )[1:]
    Amptsy = (2/self.N)* abs( fft(self.fy)[:int(self.N/2)] )[1:]
    Amptsz = (2/self.N)* abs( fft(self.fz)[:int(self.N/2)] )[1:]
    
    
    print 'The highest frequency in the x axis is:', round(np.argmax(Amptsx),6)
    print 'The highest frequency in the y axis is:', round(np.argmax(Amptsy),6)
    print 'The highest frequency in the z axis is:', round(np.argmax(Amptsz),6)
    
    print 'The highest amplitude in the x axis is:', round(np.max(Amptsx),6) 
    print 'The highest amplitude in the y axis is:', round(np.max(Amptsy),6)
    print 'The highest amplitude in the z axis is:', round(np.max(Amptsz),6) 
    
    return freqs, Amptsx, Amptsy, Amptsz

我的幅度結果准確,但頻率不准確。 我的結果如下:

The highest frequency in the x axis is: 0.0.
The highest frequency in the y axis is: 1.0.
The highest frequency in the z axis is: 15.0.
The highest amplitude in the x axis is: 0.768894.
The highest amplitude in the y axis is: 0.59046.
The highest amplitude in the z axis is: 0.3679.

我的猜測是我的頻率被四舍五入了。 我試圖修復它但沒有成功。 有什么建議?

有兩個問題:

 freqs = arange(1, self.N, 1)[:int(self.N/2) - 1] Amptsx = (2/self.N)* abs( fft(self.fx)[:int(self.N/2)] )[1:]
 print 'The highest frequency in the x axis is:', round(np.argmax(Amptsx),6)
  1. 頻率和幅度陣列未正確對齊,這意味着與給定頻率對應的幅度在Amptsx陣列中的索引與頻率在freqs陣列中的freqs

    原因是通過使用[:int(self.N/2) - 1]可以從freqs末尾刪除一個額外的項目,而通過使用[1:]可以從Amptsx開頭刪除一個額外的項目。

    您應該從兩個數組的末尾或開頭刪除一項,具體取決於應用程序中哪一項具有正確含義。

    我懷疑你這樣做是為了從數組的開頭刪除零頻率的值——即傳感器值中的恆定偏移量——所以在這種情況下你應該改變[:int(self.N/2) - 1][1:int(self.N/2)]freqs

  2. argmax為您提供最高價值的指標Amptsx ,這不是一個頻率。 您應該使用該索引從freqs獲取頻率值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM