# IIR / FIR filters analysis

This little script provides a function "`analyse_filtre(h)`", which takes as input a transfer function (polynomial function of z), and traces different graphs relating to this filter:

• Poles et zeros
• Frequential response (lineair and logarithmic scales)
• Step and impulse responses
• Group delay

### Example 1: analysis of an exponential filter (also called "numerical RC filter")

``````//     yn = (1-g)*y_n-1 + g*x_n
//     y * (1 - (1 - g) z^-1) = g x
// <=> y = g / (1 - (1 - g) z^-1))
g = 0.1;
h = g / (1 - (1-g)/%z);
analyse_filtre(h);
``````

### Example 2: analysis of a moving average filter

``````// h = 0.1 * (1 + z + z^2 + ... + z^9)
h = poly(ones(1,10),'z','c') / 10;
// Replace z by z^-1 so as to have a causal filter
h = horner(h,%z^-1);
analyse_filtre(h);
``````

Note: the group delay is of course constant for this filter (and equal to the mean delay of the filter, here, 4.5 samples), the fluctuations seen on the graph being only rounding errors of very small magnitude.