filter2

filter2 — Performs filtering using a transposed form-II digital filter lattice with no time-varying control.

Description

General purpose custom filter with no 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
      

Syntax

ares filter2 asig, iM, iN, ib0, ib1, ..., ibM, ia1, ia2, ..., iaN
kres filter2 ksig, iM, iN, ib0, ib1, ..., ibM, ia1, ia2, ..., iaN

Initialization

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 and specified directly or loaded into a table via GEN01.

Performance

The filter2 opcodes perform filtering using a transposed form-II digital filter lattice with no time-varying control.

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.

Examples

A first-order linear-phase lowpass FIR filter operating on a k-rate signal:

k1 filter2 ksig, 2, 0, 0.5, 0.5   ;; k-rate FIR filter

Here is another example of the filter2 opcode. It uses the file filter2.csd.

Example 257. Example of the filter2 opcode.

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

<CsoundSynthesizer>
<CsOptions>
; 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 filter2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr 1	 ; 2 saw waves of which one is slightly detuned
 
ib1   = p5  
ivol  = p6				;volume to compensate                                               
kcps  init cpspch(p4)
asig1 vco2 .05, kcps			;saw 1
asaw1 filter2 asig1, 1, 1, 1, ib1	;filter 1 
asig2 vco2 .05, kcps+1			;saw 2                      
asaw2 filter2 asig2, 1, 1, 1, ib1	;filter 2
aout  = (asaw1+asaw2)*ivol		;mix
      outs aout, aout

endin
</CsInstruments>
<CsScore>

i 1 0 4 6.00 -.001 5	;different filter values
i 1 + 4 6.00 -.6   2	;and different volumes
i 1 + 4 6.00 -.95 .3	;to compensate
e
</CsScore>
</CsoundSynthesizer>


See Also

zfilter2

Credits

Author: Michael A. Casey
M.I.T.
Cambridge, Mass.
1997

New in version 3.47