An Nth-order linear constant-coefficient difference equation is of the form
The frequency response of such a system can be determined by finding its impulse response h[n], and taking the Fourier transform of h[n]. In this week's lab, you will implement a second-order difference equation in real time, measure its frequency response, and compare it to the theoretical response.
Consider the difference equation
org x:$100 ; put data starting at $100 in X data space ynm1 ds 1 ; set aside one word for y[n-1]
You also need to set aside storage for the coefficients a1, a2, b0, b1, b2, and b3. Here is how you might do that:
org y:$0 ; put data starting at $0 in Y data space a1 dc -0.5 ; set aside one word for a1
You could then calculate y[n] like this:
move x:ynm1,x0 move y:a1,y0 mpy -x0,y0,a ; -a1 y(n-1) -> acc a move x:ynm2,x0 move y:a2,y0 mac -x0,y0,a ; -a1 y(n-1) -a2 y(n-2) -> acc a
When you get done calculating y[n] you will need to update your variables: what is now x[n-1] will, next time through, be x[n-2]:
move x:xnm1,x0 ; Replace x[n-2] by x[n-1] for next pass move x0,xnm2 ; through filter