On Wed, Nov 04, 2015 at 08:56:05AM -0800, Phil Burk wrote:
> What is the "right" way to scale the inputs of an FFT.
> 
> I have implemented some FFT functions in JSyn. The goal is to support
> spectral analysis, processing and synthesis for music applications.
> 
> I would like to be able to measure the amplitude of various sinewave
> partials in the original signal. With my current scaling, if I do an FFT of
> a sine wave with amplitude 1.0 aligned with a bin then the magnitude comes
> out 1.0.
> 
>     magnitude = sqrt(real*real + imag*imag);
> 
> Also my FFT and IFFT are inverse functions:   x==IFFT(FFT(x))
> 
> My current scale factors are 2.0/M for FFT and 0.5 for IFFT. I am happy
> with this. But I see many conflicting recommendations in the literature
> that suggest I am doing it wrong.
> 
> In this MatLab forum,
> http://www.mathworks.com/matlabcentral/answers/15770-scaling-the-fft-and-the-ifft
> they recommend  1/M and M, or 1/sqrt(M) and sqrt(M).  They say it is
> important that the product of the scale factors is 1.0. But then the IFFT
> is not the exact inverse of the FFT.
> 
> Is there a "right" way or a "wrong" way or is there just "my" way?

Generally I prefer to scale the values only one time, at the end of
the game.  I'm using FFTW library [1] with Incudine [2], and the
original transforms r2c and c2r (luckily) are unnormalized. Instead
of scaling the result of r2c, I update the scaling factor within the
structure used for the fft. For example, after

    (defvar *fft* (make-fft 1024))
    (describe *fft*)
    ...
    SCALE-FACTOR = 9.765625d-4
    ...

If it is necessary to process the result of the analysis, I use
separated analysis buffers (inspired by ChucK's UAnaBlob [3]).
If a process further scales the data, for example by sqrt, only the
scaling factor of the analysis buffer is updated instead of
normalizing all the values, i.e.

    scl = sqrt(scl) = 1/sqrt(N)

and the scaling factor of the original fft remains the same, so it is
possible to use other analysis buffers to do other parallel processing.

Finally, the ifft routine scales the unnormalized original c2r by the
(possibly updated) scaling factor of the analysis buffer.

Besides, if ifft is used without fft, the scaling factor is simply 1
(with an internal and fixed scaling factor, it is necessary to scale
the values of the input buffer of the ifft: x*m/m).

Tito


[1] http://fftw.org/

[2] http://incudine.sourceforge.net/

[3] http://chuck.cs.princeton.edu/doc/language/uana.html
_______________________________________________
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp

Reply via email to