[Matlab]自编FFT运算验证

差点被下标搞晕了,matlab下标从1开始,而X(k)和r下标从0开始。

http://www.ilovematlab.cn/forum.php?mod=viewthread&tid=545743&page=1&extra=#pid3399877

理论基础:

实现代码:

clear;
clc;
close all;
N = 8;
xn = [ 4 3 2 6 7 8 9 0 ];

G = zeros(1,N/2);
H = zeros(1,N/2);

for i = 0: N/2 - 1
    k = i+1;
    for r = 0 : N/2 - 1
        G(k) = G(k) + xn(2*r+1)*w_nk( N / 2 ,r*i);
        H(k) = H(k) + xn(2*r+2)*w_nk( N / 2 ,r*i);
    end
end

X = zeros(1,N);
for i = 0:N/2 -1
    k = i+1;
    X(k)     = G(k) + w_nk(N,i)*H(k);
    X(k+N/2) = G(k) - w_nk(N,i)*H(k);
end

Xk = fft(xn,8);

f = 0:7;
figure(1);
subplot(2,2,1);
stem(f,abs(X));
title('自编FFT-幅度谱');
subplot(2,2,2);
stem(f,abs(Xk));
title('库FFT-幅度谱');
subplot(2,2,3);
stem(f,angle(X));
title('自编FFT-相位谱');
subplot(2,2,4);
stem(f,angle(Xk));
title('库FFT-相位谱');

验证结果:

posted @ 2018-05-17 17:57  Alimy  阅读(526)  评论(0编辑  收藏  举报