Why FFT results are different from theory?

2 ビュー (過去 30 日間)
Wanjie
Wanjie 2013 年 11 月 2 日
コメント済み: Wanjie 2013 年 11 月 4 日
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')
  1 件のコメント
dpb
dpb 2013 年 11 月 2 日
Big hint...
plot(t,S)

サインインしてコメントする。

採用された回答

Wanjie
Wanjie 2013 年 11 月 4 日
Hi, all,
At last, I found the problems. It is due to the vector I used, x=[1 1 1 1 -1 -1 -1 -1]. This is not an odd function, so I will definitely get real part. Thank you for your help, Wayne.
  2 件のコメント
Wayne King
Wayne King 2013 年 11 月 4 日
Isn't that what I told you?
Wanjie
Wanjie 2013 年 11 月 4 日
Yes, that's it. So I changed the vector to X=[0 1 1 1 0 -1 -1 -1], which is an odd function with corresponding time. This is still a square wave, and also an odd function. The x=[1 1 1 1 -1 -1 -1 -1] is a function which is not odd or even.
Thank you very much for your help, Wayne!

サインインしてコメントする。

その他の回答 (2 件)

Wayne King
Wayne King 2013 年 11 月 2 日
編集済み: Wayne King 2013 年 11 月 2 日
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)])
  1 件のコメント
Wanjie
Wanjie 2013 年 11 月 2 日
Thank you, Wayne. I used definition equation of DFT and got the same results as Matlab FFT for my square wave question. But I am still confused with the FFT. The Fourier Transform results of square wave only have imaginary part. But FFT results of square wave have real and imaginary part. Right now, I do not understand why these two results are not the same. You said don't confuse the DFT with the different Fourier Transform. Does this mean that I should have this difference? I understand the FFT as that if the signal is periodic, the FFT results should be the same as Fourier Transform results. Am I right at this point?
Thank you very much for your help!

サインインしてコメントする。


Wayne King
Wayne King 2013 年 11 月 2 日
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
  1 件のコメント
Wanjie
Wanjie 2013 年 11 月 2 日
Thank you again, Wayne. I think I understand this a little more. I still have some confusions. If I want to use FFT to calculate a periodic square wave, which is an odd function, how can I get it? This is what I want to get in my Matlab code.
Thank you very much for your help!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeParametric Spectral Estimation についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by