Skip to content

Variable 2nd Order (Bandpass) Filter

Description

Given a 1-dimension input, provides a Second Order IIR filter output with a variable center frequency and bandwidth.

Syntax and Default Values

The variable-second-order-filter controller (1-dimensional) can be created using the following Lisp, mlys.lua or mlys (Max) syntax:

(make-controller 'variable-second-order-filter
                  dimension
                  period
                  input
                  frequency
                  bandwidth)
create_controller{kind="variable-second-order-filter",
                  period=-1,  -- optional
                  input=<input controller>, -- dim = 1!
                  frequency=700,  -- value or a 1-dimensional controller
                  bandwidth=20,   -- value or a 1-dimensional controller
                  name="Variable2ndOrderFilter"}

In Modalys for Max, this object is named mlys.variable-second-order-filter:

An 1-dimensional input controller must be connected to the first inlet.
The dimension is set to 1 under the hood.
💡If a second inlet is given, you can connect a controller representing the frequency; if there is a 3rd one, then it will be for the bandwidth.

Parameters

The 'variable-second-order-filter controller takes five arguments:

  • dimension: dimension of the input and output controllers (must be 1, automatic for mlys.lua or Modalys for Max)
  • period: the time between the updates of the controller. Should be -1 (automatic). If zero, then it updates every sample.
  • input: filter input (a 1-dimensional controller).
  • frequency: controller specifying the center frequency in Hz (dim=1).
  • bandwidth: controller specifying the bandwidth in Hz (dim=1).

The dimension must be 1 for all controllers.

The center frequency and bandwidth parameters should be both be controllers of dimension 1. Note that there is no amplitude controller for this filter. Amplitude gain is internally set to 1, but resonances caused by very narrow bandwidths could result in very high amplitude values.

Discussion

The variable second order (bandpass) filter can be used for a variety of purposes, but generally is used either to smooth out envelopes or create resonances from impulses. Using a low frequency and fairly wide bandwidth, it can smooth out envelopes (a graph of this example is shown in the image, above):

(setq my-env (make-controller 'envelope 1 '((0 0.0) (0.1 1.0) (1.4 1) (1.5 0)) ))
(setq my-filtered-env (make-controller 'variable-second-order-filter 1 0 my-env (const 1) (const 5)))
Or it can be used to add a resonance to an impulse or other noisy sound, by using a specific frequency and a very narrow bandwidth:

(setq my-noise (make-controller 'noise 1 0 (list (const 44100) (const 0.25) (const 0.25) (const 1) (const 1)) 10))
(setq my-filtered-noise (make-controller 'variable-second-order-filter 1 0 my-noise (const 440) (const 1)))
You may use the more general-purpose 'biquadratic-filter controller instead of this filter. However, to do so you will need to generate your own filter coefficients (whereas this filter lets you use higher-level parameters like frequency and bandwidth).


★     ★
★