# Juce fft

**URL:** <https://forum.juce.com/t/juce-fft/16992>\
**Category:** General JUCE discussion\
**Created:** [March 23, 2016, 11:34am UTC](https://forum.juce.com/t/juce-fft/16992 "2016-03-23T11:34:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nevos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nevos/32/23_2.png) [@nevos](https://forum.juce.com/u/nevos)\
**Post date:** [March 23, 2016, 11:34am UTC](https://forum.juce.com/t/juce-fft/16992/1 "2016-03-23T11:34:16Z")

</div>

Hi all,

I have a few questions about the built-in JUCE FFT, as I'm having trouble using it.

So as a very basic example, I initialise the FFT object with an order of 9 and inverse=false.&nbsp;I create an array that is twice the size of the fft size and fill the first half of it with the input buffer and the second half with zeros. Then, I perform an FFT on it using performRealOnlyForwardTransform(), which AFAIK, returns an interleaved array of real and imaginary components. I then take this array and perform an IFFT using performRealOnlyInverseTransform and store the first half of the result in the output buffer. So theoretically, whatever audio passes through it should remain unchanged. However, it seems like the result of the IFFT contains values outside the range of -1 to 1 and I get a very distorted result.

Do we need to normalise the output of the IFFT? Also, what does the inverse boolean do? Do I need to set it to true in order to be able to perform an IFFT? I get a jassert error when I do. :/

&nbsp;

Thanks!

Nevo

---

<div class="post-metadata">

**Author:** ![\_pi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/_pi/32/527_2.png) [@\_pi](https://forum.juce.com/u/_pi)\
**Post date:** [March 23, 2016, 3:15pm UTC](https://forum.juce.com/t/juce-fft/16992/2 "2016-03-23T15:15:00Z")

</div>

This works:

```
int main (int, char*[]) {
     **FFT** fft **{**** 2 **_/\*bitstrength\*/_** , ****false** _/\*isInverse\*/_ **};**      **FFT** inv **{**** 2 **_/\*bitstrength\*/_** , ****true &nbsp;** _/\*isInverse\*/_ **};**     float data[8] = { **1,2,3,4,** 0,0,0,0};_// time data_    fft. **performRealOnlyForwardTransform** (data);
    struct FreqData { float mag, phase; };
    auto freqdata = (FreqData*)data;
    inv. **performRealOnlyInverseTransform** (data);
    DBG(data[0]); DBG(data[1]); DBG(data[2]); DBG(data[3]); // 1 2 3 4
    return 0;
}
```

π

---

<div class="post-metadata">

**Author:** ![nevos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nevos/32/23_2.png) [@nevos](https://forum.juce.com/u/nevos)\
**Post date:** [March 24, 2016, 8:29am UTC](https://forum.juce.com/t/juce-fft/16992/3 "2016-03-24T08:29:55Z")

</div>

Didn't realise we're suppose to have two different FFT instances, one for forward and one for inverse. Thanks!

---

<div class="post-metadata">

**Author:** ![nevos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nevos/32/23_2.png) [@nevos](https://forum.juce.com/u/nevos)\
**Post date:** [March 27, 2016, 9:37pm UTC](https://forum.juce.com/t/juce-fft/16992/4 "2016-03-27T21:37:15Z")

</div>

It still doesn't work for me.

I have created two global&nbsp;variables&nbsp;​in the header file like so:

```
FFT invFFT;  
FFT forFFT;
```

Then instantiated them in the constructor like so:

```
MonsterizerAudioProcessor::MonsterizerAudioProcessor():
    invFFT(9, true),
    forFFT(9, false)
{
    //nothing here.
}
```

And then I use them like so. But I'm getting a jassert error. It seems like the inverse FFT enters the forward transform for some reason as the config object says inverse=true. fftInput is of length 1024 and I populate it with zeros before using it.

```
for (int channel = 0; channel < getTotalNumInputChannels(); ++channel){

    for(unsigned int n=0; n<512; n++){
        fftInput[n] = buffer.getReadPointer(channel)[n];
    }

    forFFT.performRealOnlyForwardTransform(fftInput);

    invFFT.performRealOnlyInverseTransform(fftInput);

    for(unsigned int n=0; n<512; n++){
       buffer.getWritePointer(channel)[n] = fftInput[n];
    }

}
```

Any idea why this doesn't work?

---

<div class="post-metadata">

**Author:** ![oxxyyd](https://avatars.discourse-cdn.com/v4/letter/o/e47c2d/32.png) [@oxxyyd](https://forum.juce.com/u/oxxyyd)\
**Post date:** [March 28, 2016, 12:33am UTC](https://forum.juce.com/t/juce-fft/16992/5 "2016-03-28T00:33:03Z")

</div>

Hmm, first you create&nbsp;two&nbsp;variables, then you instantiate them. What's the difference?

---

<div class="post-metadata">

**Author:** ![\_pi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/_pi/32/527_2.png) [@\_pi](https://forum.juce.com/u/_pi)\
**Post date:** [March 28, 2016, 3:24am UTC](https://forum.juce.com/t/juce-fft/16992/6 "2016-03-28T03:24:00Z")

</div>

I'm guessing you mean member variables rather than global variables.

Maybe you can evolve from my working example to your example over several small steps where you can check the result at each stage.

i.e. Get it working on a dummy waveform before applying it in an actual real-time audio render callback.

Maybe paste the whole file...

π

PS You will probably want to replace those loops with memcpy once you have it working

---

<div class="post-metadata">

**Author:** ![nevos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nevos/32/23_2.png) [@nevos](https://forum.juce.com/u/nevos)\
**Post date:** [March 28, 2016, 9:01am UTC](https://forum.juce.com/t/juce-fft/16992/7 "2016-03-28T09:01:01Z")

</div>

Hey pi,

I have copied and pasted your code into the processBlock function, but I still get the same error.

Please find attached a few screenshots. I tried redownloading JUCE and creating a new project but I get the same error over and over again.

Maybe an important detail is that I'm using REAPER 32-bit as the Xcode scheme for debugging and it works fine on other effects.

&nbsp;

Thanks again,

Nevo

PS, yeah I'm planning on replacing those. Just wanted to be completely sure I'm doing everything correctly.

---

<div class="post-metadata">

**Author:** ![nevos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nevos/32/23_2.png) [@nevos](https://forum.juce.com/u/nevos)\
**Post date:** [March 28, 2016, 9:02am UTC](https://forum.juce.com/t/juce-fft/16992/8 "2016-03-28T09:02:07Z")

</div>

Well&nbsp;first I declare them and then instantiate them using the FFT constructor.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [March 28, 2016, 11:37am UTC](https://forum.juce.com/t/juce-fft/16992/9 "2016-03-28T11:37:00Z")

</div>

BaptisteB solved a similar issue here: http://www.juce.com/forum/topic/issue-fft-plugin-inverse-transformation

Maybe that helps... using perform instead of performRealOnlyForwardTransform helped him...

Good Luck...  
&nbsp;

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [March 28, 2016, 11:41am UTC](https://forum.juce.com/t/juce-fft/16992/10 "2016-03-28T11:41:38Z")

</div>

You should try pulling from github. See this recent commit :-)

https://github.com/julianstorer/JUCE/commit/a6585b1ebf53025ad3ede385446b8cee95e1e3e0

---

<div class="post-metadata">

**Author:** ![nevos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nevos/32/23_2.png) [@nevos](https://forum.juce.com/u/nevos)\
**Post date:** [March 28, 2016, 12:13pm UTC](https://forum.juce.com/t/juce-fft/16992/11 "2016-03-28T12:13:00Z")

</div>

What an unfortunate typo :D. I downloaded the latest version from the JUCE website but now I'll work with github repo directly.

&nbsp;

Thanks!

---

<div class="post-metadata">

**Author:** ![nevos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nevos/32/23_2.png) [@nevos](https://forum.juce.com/u/nevos)\
**Post date:** [March 28, 2016, 12:18pm UTC](https://forum.juce.com/t/juce-fft/16992/12 "2016-03-28T12:18:27Z")

</div>

Thanks!&nbsp;
