| Electronics > Projects, Designs, and Technical Stuff |
| why The FFT can not compute this second harmonic correctly? |
| (1/6) > >> |
| ali_asadzadeh:
Hi, I have generated two sin waves with the F and 2*F frequency, Suppose that I have a 50Hz signal and a 100Hz signal with equal amplitudes and 64 samples in one cycle of the 50Hz signal Here is the Matlab code t=linspace(0,2*pi,64); x=sin(t); y=sin(2*t); sum= x + y; you can see all the signals at once Now when I get the full wave FFT with this Matlab command, the results seems ok, abs(fft(sum))/64 The Result is this,As you can see the first and second harmonic has almost the same amplitude, Now if I try to cut 32 samples of data (from at some point till 32 samples next) and Calculate only the 32 samples for FFT, I should be able to see the 100Hz amplitude data correctly,since there is at least one cycle of the 100Hz wave data in that window, but As you can see it seems that there is no 100Hz data inside the 32 sample data. Here is the Matlab code s= sum(16:47); And the FFT looks like this abs(fft(s))/32 what am I missing? Do you have any idea? |
| Marco:
You shouldn't use any old FFT to do a DFT, FFT's are often complex FFT ... and to implement DFT you need a "real" FFT (ie. real time domain input -> quadrature frequency domain output). What you're getting out at the moment is complete bullshit. Even if you were doing it right (ie. use DFT instead) you wouldn't see the lowest frequency signal any more in the second case though. First lets start thinking and expressing the problem more clearly. Don't say FFT, say DFT. Don't say 50 or 100Hz, say frequency is 1/64 and 1/32. When you take 32 samples, the lowest frequency the DFT has a bin for other than DC is 1/32 ... 1/64 simply doesn't have a bin any more. It's useful to look at the DFT as periodic, you can repeat the block you are transforming and it produces the same DFT result. So what happens when you repeat your 32 sample window? You get lots of sudden jumps at the boundaries, which means high frequency components. All that energy from the low frequency 1/64 has been transferred to high frequencies and DC. Only 1/32 remains, in the first frequency bin. |
| awallin:
try again with a time-series that contains 100 or so waves of the thing you want to measure and you will get more sane results. you'll need an X-axis in Hz to interpret what fft-bin corresponds to what frequency. numpy/matlab might also have more user-friendly high-level functions for PSD (e.g. "pwelch" or similar) |
| rstofer:
Does this help? http://icrf.nl/Portals/0/Matlab/DFT_and_Matlab.pdf Lots of math and examples |
| dmendesf:
This is a common misunderstanding about what the DFT / DFT does. Most people understand it as "bin N has the exact amplitude / phase of order N harmonic, always". This is just not true. It works like that: "IF the input is a sum of N harmonics that are exactly multiple of the FFT lenght, THEN then bin N has the exact amplitude / phase of the order N harmonic". If you violate this rule then the FFT can have any arbitrary data. I'm posting from my cell phone but when I'm at the computer I'll post a link to a site that has an interactive FFT / DFT Applet that let you change the input vector in real time and look at the output to see what impact it has. |
| Navigation |
| Message Index |
| Next page |