function [FX]=myfft(x)
N0=length(x);
if N0==1
FX=x;
else N0>1
N=2^ceil((log(N0))/(log(2)));
for i=0:(N/2)-1
x1(i+1)=x(2*(i+1));
x2(i+1)=x(2*(i+1)-1);
end
FX1=myfft(x1);
FX2=myfft(x2);
WN=exp(-j*2*pi/N);
for i=0:(N/2)-1
FX(i+1)=FX1(i+1)+(WN^(i+1))*FX2(i+1);
FX(i+1+(N/2))=FX1(i+1)-(WN^(i+1))*FX2(i+1);
end
end
k=[0:1:N0-1];
figure(2);
subplot(2,1,1);
stem(k,x(k+1));
xlabel('n');
ylabel('x(n)');
subplot(2,1,2);
stem(k,abs(FX(k+1)));
xlabel('k');
ylabel('|FX(k)|');
end
2023-01-07 21:02:00
780KB
数字信号处理
1