[Feature Requests + issues] FFT class and rescaling


#1

Hello Jules and the ROLI team !

I have a request about the new FFT class. I was having fun with it last week, and I noticed there is no rescaling function or no information about the rescaling which must occur when we take the FFT of the signal and then its inverse FFT. I was wondering if the rescaling was done automatically or not like in some other FFT librairies. Finally, I digged into the source code to see that nothing is done, which means a user needs to do it manually.

So, what I would like if possible, would be to add a new function "rescaling" in the FFT class which takes an array of float or complex numbers and divides all the samples by the current FFT size. Moreover, it would be great if the need to rescale the samples is written somewhere in the FFT documentation, so everything is clear enough. Right now, for someone who wants to use the FFT class of JUCE and who has never used a FFT before, the class might be misleading...

Thanks in advance !

Ivan


#2

A few other things :

  • I think the perform function doesn't rescale the output when isInverse = true, but performRealOnlyInverseTransform rescales !
  • It is not logical to have two functions performRealOnlyForward and performRealOnlyInverse if a jassert is called when the object is created with the wrong isInverse in parameter. Maybe the class should have only a performRealOnly function.
  • It is written in the documentation that the performRealOnlyForward function output contain complex frequency and phase data. That doesn't mean anything : it is either a complex number (real + imag data) or it is real frequency + real phase. Indeed, the truth is  : complex number. It would be good to write also in the documentation how the information is organized. At first I thought it was N real and then N imag but the truth is (real imag) N times instead.
  • Finally, since the performRealOnlyForward and performRealOnlyInverse act on real samples in the time domain, it could be possible to use parameters arrays with the size N or N+1 instead of N * 2 since the data in the frequency domain needs to be symmetric (for real parts and antisymmetric for imag parts)...

Thanks in advance !

(I had a hard time making a convolution algorithm work with JUCE's FFT lol)


#3

Hi Wolfen,

Thanks for the comments. I have to admit that I am not really an FFT expert when it comes to audio - I know it from physics - so sorry for that ;-) but looking at that class now, to me it would actually make more sense to have the inverse FFT rescale the data automatically (as a physicist I'd call it "normalisation"), rather than introducing  a rescaling function. So that if you FFT some data and then immediately inverse-FFT it back, you get the same units as before. What do you think?

Second bullet point in your second post: yes I agree, and actually I don't like the idea very much that you have to define in the *constructor* whether the FFT is inverse or not. I'll think about how to make it better.


#4

Hello timur !

You are right about the rescaling or normalization. The issue for me was that it is done automatically in performRealOnlyInverse but not in perform when isInverse=true. So, this operation should be either done automatically in both functions, or not done at all but the FFT class might provide a function rescale or normalize. And all this stuff should be well documented in the class documentation so everything is clear for developers using it.

Thanks for having a look into this, and if you have any audio related question, or if I can do anything to help, don't hesitate to ask ;)


#5

Great - I'll add the normalisation and update the docs.

In any case, this is a very minimal FFT class, more for fun than for high performance, so I'd rather not invest too much time into this :-) It is possible that we may have something a bit more professional at some point in the future...


#6

In any case, this is a very minimal FFT class, more for fun than for high performance, so I'd rather not invest too much time into this :-) It is possible that we may have something a bit more professional at some point in the future...

I know I know, but since it's here and it's still useful, I think it would be great to have a set of minimal features, until you do something more professional in the future ;) For example, I'm using FFTReal 2.11 all the time, but for some project I needed to be able to do FFT with complex numbers, and I did it with JUCE's FFT.