Hi,
I’m implementing an FIR filter (should be super simple!). I’m writing my own because being the genius I am I couldn’t figure out how to use an array of arbitrary coefficients in the dsp FIR method. Either way, I just want something that works for the time being - I’m not too worried about efficiency.
With all that said, my method works ALMOST correctly but I get occasionally 1-sample-off glitches that are periodic, so I think the loops are wrong, or the way I’m wrapping the pointer to the current sample in the circular buffer isn’t quite right, but I can’t work out the exact issue. It’d be wonderful if someone would take a look and see if they notice the issue.
float result = 0; // initialisation to 0 of the result
// For each sample
for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
{
bp = buffer_pointer[channel]; //bp is now the current index in the circular buffer
delayLine[channel][buffer_pointer[channel]] = channelData[sample]; //insert current input into circular buffer
result = 0;
for (int i = 0; i < filter_length; i++) { // for each tap
result = result + delayLine[channel][bp] * filterCoefs[i]; // multiply
bp--;
if (bp < 0)
bp += filter_length;
}
buffer_pointer[channel] = (buffer_pointer[channel] + 1) % filter_length; //update buffer pointer
channelData[sample] = result;
}
Where filter_length is the number of coefficients in the filter array.
Thanks for the help!
