2015-05-25 76 views
0

我對信號處理是全新的,並且試圖製作一個程序來顯示PCM(WAV)文件中低頻信號的幅度。使用FFT確定低頻信號的幅度

到目前爲止,我已經能夠在WAV文件的讀取和填充數組(每個通道實際上是一個多維數組,一個,但我們只考慮在通道的通道爲基礎)的float與從WAV獲取的聲音文件的數據點。每個數據點都是一個幅度。 總之,我有聲波的時域表示。 我使用它來繪製波的振幅的曲線相對於時間,這看起來像:

Amplitude with respect to time

我的目標是做完全低於一定值相同,但只顯示頻率(例如350Hz)。清楚的是,這並不是我想要在頻域中顯示圖形(即在快速傅立葉變換之後)。我想顯示相同的幅度與時間的關係圖,但是對於[0,350Hz]範圍內的頻率。

我正在尋找可以做一個函數:

// Returns an array of data points that contains 
// amplitude data points, after a low pass filter 
float[] low_pass_filter(float[] original_data, float low_pass_freq=350.0) 
{ 
    ... 
} 

我對FFT讀了,讀Chris Lomont's code for the FFT和理解「理論」一低通濾波器的後面,但我發現很難讓我的頭腦如何真正實現這個特定的功能(上圖)。任何幫助(+解釋)將不勝感激!

+1

[C#中的低通和高通濾波器]的可能重複(http://stackoverflow.com/questions/8079526/lowpass-and-high-pass-filter-in-c-sharp) –

回答

0

我結束了使用this的例子,它工作得很好。我包了一點更好,以結束:

/// <summary> 
    /// Returns a low-pass filter of the data 
    /// </summary> 
    /// <param name="data">Data to filter</param> 
    /// <param name="cutoff_freq">The frequency below which data will be preserved</param> 
    private float[] lowPassFilter(ref float[] data, float cutoff_freq, int sample_rate, float quality_factor=1.0f) 
    { 
     // Calculate filter parameters 
     float O = (float)(2.0 * Math.PI * cutoff_freq/sample_rate); 
     float C = quality_factor/O; 
     float L = 1/quality_factor/O; 

     // Loop through and apply the filter 
     float[] output = new float[data.Length]; 
     float V = 0, I = 0, T; 
     for (int s = 0; s < data.Length; s++) 
     { 
      T = (I - V)/C; 
      I += (data[s] * O - V)/L; 
      V += T; 
      output[s] = V/O; 
     } 

     return output; 
    } 

常規和低通波形輸出:

Both waveforms

和孤立的常規波形VS低通波形:

Regular only

Low-pass only