Why FFT results are different from theory?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Wanjie
el 2 de Nov. de 2013
Comentada: Wanjie
el 4 de Nov. de 2013
Hello, all,
When I used FFT to calculate a square wave, I encountered a problem. I used 8 total points of FFT,and in theory the real part of FFT results for a square wave should be 0 and imaginary part for odd harmonics should be 4/pi/N. However, what I got is a correct imaginary part but a wrong real part. For 8 total FFT points, the real part is all 0.25, which is huge for me. Also, when I increased the total NFFT points, this real part is decreasing. But it never be 0. Does anyone know what I am doing wrong? Thank you very much for your help.
This is my code:
clear all;
clc
Fs=200;
NFFT=2^3;
Delt=1/Fs;
t=(0:NFFT-1)*Delt;
f=(0:NFFT/2-1)*Fs;
S(1:NFFT/2)=1;
S(NFFT/2+1:NFFT)=-1;
RFFT=fft(S,NFFT)/NFFT;
% ss=ifft(RFFT,NFFT)*NFFT;
figure(1)
plot(f,2*real(RFFT(1:NFFT/2)),'r')
hold on
plot(f,2*imag(RFFT(1:NFFT/2)),'b')
hold off
title('FFT results')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
legend('real','imaginary')
figure(2)
plot(t,S,'r','LineWidth',2)
title('Transient source waveform')
xlabel('Time (s)')
ylabel('Transient source amplitude')
Respuesta aceptada
Más respuestas (2)
Wayne King
el 2 de Nov. de 2013
Editada: Wayne King
el 2 de Nov. de 2013
I'm not sure why you are saying the results are different from the theory.
fft() is just an efficient implementation of the DFT (discrete Fourier transform)
The DFT is an operator from an N-dimensional vector space to an N-dimensional vector space. Don't confuse the DFT (fft()) with the different Fourier transform or Fourier series.
The DFT of
x = [1 1 1 1 -1 -1 -1 -1]
is
fft(x)
You can work this out easily by pencil and paper for an 8-point vector to convince yourself.
For example, because MATLAB uses 1-indexing:
xdft = fft(x);
xdft(1)
is equal to
sum([1 exp(-1i*pi/4) exp(-1i*pi/2) exp(-1i*(3*pi)/4) 1 -exp(-1i*(5*pi)/4) -exp(-1i*(6*pi)/4) -exp(-1i*(7*pi)/4)])
Wayne King
el 2 de Nov. de 2013
Your statement that the Fourier transform of a square wave should be purely imaginary is based on the assumption that the square wave is an odd function f(-t) = -f(t) (or whatever continuous varable you like)
But what is -t to MATLAB? How can
x = [1 1 1 1 -1 -1 -1 -1]
be interpreted as an odd function of t?
It is just a N-point vector with indices n = 0,1,2,...N-1
Ver también
Categorías
Más información sobre Parametric Spectral Estimation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!