Hey guys, I'm trying to implement a simple 2 pole IIR filter on my KL25Z. Coefficients were calculated using Matlab, it's a Butterworth Highpass, second order, Fs at 10 KHz, and Cut off at 60 Hz. I'm feeding in a mixed signal sin(2*pi*80*t)+sin(2*pi*175*t) which is generated by one of the boards to the the other board which is running the IIR filter program.

Here's the code: http://imgur.com/NDqYXfT

Here's what I'm feeding into my filtering board:http://imgur.com/d7NzRzG

Here's the filter board DAC output: http://imgur.com/Vmjn9LH

I'm expecting the 80Hz sinewave to remain at the output, or at least something similar (I know these filters are not perfect), but the output looks like an audiowave or some sort. Can't figure out why. You guys have an idea what it is or maybe there's some error in my code (most likely). Thanks a lot guys!

Hi, i have used IIR filters on mcu.

y[j]=B[0]*x[j]+B[1]*x[j-1]+B[2]*x[j-2]-A[1]*y[j-1]-A[2]*y[j-2]; A,B coefficients were from matlab, And it worked.

Your code looks good. But filter to work, for(;;) cycle must sample at 10kHzrate as you chosen in matlab. And now i dont see any timing in code, that means that it samples as fast as it can. Maybe thats a problem. I think that coefficients are correlated with sampling frequency, in matlab [B,A]=butter(order,Wn,'type'), Wn=0:1, Wn = fcutoff/fsampling. Nice oscilloscope thought.