zfilter2 — Performs filtering using a transposed form-II digital filter lattice with radial pole-shearing and angular pole-warping.


General purpose custom filter with time-varying pole control. The filter coefficients implement the following difference equation:

(1)*y(n) = b0*x[n] + b1*x[n-1] +...+ bM*x[n-M] - a1*y[n-1] -...- aN*y[n-N]

the system function for which is represented by:

           B(Z)      b0 + b1*Z-1  + ... + bM*Z-M
  H(Z)  =  ----  =  --------------------------
           A(Z)       1 + a1*Z-1  + ... + aN*Z-N


ares zfilter2 asig, kdamp, kfreq, iM, iN, ib0, ib1, ..., ibM, \
      ia1,ia2, ..., iaN


At initialization the number of zeros and poles of the filter are specified along with the corresponding zero and pole coefficients. The coefficients must be obtained by an external filter-design application such as Matlab or Octave (GPL) and specified directly or loaded into a table via GEN01. With zfilter2, the roots of the characteristic polynomials are solved at initialization so that the pole-control operations can be implemented efficiently.


The filter2 opcodes perform filtering using a transposed form-II digital filter lattice with no time-varying control. zfilter2 uses the additional operations of radial pole-shearing and angular pole-warping in the Z plane.

Pole shearing increases the magnitude of poles along radial lines in the Z-plane. This has the affect of altering filter ring times. The k-rate variable kdamp is the damping parameter. Positive values (0.01 to 0.99) increase the ring-time of the filter (hi-Q), negative values (-0.01 to -0.99) decrease the ring-time of the filter, (lo-Q).

Pole warping changes the frequency of poles by moving them along angular paths in the Z plane. This operation leaves the shape of the magnitude response unchanged but alters the frequencies by a constant factor (preserving 0 and p). The k-rate variable kfreq determines the frequency warp factor. Positive values (0.01 to 0.99) increase frequencies toward p and negative values (-0.01 to -0.99) decrease frequencies toward 0.

Since filter2 implements generalized recursive filters, it can be used to specify a large range of general DSP algorithms. For example, a digital waveguide can be implemented for musical instrument modeling using a pair of delayr and delayw opcodes in conjunction with the filter2 opcode.


A controllable second-order IIR filter operating on an a-rate signal:

a1 zfilter2 asig, kdamp, kfreq, 1, 2, 1, ia1, ia2 ;; controllable a-rate IIR filter

Here is an example of the zfilter2 opcode. It uses the files zfilter2.csd.

Example 1241. Example of the zfilter2 opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

; Select audio/midi flags here according to platform
-odac   ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o zfilter2.wav -W ;;; for file output any platform

; By Stefano Cucchi 2020

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1	
kdamp linseg p5, p3, p6 
kfreq linseg p7, p3, p8				                                            
kcps  init cpspch(p4)
asig1 vco2 .2, kcps			
asaw zfilter2 asig1, kdamp, kfreq, 2, 2, 0.81, 0.713, 0.0001, 0.99	

acompare oscil 0.2, 440 ; signal comparator for volume 
asaw balance asaw, acompare ; adjust the volume. Volume can have big variation due to filter.
      outs asaw, asaw


i 1 0 5 6.00 0.6 0.99 0.006 0.006 ; varying ringing time (from 0.6 to 0.99)
i 1 6 5 6.00 0.3 0.3 0.01 -0.8    ; varying frequency warp factor (from 0.01 to -0.8)

See Also



Author: Michael A. Casey
Cambridge, Mass.

New in Version 3.47