DSPRelated.com
Forums

Am I missing something obvious?

Started by Edison June 25, 2007
Hi

I have recently started working with DSP systems. After a great deal of
struggle with an EZ LITE KIT I have finally managed to get a sensible
result for an FFT, using an internally generated waveform for testing.

Now for the problem:

Now I have a reasonable looking FFT I thought I'd try and perform the FFT
on two frequencies, the fundamental and its second harmonic. The strange
thing is that I added 50% of the second harmonic to 100% fundamental. The
resulting FFT bin for the harmonic was only 38% lower than the
fundamental.

SO I tried performing the FFT on the two signals at 100% independantly and
the second harmonic bin magnitude was greater than the fundamental (which
explains the lower than expected result in the first case). 

Am I missing something obvious or is the FFT routine I'm using going
wrong?

I have tried reading around the subject and can not find anything that
fully describes this.

Thanks in advance

Ed
On Jun 25, 3:24 pm, "Edison" <e...@senscient.com> wrote:
> Hi > > I have recently started working with DSP systems. After a great deal of > struggle with an EZ LITE KIT I have finally managed to get a sensible > result for an FFT, using an internally generated waveform for testing. > > Now for the problem: > > Now I have a reasonable looking FFT I thought I'd try and perform the FFT > on two frequencies, the fundamental and its second harmonic. The strange > thing is that I added 50% of the second harmonic to 100% fundamental. The > resulting FFT bin for the harmonic was only 38% lower than the > fundamental. > > SO I tried performing the FFT on the two signals at 100% independantly and > the second harmonic bin magnitude was greater than the fundamental (which > explains the lower than expected result in the first case). > > Am I missing something obvious or is the FFT routine I'm using going > wrong? > > I have tried reading around the subject and can not find anything that > fully describes this. > > Thanks in advance > > Ed
I'm assuming the signals you're talking about using are "pure" sinusoids. Are their frequencies integer multiples of Fs/N (where Fs is your sampling rate and N is the size of your FFT)? Google for "spectral leakage"; if the frequencies don't fall right on top of your DFT output bins, you'll get results that you might not expect. Jason
>I'm assuming the signals you're talking about using are "pure" >sinusoids. Are their frequencies integer multiples of Fs/N (where Fs >is your sampling rate and N is the size of your FFT)? Google for >"spectral leakage"; if the frequencies don't fall right on top of your >DFT output bins, you'll get results that you might not expect. > >Jason >
Yes the signals are "pure" sinusoids. The sample frequency is set at 1MSPS, and the input buffers were initially filled with 64k points of data. Once I had discovered the problem I switched to 16k points which gave the same result. The fundamental id set at 100kHz, do the 2nd harmonic is 200kHz. These are not exactly bin centred but are both well within their bin and certainly don't straddle bins. The 2nd harmonic is coming out significanly higher than the fundamental, I will provide exact numbers tomorrow when I'm back in the office. The book I have been using to refer to (DSP, a practical guide for engineers and scientists) makes mention of scaling factors when talking about DFTs, but brushes over it stating that it will be discussed later. Something that reading on I can not find. Ed
On Jun 25, 12:24 pm, "Edison" <e...@senscient.com> wrote:
> Now for the problem: > > Now I have a reasonable looking FFT I thought I'd try and perform the FFT > on two frequencies, the fundamental and its second harmonic. The strange > thing is that I added 50% of the second harmonic to 100% fundamental. The > resulting FFT bin for the harmonic was only 38% lower than the > fundamental. > > SO I tried performing the FFT on the two signals at 100% independantly and > the second harmonic bin magnitude was greater than the fundamental (which > explains the lower than expected result in the first case). > > Am I missing something obvious or is the FFT routine I'm using going > wrong?
Are you looking at the magnitude (sqrt(real^2+imag^2)) or just the real component? The real components will wander around in magnitude depending on whether your test sinusoids are even or odd functions with respect to the fft aperture/window. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
>Are you looking at the magnitude (sqrt(real^2+imag^2)) or just the >real >component? The real components will wander around in magnitude >depending on whether your test sinusoids are even or odd functions >with respect to the fft aperture/window. > > >IMHO. YMMV. >-- >rhn A.T nicholson d.0.t C-o-M
Firstly Jason, thank you. I have now tried the same test with bin centered frequencies and the two signals came out at the same level. Ron, I'm looking at the absolute values of the real and imaginary components as I need to preserve the phase information. I never had any idea that spectral leakage could have such an effect on my results. How can I prevent this? or will I have to stick to bin centred frequencies. This is possible as I will be generating two fundamentals around 80 and 90 kHz and looking at the 2nd, 3rd, 4th and 5th harmonics. I had chosen easy numbers (85 and 95kHz) but these could change. Would increasing the bin width help to reduce the spectral leakage? Thanks Ed
> I never had any idea that spectral leakage could have such an effect on my > results. How can I prevent this? or will I have to stick to bin centred > frequencies. This is possible as I will be generating two fundamentals > around 80 and 90 kHz and looking at the 2nd, 3rd, 4th and 5th harmonics. I > had chosen easy numbers (85 and 95kHz) but these could change. > > Would increasing the bin width help to reduce the spectral leakage?
Spectral leakage can have a big effect on the output from your FFT. Remember, for a finite-duration input signal, an FFT just gives you a sampled version of the signal's DTFT. The truncation of an infinite sequence to a finite length is equivalent to multiplying the signal times a rectangular window function. The rectangular window has a "periodic sinc" DTFT, which is what you end up sampling when you take the FFT of a finite-duration sinusoid. Depending upon how your bins are spaced, you'll get values somewhere on the sidelobes of the sinc function, which isn't what you want. Increasing the bin width won't help you; it actually is the opposite of what you want. Using a larger FFT size will give you finer bin spacing, and you will therefore be more likely to have a bin very close to the frequency you're searching for. You can do some form of interpolation between bins to get an estimate of the actual peak frequency. Also, you can multiply your input data by a more suitable window function. These functions always have a tradeoff between mainlobe width and sidelobe height, and for your application, it seems you would want sharp peaks, so you would want one with a small mainlobe width. Jason
On Jun 26, 1:36 am, "Edison" <e...@senscient.com> wrote:
> >Are you looking at the magnitude (sqrt(real^2+imag^2)) or just the > >real > >component? The real components will wander around in magnitude > >depending on whether your test sinusoids are even or odd functions > >with respect to the fft aperture/window.
...
> I'm looking at the absolute values of the real and imaginary > components as > I need to preserve the phase information.
The absolute values of the real and imaginary parts will change in ratio depending on the phase of your test sinusoids (odd, even, or some mix in the fft aperture), even if your test sinusoids are centered in a fft bin. If you just want to look at either the real or imaginary component, you might want to generate your test sinusoids so that they stay strictly even, or strictly odd, around the center of the fft aperture, even if the frequency is not bin centered.
> I never had any idea that spectral leakage could have such an > effect on my > results. How can I prevent this? or will I have to stick to bin > centred > frequencies. This is possible as I will be generating two > fundamentals > around 80 and 90 kHz and looking at the 2nd, 3rd, 4th and 5th > harmonics. I > had chosen easy numbers (85 and 95kHz) but these could change. > > Would increasing the bin width help to reduce the spectral > leakage?
Increasing bin width makes it more likely that an arbitrary sinusoid is even farther from a bin center. What you might want to do to avoid any spectral leakage is to (re)sample your signal so that your fft aperture is an exact multiple of all of your signals periods. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M http://www.nicholson.com/rhn/dsp.html
Edison wrote:
>> Are you looking at the magnitude (sqrt(real^2+imag^2)) or just the >> real >> component? The real components will wander around in magnitude >> depending on whether your test sinusoids are even or odd functions >> with respect to the fft aperture/window. >> >> >> IMHO. YMMV. >> -- >> rhn A.T nicholson d.0.t C-o-M > > Firstly Jason, thank you. > > I have now tried the same test with bin centered frequencies and the two > signals came out at the same level. > > Ron, > > I'm looking at the absolute values of the real and imaginary components as > I need to preserve the phase information.
Do you mean "absolute value" the way I do? That's sqrt(Im^2 + Re^2), while phase angle is arctan(Im/Re).
> I never had any idea that spectral leakage could have such an effect on my > results. How can I prevent this? or will I have to stick to bin centred > frequencies. This is possible as I will be generating two fundamentals > around 80 and 90 kHz and looking at the 2nd, 3rd, 4th and 5th harmonics. I > had chosen easy numbers (85 and 95kHz) but these could change. > > Would increasing the bin width help to reduce the spectral leakage?
Bin width is just slang for the frequency spacing between elements of the Fourier series. (That's right: series. An FFT is a /series/ of numbers, each applying to a discrete frequency. You can't compute continuous functions with a computer.) Any frequency not strictly a member of the Fourier series derivable from the sequence if samples is spread into all the frequencies that are members to a greater or lesser extent. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;