Hi,
I’m using the inverse FFT to create an impulse response for a FIR filter.
Given a frequency response I need to fill in the fft buffer. I want a linear phase response. I’m not sure if I filled in the phase correctly because I do not get a symmetrical impulse response. And to my knowledge a linear phase filter should have a symmetrical impulse response. Right?
This is the code to fill in the fft input buffer:
float *fftBuf = new float[fftSize*2];
float *bPtr = fftBuf;
// set DC bin
*bPtr++ = *freqResponse++; // cos
*bPtr++ = 0.0f; // sin
// fill the remaining bins
int numBins = fftSize/2;
for (int b=1 ; b<numBins ; b++) {
// linear phase (not sure how exactly)
float phase = (float)b * MathConstants<float>::twoPi / (float)(numBins);
// get amplitude
float amp = *freqResponse++;
// convert so sin and cos
*bPtr++ = amp * cosf(phase);
*bPtr++ = amp * sinf(phase);
}
// the nyquist bin should also be 0?
*bPtr++ = 0.0f;
*bPtr++ = 0.0f;