Skip to content

Biquadratic (2nd Order IIR) Filter

Description

Filters its inputs by a second order IIR (Infinite Impulse Response) filter controlled by a set of 5 coefficients

Syntax and Default Values

The biquadratic-filter controller can be created using the following Mlys (Max), mlys.lua, or Lisp syntax:

In Modalys for Max, this object is named mlys.biquadratic-filter:

An input controller must be connected to the first inlet.
The dimension is automatically the same as the input controller.
💡If a second inlet is given, you can connect a 5-dimensional controller encapsulating the 5 coefficients of the filter. Otherwise a dynamic controller will be created automatically.

modalys.create_controller{kind="biquadratic-filter",
                          coefficients={1,,4.2,2.3,0.,1.5},
                          input=<controller of any dimension>,
                          name="MyBiquadraticFilter"}

The dimension is automatically the same as the input controller.
The coefficients parameter can be a 5-dimensional controller, but if passed as a table of 5 values, it can be changed dynamically via Max messages with MyBiquadraticFilter@coefficients

(make-controller 'biquadratic-filter
                  dimension
                  coefficients
                  input)
This controller takes 3 parameters.

The dimension parameter must be the same as the input controller's dimension.

Parameters

  • dimension: number of dimensions of the input and output controllers (automatic for mlys.lua and Modalys for Max).
  • coefficients: a 5-dimensional controller specifying the 5 bilinear filter coefficients.
  • input: filter input (a controller, possibly multi-dimensional). The coefficients controller should have 5 dimensions which represent the a0, a1, a2, b1 and b2 coefficients.
    This controller is updated at every sample (period = 0).

Discussion

This filter implements a general second-order (two-pole two-zero) filter which can be used for a variety of purposes, including smoothing out envelopes, and filtering sound-file, signal or other controllers. The following example is shown in one of the graphs (with a 1 Hz cutoff) in the above image:

(setq sp (get-info 'sample-period))
(setq my-env (make-controller 'envelope 1 
         (list '(0 0.0) '(0.1 0) (list (+ 0.1 sp) 1) '(1.5 1) (list (+ 1.5 sp) 0)) ))
(setq cutoff 1)
(setq Q 0.707)
(setq w0 (* cutoff 2 pi sp))
(setq alpha (/ (sin w0) (* 2 Q)))
(setq cw (cos w0))
(setq b0 (/ 1 (+ 1 alpha)))
(setq a0 (* b0 (- 1 cw) 0.5))
(setq a1 (* b0 (- 1 cw)))
(setq a2 a0)
(setq b1 (* b0 (* -2 cw)))
(setq b2 (* b0 (- 1 alpha)))
(setq my-filtered-env (make-controller 'biquadratic-filter 1 (const a0 a1 a2 b1 b2) my-env))
You should probably consider using it or the bilinear-filter, instead of the older filtering functions (because you can design any type of filter you want). However, you will first need to generate your own sets of coefficients from higher level parameters such as center/cutoff frequency, etc....


★     ★
★