FilterCoef calculates time-domain filter coefficients


Inherits from: Object


FilterCoef generates the a and b coefficients for the general linear difference equation for a filter in response to the location of n poles and/or zeros on the Z-plane graph. These coefficients can be used by SOS, FOS or LTI.


Important notes

Unlike ZPlane, FilterCoef does no automatic checking for identical pole/zero pairs. Neither does it check if the number of poles and zeros are equal or does it add a conjugate pole/zero automatically. Please also note that if you normalize the frequency response with ZPlane, this does not mean that the time-domain coefficients are normalized too. If you want the time-domain coefficients to be normalized, you have to state this explicitly when you call .calc for FilterCoef (the default behaviour is to normalize the frequency response as well as the time-domain coefficients). See the examples for a further explanation.



Creation / Class Methods


*new(poles, zeros, real, norm)

Creates a new instance of FilterCoef. 

poles - An Array containing a number of poles of type Polar.

zeros - An Array containing a number of zeros of type Polar.

real - A Boolean indicating whether the filter coefficients returned are real or complex. See also instance method 'checkIfReal'.

norm - A Boolean indicating whether the time-domain coefficients should be normalized. 


*calc(poles, zeros, norm)

Calculates the time-domain coefficients for the general linear difference equation for a filter. If norm is set to true (by default), the a coefficients are scaled by the reciprocal of the maximum value of the frequency response. Returns an Array of arrays holding the a coefficients: (a0, a1, a2... an) and the b coefficients: (b1, b2, b3... bn).

poles - An Array containing a number of poles of type Polar.

zeros - An Array containing a number of zeros of type Polar.

norm - A Boolean indicating whether the time-domain coefficients should be normalized.

Instance Methods


checkIfReal

Checks if the specified poles and zeros result in a real or complex valued function. Modifies the 'real' variable in response.


calc(norm)

Calculates the time-domain coefficients for the general linear difference equation for a filter. If norm is set to true (by default), the a coefficients are scaled by the reciprocal of the maximum value of the frequency response. Returns an Array of arrays holding the a coefficients: (a0, a1, a2... an) and the b coefficients: (b1, b2, b3... bn).

norm - A Boolean indicating whether the time-domain coefficients should be normalized.

calcImpResp

Calculates the impulse response of the filter. Returns an Array with the result.

Examples: also see ZPlane




// An allpass filter example.

(

a = FilterCoef.new([Polar.new(0.8, 0.25pi), Polar.new(0.8, -0.25pi)], [Polar.new(0.8.reciprocal, 0.25pi), Polar.new(0.8.reciprocal, -0.25pi)]).postln;


a.calc.postln;

a.calcImpResp.real.plot("Impulse Response", discrete: true)

)



// Use of FilterCoef together with SOS.


// Bandpass filter at 0.03 pi (corresponds roughly to 211 Hz at a sampling rate of 44.1 kHz).

(

c = FilterCoef.calc([Polar.new(0.9997, 0.03pi), Polar.new(0.9997, -0.03pi)], [Polar.new(0.0, 0.0pi), Polar.new(0.0, 0.0pi)])

);


Server.default = Server.internal;

s = Server.default;

s.boot;

SCFreqScopeWindow.new(400, 200, 0);

s.scope;


// IMPORTANT: The b (feedback) coefficients need to be negated.

{ SOS.ar(WhiteNoise.ar(0.9).dup(2), c[0][0].real, 0, 0, c[1][1].real.neg, c[1][2].real.neg) }.play