series_iir()

Applies an Infinite Impulse Response filter on a series.

The function takes an expression containing dynamic numerical array as input, and applies an Infinite Impulse Response filter. By specifying the filter coefficients, the function can be used:

  • to calculate the cumulative sum of the series
  • to apply smoothing operations
  • to apply various high-pass, band-pass, and low-pass filters

The function takes as input the column containing the dynamic array and two static dynamic arrays of the filter's a and b coefficients, and applies the filter on the column. It outputs a new dynamic array column, containing the filtered output.

Syntax

series_iir(x, b , a)

Arguments

  • x: Dynamic array of numeric values, typically the resulting output of make-series or make_list operators.
  • b: Dynamic array of numeric values, containing the numerator coefficients of the filter.
  • a: Dynamic array of numeric values, containing the denominator coefficients of the filter.

Important

The first element of a (that is, a[0]) mustn't be zero, to avoid division by 0. See the formula below.

The filter's recursive formula

  • Consider an input array X, and coefficients arrays a and b of lengths n_a and n_b respectively. The transfer function of the filter that will generate the output array Y, is defined by:
Yi = a0-1(b0Xi + b1Xi-1 + ... + bnb-1Xi-nb-1 - a1Yi-1-a2Yi-2 - ... - ana-1Yi-na-1)

Example

Calculate a cumulative sum. Use the iir filter with coefficients a=[1,-1] and b=[1]:

let x = range(1.0, 10, 1);
print x=x, y = series_iir(x, dynamic([1]), dynamic([1,-1]))
| mv-expand x, y
x y
1.0 1.0
2.0 3.0
3.0 6.0
4.0 10.0

Here's how to wrap it in a function:

let vector_sum=(x:dynamic)
{
  let y=array_length(x) - 1;
  toreal(series_iir(x, dynamic([1]), dynamic([1, -1]))[y])
};
print d=dynamic([0, 1, 2, 3, 4])
| extend dd=vector_sum(d)
d dd
[0,1,2,3,4] 10