Sign in

username or email:

password:



Not a member?
Forgot your password?

Search compdsp



Search tips

Ads

Discussion Groups

Free Online Books

See Also

Embedded SystemsFPGA

Discussion Groups | Comp.DSP | Wrong Amplitude After FFT Calculation!

There are 16 messages in this thread.

You are currently looking at messages 1 to .


Is this discussion worth a thumbs up?

+1

Wrong Amplitude After FFT Calculation! - karanbanthia - 2012-09-18 14:13:00

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;
}


______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - David Drumm - 2012-09-18 15:53:00



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. 
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - Fred Marshall - 2012-09-18 18:14:00

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



______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - kevin - 2012-09-19 02:37:00

On 9/18/2012 11:13 AM, karanbanthia wrote:


> Hello all,
> I am not able to get the correct amplitude

I'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
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - Dave - 2012-09-19 09:02:00

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 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

______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - David Drumm - 2012-09-19 12:18:00

Here's a good article about scalloping loss and efficient fixes: 

http://www.dspguru.com/dsp/tutorials/reducing-fft-scalloping-loss-errors-without-multiplication
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - karanbanthia - 2012-09-27 13:02:00

>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, so frequency bin resolution is 1Hz and I am varying the
input frequency in integer multiples of 1Hz.
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - karanbanthia - 2012-09-27 13:07:00

>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
usi>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 values
f>or
>> 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
>
>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?
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - karanbanthia - 2012-09-27 13:10:00

>Here's a good article about scalloping loss and efficient fixes: 
>
>http://www.dspguru.com/dsp/tutorials/reducing-fft-scalloping-loss-errors-without-multiplicat
ion
>

Scalloping loss wouldn't result when I am using a Flat-top window, right?
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Wrong Amplitude After FFT Calculation! - robert bristow-johnson - 2012-09-27 15:26:00

On 9/27/12 1:02 PM, karanbanthia wrote:
>
> My input frequency is exactly at every bin center. Sampling frequency is
> 128Hz and N,  so frequency bin resolution is 1Hz and I am varying the
> input frequency in integer multiples of 1Hz.

did you lose a digit?  is N8?



-- 

r b-j                  r...@audioimagination.com

"Imagination is more important than knowledge."


______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

| 1 | |