FIR 2kHz Bandstop Comb Filter
This will filter out a 2kHz that may be corrupting your input signal.
#define COMB_FILTER_ORDER 3 // Filter Order, i.e., M
#define DELAY_ARRAY_SIZE 9 // Number of (delayed) input samples to store
int filtersum; // Sum-of-products accumulator for calculating the filter output value
int delay[DELAY_ARRAY_SIZE]; // Array for storing (delayed) input samples
static int gain1 = 1;
static int gain2 = 4;
interrupt void isr() //Interrupt service routine
{
short i; // Loop counter
delay[0] = get_sample() / gain1; // Read filter input sample from ADC and scale the sample
filtersum = delay[0]; // Initialize the accumulator
for (i = COMB_FILTER_ORDER; i > 0; i--)
{
filtersum += delay[i]; // Accumulate array elements
delay[i] = delay[i-1]; // Shift delay elements by one sample
}
filtersum *= gain2; // Scale the sum-of-products
send_output(filtersum); // write filter output sample to DAC
return; // interrupt servicing complete
}
void main()
{
short i; // loop counter
for (i=0; i< DELAY_ARRAY_SIZE; i++) // Initialize delay elements with 0
{
delay[i] = 0;
}
init_all(); // global initialization
while(1); // infinite loop
// do nothing except wait for the interrupt
}