Description

Guitar and Audio technology blog

Monday 20 December 2010

Biquad notch filter


Following the last blog post more code has been written making a functioning biquad notch filter.  Although there is some aliasing produced the filter acts a notch filter with the peak around the 8khz range.  The filter works very well as a high pass filter as it cuts all low frequencies.  Switch statements are used to make sure the correct samples for previous inputs and outputs are used. The code is as follows:

void Laneycub10::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
float* in = inputs[0];
float* out1 = outputs[0];
float* out2 = outputs[1];

float a0 = 1;
float a1 = 0;
float a2 = -1;
float b1 = 0.1;
float b2 = 0.9;
float xn0 = 0;
float xn1 = 0;
float xn2 = 0;
float yn1 = 0;
float yn2 = 0;
while (--sampleFrames >= 0)
{
float x = *in++;
switch (xcursor) {
case 0:
xn0 = xbuffer[xcursor];
xn1 = xbuffer[2];
xn2 = xbuffer[1];
break;

case 1:
xn0 = xbuffer[xcursor];
xn1 = xbuffer[0];
xn2 = xbuffer[2];

break;

case 2:
xn0 = xbuffer[xcursor];
xn1 = xbuffer[1];
xn2 = xbuffer[0];

break;

}

switch (ycursor) {
case 0:

yn1 = ybuffer[2];
yn2 = ybuffer[1];
break;

case 1:

yn1 = ybuffer[0];
yn2 = ybuffer[2];

break;



}


float y = a0*xn0 + a1*xn1 + a2*xn2 - b1*yn1 - b2*yn2;
xbuffer[xcursor++] = x;
ybuffer[ycursor++] = y;


if (xcursor == size)
xcursor = 0;
if (ycursor == size) //failsafe W cursor should never reach size
ycursor = 0;

*out1++ = y;

No comments:

Post a Comment