2012-04-27 111 views
0

我被要求在matlab中寫一個fft混合基數,但在此之前,我想讓我們直接進行離散傅里葉變換。所以我決定根據維基百科定義的公式編寫代碼。Matlab中的離散傅立葉變換

[對不起,我不能還發表圖片]

http://en.wikipedia.org/wiki/Discrete_Fourier_transform

所以我寫了我的代碼如下:

%Brutal Force Descrete Fourier Trnasform 
function [] = dft(X) 

%Get the size of A 
NN=size(X); 
N=NN(2); 
%==================== 

%Declaring an array to store the output variable 
Y = zeros (1, N) 
%========================================= 



for k = 0 : (N-1) 
    st = 0; %the dummy in the summation is zero before we add 
    for n = 0 : (N-1) 
     t = X(n+1)*exp(-1i*2*pi*k*n/N); 
     st = st + t; 
    end 
    Y(k+1) = st; 
end 
Y 
%============================================= 

然而,我的代碼似乎是輸出結果不同於這個網站的: http://www.random-science-tools.com/maths/FFT.htm

你能幫我檢測到底在哪裏問題是什麼?

謝謝!

============ 沒關係看來我的代碼是正確的....

回答

0

默認情況下,在網站鏈接計算器之前應用窗口函數將數據做FFT。這可能是差異的原因嗎?您可以從下拉菜單中關閉窗口。

順便說一句,在Matlab中有一個FFT函數