# Difference equation to FIR filter coefficients

I have a difference equation

$$y[n] = y[n-1] + 0.5x[n] - 0.5x[n-2] \text{.}$$

According to this answer, the filter should have finite impulse response. I just can't figure out how to get the FIR filter coefficients. I tried to use the transfer function.

$$Y(z) - Y(z)z^{-1} = 0.5X(z) - 0.5X(z)z^{-2}$$

$$H(z) = \frac{Y(z)}{X(z)} = \frac{0.5 - 0.5z^{-2}}{1-z^{-1}}$$

But here I got stuck. Can anyone tell me how to make this a non-recursive implementation?

You can simplify the z-transform further,

$$H(z) = \frac{Y(z)}{X(z)}= \frac{0.5-0.5z^{-2}}{1-z^{-1}}$$

$$H(z) = \frac{(1-z^{-1})(1+z^{-1})}{2(1-z^{-1})}$$

canceling the common pole and zero

$$H(z) = \frac {1+z^{-1}}{2}$$

take inverse z-transform

$$Y(n) = \frac{x(n)+x(n-1)}{2}$$

• How simple. I wouldn't figure out that the polynomial could be factorized. Jun 6 at 12:10

There is already a good answer, but here is some extra explanation.

This is called "pole/zero cancellation". That means you have a pole, say, $$z_p$$ but you also have a zero at $$z_p$$ so the zero cancels the pole.

One particular example where this can be useful is a moving average filter of length $$N$$, The transfer function is

$$H(z) = \frac{1}{N} \sum_{n=0}^{N-1} z^{-n} = \frac{1}{N} \cdot \frac{1-z^{-N}}{1-z^{-1}}$$

That makes the difference equation

$$y[n] = \frac{1}{N}\sum_{k=0}^{N-1} x[n-k] = y[n-1] + \frac{1}{N} (x[n]-x[n-N])$$

The FIR form of the difference equation has $$N$$ coefficients, but the IIR form with pole cancelation has only three non-zero coefficients, so it's often more efficient to implement it that way.

• That was interesting but did you mean minus rather than equals in the last equals ? Jun 6 at 13:48
• Yes, or course. Thanks for pointing it out. Fixed. Jun 6 at 14:55
• i think it's called "pole-zero cancellation", ain't it, Hil? Jun 6 at 16:36
• Fixed. I've seen both terms used. Jun 6 at 17:04