>On 9/27/12 1:02 PM, karanbanthia wrote: >> >> My input frequency is exactly at every bin center. Sampling frequencyis>> 128Hz and N=12, so frequency bin resolution is 1Hz and I am varyingthe>> 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." > > >Oh, Sorry... yes- N=128!
Wrong Amplitude After FFT Calculation!
Started by ●September 18, 2012
Reply by ●September 27, 20122012-09-27
Reply by ●September 27, 20122012-09-27
On 9/27/12 4:09 PM, karanbanthia wrote:> > Oh, Sorry... yes- N=128!okay so now i'm looking at your original: On 9/18/12 2:13 PM, karanbanthia 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 > am calculating frequency and amplitude. I am using MPLAB C30 compiler and > DSP library.so what does your Blackman window sum up to be? more specifically, what is its mean value? that is a scaling factor you need to make use of. then you have to know whether or not your DFT puts a 1/N in front of the summation or not. the FFT is merely an efficient method of calculating the DFT. so go to Oppenhiem and Shafer or to Rick Lyon's book and look at the summation formula for the DFT. now, the less common convention for the inverse DFT is N-1 x[n] = SUM{ X[k] e^(j 2 pi n k/N) } k=0 then the DFT is N-1 X[k] = 1/N SUM{ x[n] e^(-j 2 pi n k/N) } n=0 this means that if you do the complex math, that *without* a window, a cosine of amplitude A and bin frequency of K cycles per N samples: x[n] = A cos(2 pi K n/N) that must result in X[k] = 0 for all k except x[K] = cong{ X[N-K] } = A/2 now the common convention is that the 1/N goes on the other summation (for x[n]) so then X[k] is scaled greater by a factor of N x[K] = X[N-K] = N A/2 you take one of these amplitudes and scale it by the *mean* of your Blackman window and that should get exactly what lives in bin K and bin N-K. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●September 28, 20122012-09-28
Am 27.09.12 19:07, schrieb karanbanthia:>> 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 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??Windowing your signal s(t) with the function W(t) results in a convolution in frequency domain s(w) x W(w) (with x = convolution, w = frequency). For a pure sinusoidal inpt signal, that means that you get a copy of the FT of your window function centered at the frequency of your sinusoidal, sampled at the integer bins of your FFT W(w-w_c). The question then reduces to "How can I reconstruct the amplitude of that sampled copy?" You should get the exact same answer in the case where w_c is an integer frequency, i.e. the sine wave fits exactly an integer number into your time sequence - note, that the last value is then different from the first! In the general case, try to make use of Parseval's equation: The sum of squares is invariant under the fourier transform. So I would compute the FFT of the window function alone and do: alpha = sum(W(t)^2) beta = sum(W(w)^2) Then from the FFT of the windowed signal WS(w) P = sum(WS(w)^2) a few samples around the peak (width of your window function in frequency domain W(w)) The amplitude of the original signal should be: A = sqrt(P * alpha / beta) The good news: Due to windowing, this should not change much fractional changes of the frequency. The bad news: It is frequency and phase dependent. Especially for lower frequencies, the shape of your window function is similar to the shape of the signal. Christian
Reply by ●September 28, 20122012-09-28
Something to try: Replace utoa(txt,(unsigned int)(peaksqrt),10); with utoa(txt,(unsigned int)(peak),10); This will get rid of the integer sqrt function. See if that helps.
Reply by ●September 28, 20122012-09-28
On 9/27/12 4:09 PM, karanbanthia wrote:> > Oh, Sorry... yes- N=128!i don't usually nag, karanbanthia, but i spelled out exactly what the scaling issues are. you have two questions to answer and if you get to the bottom of those two questions, you will either have the correct amplitudes in your FFT bins *or* you will know that something isn't working correctly. my brain cells are gonna forget about this in a day or two. if you want any other help from me, deal with those two questions and get back. otherwise, as i see how this thread is going, you're just spinning your wheels and no one can help you. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●October 3, 20122012-10-03
>On 9/27/12 4:09 PM, karanbanthia wrote: >> >> Oh, Sorry... yes- N=128! > >okay so now i'm looking at your original: > >On 9/18/12 2:13 PM, karanbanthia 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 amusing>> as input. When I vary the input frequency, FFT detects the frequency >> correctly till 64Hz (i.e. Fs/2) but it gives different amplitude valuesfor>> 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 whereI>> am calculating frequency and amplitude. I am using MPLAB C30 compilerand>> DSP library. > > >so what does your Blackman window sum up to be? more specifically, what >is its mean value? that is a scaling factor you need to make use of. > >then you have to know whether or not your DFT puts a 1/N in front of the >summation or not. the FFT is merely an efficient method of calculating >the DFT. so go to Oppenhiem and Shafer or to Rick Lyon's book and look >at the summation formula for the DFT. > >now, the less common convention for the inverse DFT is > > N-1 > x[n] = SUM{ X[k] e^(j 2 pi n k/N) } > k=0 > >then the DFT is > > N-1 > X[k] = 1/N SUM{ x[n] e^(-j 2 pi n k/N) } > n=0 > > >this means that if you do the complex math, that *without* a window, a >cosine of amplitude A and bin frequency of K cycles per N samples: > > > x[n] = A cos(2 pi K n/N) > > >that must result in X[k] = 0 for all k except > > x[K] = cong{ X[N-K] } = A/2 > > >now the common convention is that the 1/N goes on the other summation >(for x[n]) so then X[k] is scaled greater by a factor of N > > > x[K] = X[N-K] = N A/2 > > >you take one of these amplitudes and scale it by the *mean* of your >Blackman window and that should get exactly what lives in bin K and binN-K.> > >-- > >r b-j rbj@audioimagination.com > >"Imagination is more important than knowledge." > > >Thanks! This indeed helped. I got the correct amplitude now!






