Matlab中的离散傅立叶变换

时间:2012-04-27 01:44:33

标签: matlab fft dft

我被要求在matlab中编写一个fft混音基数,但在此之前我想让它以直接的方式进行离散傅立叶变换。所以我决定根据维基百科中定义的公式编写代码。

[抱歉我暂时不允许发布图片]

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

你能帮我查一下确切的问题吗?

谢谢!

============ 没关系,我的代码似乎是正确的....

1 个答案:

答案 0 :(得分:0)

默认情况下,Web链接中的计算器会在执行FFT之前对数据应用窗口函数。这可能是差异的原因吗?您可以从下拉菜单中关闭窗口。

BTW在Matlab中有一个FFT函数