See also: Fourier transform, IIR filter design

Containers for linear filters

This is a container library for linear filters. It consists of three different container structures:

TransferFunctionTransfer function polynomial.
ZeroPoleGainThe Zero-Pole-Gain representation of the system.
SignalChainAn arbitrary list of the former two.

They all have the same interface, but there are differences in the performance of certain methods.

Every data member of these structures is public.

import signals.containers-1;
Creating linear filter structures
import signals.containers-1;
my_tf = new ( [ new TransferFunction( [1,2,3,4,5,6], // numerator of the polynomial [7,8,9] // denominator of the polynomial ,150 Hz // sampling frequency, optional ), new ZeroPoleGain( [1,1,0.5,-0.3], // zeros [0,-0.5+0.3j,-0.5-0.3j, 0.95j, -0.95j], // poles 1 // gain ,150 Hz // sampling frequency, optional ) ]) Create Structure
Visualization
my_tf.plotAmplitude(20/* number of points */) // The Y axis is in logarithmic (dB) scale. Amplitude Plot my_tf.plotPhase(20/* number of points */) Phase Plot my_tf.plotZerosPoles() Pole-Zero Plot my_tf.plotImpulseResponse(20/* number of points */) Impulse Response my_tf.plot() // plot in the native form Plot

plot() has different behaviors in different representations. In the cases of TransferFunction or SignalChain, it plots the amplitude response. In the case of ZeroPoleGain, it plots the pole-zero diagram.

Using the structures

Filtering a test signal
input = [! zeros(100,1), ones(100,1), zeros(100,1), ones(100,1) !]; // test signal filtered = my_tf.filter(input); chart().curve(input).curve(filtered) Filter
Additional functions
// simplified implementation details of the system my_tf.getImplementationDetails() // amplitude response as an array my_tf.amplitude(10 /* number of points */ ) // phase response as an array my_tf.phase(10 /* number of points */ ) // complex gain as an array my_tf.complexGain(10 /* number of points */ ) // impulse response as an array my_tf.impulseResponse(10 /* number of samples */) // transfer polynomial evaluated at a given point my_tf.value(0.54)
Converting between representations
// convert any structure to zero-pole-gain my_tf.toZeroPoleGain() // convert any structure to transfer polynomial my_tf.toTransferFunction() // convert the system to an array of second order IIR filters my_tf.toSecondOrder()

toSecondOrder() returns a SignalChain structure. It is useful when trying to implement IIR filters and facing stability issues due to quantization.