John Reynolds
Member
I've been experimenting with first order filters for a bass preamp. I've been able to get a Low Pass filter working just fine by calculating the coefficients with this code:
I spent a long time trying to get a first order High Pass filter to work using this same structure, but was not successful. According to the references I looked at it should just be a matter of changing coefficients[3] from "-k" to "k" and coefficients[0] to "1 - abs(k)." And apparently there's a need to "invert the spectrum" by changing, "freq /AUDIO_SAMPLE_RATE" to "0.5 - (freq / AUDIO_SAMPLE_RATE)." But nothing I tried seemed to work.
However, I WAS able to implement a fine first order High Pass filter by simply subtracting the LPF output from its input signal, using a Mixer object! So my current needs for this project are satisfied
But my question is, "Was I doing something wrong in my implementation of a High Pass filter or did I just run up against numerical precision issues?" I was using the standard 44.1KHz sample rate with a cutoff frequency in 2KHz range.
Seems like this should have been easy and just wondering if I was missing something!
Thanks,
John
Code:
// --------------------------------------
// Calculate first-order LPF coefficients
double coefficients[5]= {0,0,0,0,0};
void calcCoefficients(float freq){
double k = exp(-2 * PI * freq / AUDIO_SAMPLE_RATE);
coefficients[0] = 1-k; coefficients[3] = -k;
}
I spent a long time trying to get a first order High Pass filter to work using this same structure, but was not successful. According to the references I looked at it should just be a matter of changing coefficients[3] from "-k" to "k" and coefficients[0] to "1 - abs(k)." And apparently there's a need to "invert the spectrum" by changing, "freq /AUDIO_SAMPLE_RATE" to "0.5 - (freq / AUDIO_SAMPLE_RATE)." But nothing I tried seemed to work.
However, I WAS able to implement a fine first order High Pass filter by simply subtracting the LPF output from its input signal, using a Mixer object! So my current needs for this project are satisfied
But my question is, "Was I doing something wrong in my implementation of a High Pass filter or did I just run up against numerical precision issues?" I was using the standard 44.1KHz sample rate with a cutoff frequency in 2KHz range.
Seems like this should have been easy and just wondering if I was missing something!
Thanks,
John