I’m trying to create a direct-form FIR filter to match a given frequency-magnitude equation. ie. Let’s say you have a simple equation like:

y = 1.001^(-f), where y gives amplitude/magnitude from 0 to 1, and f is frequency in Hz.

Then say the FIR filter should be usable between 0 Hz (or close to it) and 20 kHz at 44100 kHz sampling. Let’s say there are 20 taps, so we need 20 coefficients in the end.

I understand the absolutely simplest method is to just calculate the magnitudes at the centers of my FIR bins from my magnitude equation. I can assign those in an array, and perform a real-only inverse FFT to convert it to the time domain, and window it to smooth it out.

So if that’s right I would need to do three steps.

**1) Real-Only Inverse FFT:**

I understand each bin is `sampleRate / numPoints`

(Hz) wide. And I need the center of each bin.

```
for (int i=0; i < numBins; i++){
binWidth = sampleRate/numBins;
centerFreq = 0.5*binWidth + (binWidth * i);
magnitude = 1.001^(-centerFreq);
magnitudeDb = Decibels::gainToDecibels(magnitude);
magnitudeArray[i] = magnitude;
magnitudeDbArray[i] = magnitudeDb;
}
```

So now I have all my bin center freqs, and their magnitudes. I also put them in vectors. What next?

The Juce FFT library has a real-only inverse FFT:

`void dsp::FFT::performRealOnlyInverseTransform ( float * inputOutputData ) const`

How would I process my frequency-magnitude data into a format that this function could appropriately take?

Also the manual says I first need to create the FFT with 2^order points. Is this just the maximum size the FFT can process? Ie. if I set it to 2^8 = 256, that would be more than ample for producing a 50 bin/coefficient FIR right?

**2) Windowing**

I’ve read the differences between different windowing methods here.

I see the JUCE class is defined here:

https://docs.juce.com/master/classdsp_1_1WindowingFunction.html

So do I just create the window, set the type, set the size, and then multiply it against my coefficients from the real-only iFFT?

What is the proper size to set for the window? Is it equal to the number of real coefficients I get from the iFFT above?

If you could be willing to write a few lines of rough code to show how this would work, particularly in terms of how I could put my magnitude levels for the bins into the real-only iFFT, I’d appreciate it immensely. Thanks.