DSPRelated.com
Forums

Matlab fft different result! where is the error?

Started by s210...@hotmail.com July 17, 2009
Dear all Hi
There is different results in the imaginary parts of Matlab FFT function and my own function. where is the error come from?

her is the code:

clear all
close all
clc

x=[3 2 1 1 2]';
N=length(x);
n=0:N-1;
yt(x); % matlab function
%-----
%this part contains my own function
k=n;
X=[];

for a=1:length(k)
Xk=x'*exp(-j*2*pi*n'*k(a)/N);
X=[X;Xk];
end
%------------

figure(1)

subplot(4,2,1); stem(n,x);ylabel('x(n)')
title('DFT by using Matlab built-in function')
subplot(4,2,3); stem(real(y));ylabel('real X(k)')
subplot(4,2,5); stem(imag(y));ylabel('imag X(k)')
subplot(4,2,7); stem(abs(y));ylabel('abs X(k)')

subplot(4,2,2); stem(n,x,'r');ylabel('x(n)')
title('DFT by using my won function')
subplot(4,2,4); stem(k,real(X),'r');ylabel('real X(k)')
subplot(4,2,6); stem(k,imag(X),'r');ylabel('imag X(k)')
subplot(4,2,8); stem(k,abs(X),'r');ylabel('abs X(k)')