Hello all,
I am not able to get the correct amplitude of input signal from DFT. My
sampling frequency is 128Hz and I am take 128 Samples and computing
128-point FFT. I also have a simulated sine wave generator which I am using
as input. When I vary the input frequency, FFT detects the frequency
correctly till 64Hz (i.e. Fs/2) but it gives different amplitude values for
different frequencies even though I am not changing the amplitude, why is
this so??
I am using Blackman window and following is a part of my main code where I
am calculating frequency and amplitude. I am using MPLAB C30 compiler and
DSP library.
while(1)
{
if(startcalc==1)
{
testpin = 1;
VectorWindow(numofsamples,&storedreading[0].real,&storedreading[0].real,&windowcoeff[0]);
FFTComplexIP (log2n, &storedreading[0], (fractcomplex *)
__builtin_psvoffset(&twiddleFactors[0]), (int)
__builtin_psvpage(&twiddleFactors[0]));
BitReverseComplex (log2n, &storedreading[0]);
SquareMagnitudeCplx(numofsamples, &storedreading[0],
&storedreading[0].real);
peak = VectorMax((numofsamples/2), &storedreading[0].real,
&peakFrequencyBin);
peaksqrt = _Q15sqrt(peak);
utoa(txt,(unsigned int)(peaksqrt),10);
cmd(0x80); // Move to 1st Row, 1st Column
send_string(txt); // Sends string to LCD for display
itoa(txt,peakFrequencyBin,10);
cmd(0xc0); // Move to 2nd ROw, 1st Column
send_string(txt);
testpin = 0;
startcalc=0;
TMR3 = 0x0000;
SR = 0x0000; // Set CPU Priority to 0
}
else;
}
Wrong Amplitude After FFT Calculation!
Started by ●September 18, 2012
Reply by ●September 18, 20122012-09-18
You'll only have equal amplitudes when the input frequencies are integer multiples or each other. For example, if all your input frequencies are bin-centered, then you'll get equal, and maximum, amplitudes.
Reply by ●September 18, 20122012-09-18
On 9/18/2012 11:13 AM, karanbanthia wrote:> Hello all, > I am not able to get the correct amplitudeThe numbers aren't "wrong" or "incorrect", it's your understanding / interpretation of them. As David Drumm mentions, it depends on the relationship between the frequency sampling interval and the frequency of the sinusoid. Otherwise you get "scalloping losses" and "spectral leakage". Fred
Reply by ●September 19, 20122012-09-19
On 9/18/2012 11:13 AM, karanbanthia wrote:> Hello all, > I am not able to get the correct amplitudeI'm not familiar with your code or compiler, so I can't comment on that. However, you will have leakage when the frequency of your input sinusoid doesn't exactly match the frequency of one of your FFT output bins (your input will spread out into (mostly) adjacent bins). In addition, windowing will lower the values of your inputs, thus affecting your amplitude estimates. One way to compensate for this is to scale your outputs differently. For instance, you can simply get a sum of the window points (eg: sumw = w(0) + w(1) + w(2) + � + w(127) ), then, after the FFT, you'd scale by multiplying all FFT outputs by 1/sumw. The value of sumw, will, of course, depend on the window you're using. So, if your input amplitude is, say, 10, and your input frequency exactly matches the frequency of an FFT output bin, then using 1/sumw to scale will result in an amplitude of 5 at both the positive and negative frequencies. Kevin McGee
Reply by ●September 19, 20122012-09-19
On Sep 18, 2:13�pm, "karanbanthia" <62112@dsprelated> wrote:> Hello all, > I am not able to get the correct amplitude of input signal from DFT. My > sampling frequency is 128Hz and I am take 128 Samples and computing > 128-point FFT. I also have a simulated sine wave generator which I am using > as input. When I vary the input frequency, FFT detects the frequency > correctly till 64Hz (i.e. Fs/2) but it gives different amplitude values for > different frequencies even though I am not changing the amplitude, why is > this so?? > I am using Blackman window and following is a part of my main code where IThere are 2 effects: 1 - Coherent loss - even when the frequency falls right on an FFT bin, the window normally tapers off the energy near the end of the time series. For a given window this effect is deterministic. 2 - Spectral leakage - when the frequency doesn't fall directly on an FFT bin. The FFT spreads the energy across multiple FFT bins. A couple of possible solutions 1 - Use a Flattop window - It's designed to be used when measuring amplitude, The trade off, of course is resolution and sidelobe levels 2 - If there are no other frequencies close by, you can use the neighbouring FFT bins to interpolate to both the frequency and the amplitude. As an example using a blackman window - measure the amplitudes of frequencies measured every 0.1 FFT bin apart. So you have a table of 10 values. Next when measuring the amplitude of your real signal you measure the peak FFT value and the largest FFT bin beside it. The difference in the amplitude is looked up in your table and you can interpolate the value to get a better estimate. There are a few variations on the theme of #2. Cheers, Dave
Reply by ●September 19, 20122012-09-19
Here's a good article about scalloping loss and efficient fixes: http://www.dspguru.com/dsp/tutorials/reducing-fft-scalloping-loss-errors-without-multiplication
Reply by ●September 27, 20122012-09-27
>On 9/18/2012 11:13 AM, karanbanthia wrote: >> Hello all, >> I am not able to get the correct amplitude > >The numbers aren't "wrong" or "incorrect", it's your understanding / >interpretation of them. > >As David Drumm mentions, it depends on the relationship between the >frequency sampling interval and the frequency of the sinusoid. > >Otherwise you get "scalloping losses" and "spectral leakage". > >Fred > > > >My input frequency is exactly at every bin center. Sampling frequency is 128Hz and N=12, so frequency bin resolution is 1Hz and I am varying the input frequency in integer multiples of 1Hz.
Reply by ●September 27, 20122012-09-27
>On Sep 18, 2:13=A0pm, "karanbanthia" <62112@dsprelated> wrote: >> Hello all, >> I am not able to get the correct amplitude of input signal from DFT. My >> sampling frequency is 128Hz and I am take 128 Samples and computing >> 128-point FFT. I also have a simulated sine wave generator which I amusi=>ng >> as input. When I vary the input frequency, FFT detects the frequency >> correctly till 64Hz (i.e. Fs/2) but it gives different amplitude valuesf=>or >> different frequencies even though I am not changing the amplitude, whyis>> this so?? >> I am using Blackman window and following is a part of my main code where=>I > >There are 2 effects: >1 - Coherent loss - even when the frequency falls right on an FFT bin, >the window normally tapers off the energy near the end of the time >series. For a given window this effect is deterministic. > >2 - Spectral leakage - when the frequency doesn't fall directly on an >FFT bin. The FFT spreads the energy across multiple FFT bins. > >A couple of possible solutions > >1 - Use a Flattop window - It's designed to be used when measuring >amplitude, The trade off, of course is resolution and sidelobe levels > >2 - If there are no other frequencies close by, you can use the >neighbouring FFT bins to interpolate to both the frequency and the >amplitude. As an example using a blackman window - measure the >amplitudes of frequencies measured every 0.1 FFT bin apart. So you >have a table of 10 values. Next when measuring the amplitude of your >real signal you measure the peak FFT value and the largest FFT bin >beside it. The difference in the amplitude is looked up in your table >and you can interpolate the value to get a better estimate. > >There are a few variations on the theme of #2. > >Cheers, >Dave > >Even after using Flat-Top window, I am unable to detect the amplitude correctly. Is it that multiplication of window with input sequence in time domain results in convolution in frequency domain which may result in error? Does performing overlap fft method improve amplitude accuracy?
Reply by ●September 27, 20122012-09-27
>Here's a good article about scalloping loss and efficient fixes: > >http://www.dspguru.com/dsp/tutorials/reducing-fft-scalloping-loss-errors-without-multiplication >Scalloping loss wouldn't result when I am using a Flat-top window, right?
Reply by ●September 27, 20122012-09-27
On 9/27/12 1:02 PM, karanbanthia wrote:> > My input frequency is exactly at every bin center. Sampling frequency is > 128Hz and N=12, so frequency bin resolution is 1Hz and I am varying the > input frequency in integer multiples of 1Hz.did you lose a digit? is N=128? -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."






