40 likes | 157 Views
FIR and IIR Filters with on and off Functionality. By: Nitin Jalan For: Dr. V. Kepuska Subject: Microcomputer System 1. IIR Filter: High And Low Pass. //Low pass filter IIR function void lowpassfilter_IIR(void) {
E N D
FIR and IIR Filters with on and off Functionality By: Nitin Jalan For: Dr. V. Kepuska Subject: Microcomputer System 1
IIR Filter: High And Low Pass • //Low pass filter IIR function • void lowpassfilter_IIR(void) • { • float x = (float)(iChannel0LeftIn<<8); //shifts bits of the float x 8 bits to the left • int s; • for(s = 0; s <= 2; s++) //increments s from 0 to 2 • { • lpd0[s] = x - (lpA1[s]*lpd1[s]) - (lpA2[s]*lpd2[s]); //delay equation • x = (lpB2[s] * lpd2[s]) + (lpB1[s] * lpd1[s]) + (lpB0[s] * lpd0[s]); //output equation • lpd2[s] = lpd1[s]; //shifts the delays each sampling • lpd1[s] = lpd0[s]; • } • iChannel0LeftOut = ((int)x) >> 8; //shifts the output back 8 bits to the right • }
FIR FIltters: High Pass and Low PAss • void highpassfilter_FIR(void) • { • x[n] = (fract16) (iChannel0RightIn>>8); //shifts the x[n] 8 bits to the right • if (variables<1024) • { • buffer[variables++]= x[n]; //Buffer • } • output = 0; //sets the output to 0 • for(p=0; p<101; p++) • { • output = add_fr1x16(output, mult_fr1x16(x[(n-p+101) %101],yhp[p])); //filter delay equation including circular buffer • //uses fract16 funcions • } • n++; //increment pointer • n = n % 101; //keeps the pointer positive • iChannel0RightOut=((int)(output))<<8; //Output is shifted back 8 bits to the left • }
References • my.fit.edu/~vkepuska/ece3551 • Christian Stumf and Ryan Boleman Lab