[gstreamer-bugs] [Bug 492098] [GstFFT] Broken scaling

GStreamer (bugzilla.gnome.org) bugzilla-daemon at bugzilla.gnome.org
Mon Nov 5 23:49:48 PST 2007


If you have any questions why you received this email, please see the text at
the end of this email. Replies to this email are NOT read, please see the text
at the end of this email. You can add comments to this bug at:
  http://bugzilla.gnome.org/show_bug.cgi?id=492098

  GStreamer | gst-plugins-base | Ver: HEAD CVS




------- Comment #2 from Sebastian Dröge  2007-11-06 07:49 UTC -------
Ok, now a bit better explaination ;)

First of all, take a look at
http://en.wikipedia.org/wiki/Discrete_Fourier_transform

For floating point this can be taken more or less as a reference...
As can be seen there, you'll need a 1/nfft somewhere to get iFFT(FFT(x))==x
behaviour. Our current implementation of the FFT does exactly that for floating
point, so to a) get the original output back you have to either divide the FFT
output by nfft or the iFFT output (as the FFT is linear it doesn't matter). b),
to calculate the magnitude and get the gain for different frequency bins from
that you also have to divide the output of the FFT by nfft to get proper
results.



For fixed point things are unfortunately a bit more complicated as overflows
can happen (sure, they can happen to floating point too but that's rather
unlikely here). To quote kissfft upstream:

> Consider the case of a radix-2 fft. At every stage of the FFT there is
> an addition operation that causes word growth of 1 bit.
> So at each stage, there is a division by two to prevent the possibility 
> of overflow.  With log2(Nfft) stages, there is an overall division by 
> 2^log2(Nfft) == Nfft

So that's why you get iFFT(FFT(x)) = x/nfft. For getting the original input
again you have to take special care with fixed point samples for this reasons.
For example you could do the following:

- Analyse the time domain data and get the highest integer C that won't give a
overflow if all samples are multiplied with it.
- Multiply them all with C.
- get FFT(x) = X.
- get iFFT(X) = C*x / nfft and multiply by nfft, divide by C.

This will always give you the original data back as accurate as possible.



So my proposal for 0.10.15 is to simply document this behaviour (it can't get
much better for the above mentioned reasons) and remove the magnitude and phase
calculation functions as they're pretty useless even for the spectrum element.


-- 
See http://bugzilla.gnome.org/page.cgi?id=email.html for more info about why you received
this email, why you can't respond via email, how to stop receiving
emails (or reduce the number you receive), and how to contact someone
if you are having problems with the system.

You can add comments to this bug at http://bugzilla.gnome.org/show_bug.cgi?id=492098.




More information about the Gstreamer-bugs mailing list