2016-12-16 88 views
-3

我有MATLAB中的信號(音頻信號)代碼的FFT,但它顯示(繪製)圖。不過,我只是想將頻率分量存儲在一個變量中,但我不知道如何。 如果代碼不適用於這樣做,任何人都可以給我在Matlab或Java中工作的代碼嗎?在MATLAB或Java中的FFT

注意:我不是信號處理或MATLAB專家。


%% Basic Fourier Analysis 
    % This example uses the Fourier transform to identify component 
    % frequencies in a simple signal. 

    %% 
    % Create a time vector |t| and a sinusoidal signal |x| that is a  function of |t|. 
    t = 0:1/50:10-1/50;      
    x = sin(2*pi*15*t) + sin(2*pi*20*t); 

    %% 
    % Plot the signal as a function of time. 
    plot(t,x) 

    %% 
    % Compute the Fourier transform of the signal, and then compute the magnitude 
    % |m| and phase |p| of the signal. 
    y = fft(x);   
    m = abs(y);        
    p = angle(y);      

    %% 
    % Compute the frequency vector associated with the signal |y|, which is 
    % sampled in frequency space. 
    f = (0:length(y)-1)*50/length(y); 



    %% 
    % Plot the magnitude and phase of the signal as a function of frequency. 
    % The spikes in magnitude correspond to the signal's frequency 
    % components. 
    subplot(2,1,1) 
    plot(f,m) 
    title('Magnitude') 

    subplot(2,1,2) 
    plot(f,rad2deg(p)) 
    title('Phase') 

    %% 
    % Compute and plot the inverse transform of $y$, which reproduces the 
    % original data in $x$ up to round-off error. 
    figure 
    x2 = ifft(y); 
    plot(t,x2) 
+1

請顯示你的嘗試。據我瞭解,這段代碼不是由你寫的。 – Roxanne

+0

是的,我發現它在matlab站點 –

+0

我試圖存儲它像這樣h = fft(t,x2),然後x_h = h.x y_h = h.y –

回答

2

在MATLAB代碼在你的問題的載體m包含大小每個FFT輸出紙盒的。每個箱子都對應一個頻率,所以這個矢量在每個箱子頻率給你幅度。如果您正在查找頻譜中最大峯值的頻率,則只需在m中找到最大值,然後將此峯值的bin索引轉換爲頻率。倉索引和頻率之間的關係由下式給出:

f = i * Fs/N 

其中i在感興趣的bin的索引,Fs是採樣速率,N是FFT大小,以及f是所述對應的容器的中心頻率。有關更詳細的解釋,請參閱this question