# Subtract a digital filter from another filter

How to subtract a digital filter from another one, if their lengths are different. How to make the length equal.

• Add zeros to the shorter one? – Matt L. Aug 25 '17 at 9:55

If (and only if) the filters (either FIR or IIR) are linear, then you can subtract their coefficients term-wise, supposing they are correctly aligned (below, on the $0$ index), treating them as infinite series with trailing zeroes when the coefficients are not defined. For instance with:

$$h = [h_0, h_1, h_2]$$ and $$g = [g_{-1},g_0, g_1, g_2,g_3]$$

since the convolution with $h$ yields the same result as the convolution with a zero-padded $h$ (and $g$)

$$h' = [\ldots,0,0,h_0, h_1, h_2,0,0,\ldots]$$ the difference filter $d$ will have (symbolically $h'-g'$):

$$d = [\ldots,0,-g_{-1},h_0-g_{0}, h_1-g_{1}, h_2-g_{2},-g_{3},0,\ldots]$$

For FIR filters (or truncated IIR), you can limit to a finite sequence bounded by the smallest and the biggest index of both filters.

• Does this work only for FIR or for IIR as well? – Ben Aug 25 '17 at 13:22
• Indeed, hence the "as infinite series", if your IIR is written as an infinite sequence – Laurent Duval Aug 25 '17 at 13:39