biquada
Prev | Orchestra Opcodes and Operators | Next

## biquada

biquada — A sweepable general purpose biquadratic digital filter with a-rate parameters.

## Description

A sweepable general purpose biquadratic digital filter.

## Syntax

    ares biquada asig, ab0, ab1, ab2, aa0, aa1, aa2 [, iskip]

## Initialization

iskip (optional, default=0) -- if non-zero, intialization will be skipped. Default value 0. (New in Csound version 3.50)

## Performance

asig -- input signal

biquada is a general purpose biquadratic digital filter of the form:

a0*y(n) + a1*y[n-1] + a2*y[n-2] = b0*x[n] + b1*x[n-1] + b2*x[n-2]

This filter has the following frequency response:

B(Z) b0 + b1*Z-1 + b2*Z-2
H(Z) = ---- = ------------------
A(Z) a0 + a1*Z-1 + a2*Z-2

This type of filter is often encountered in digital signal processing literature. It allows six user-defined a-rate coefficients.

## Examples

Here is an example of the biquada opcode. It uses the file biquad.csd.

Example 103. Example of the biquada 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
    ; Audio out   Audio in    No messages
    -odac           -iadc     -d     ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o biquad.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 2

    ; Instrument #1.
    instr 1
      ; Get the values from the score.
      idur = p3
      iamp = p4
      icps = cpspch(p5)
      afco   expon  100, p3, 2000
      arez   line  0.8, p3, 0.99

      ; Calculate the biquadratic filter's coefficients
      afcon = 2*3.14159265*afco/sr
      aalpha = 1-2*arez*cos(afcon)*cos(afcon)+arez*arez*cos(2*afcon)
      abeta = arez*arez*sin(2*afcon)-2*arez*cos(afcon)*sin(afcon)
      agama = 1+cos(afcon)
      am1 = aalpha*agama+abeta*sin(afcon)
      am2 = aalpha*agama-abeta*sin(afcon)
      aden = sqrt(am1*am1+am2*am2)
      ab0 = 1.5*(aalpha*aalpha+abeta*abeta)/aden
      ab1 = ab0
      ab2 = 0
      aa0 = 1
      aa1 = -2*arez*cos(afcon)
      aa2 = arez*arez

      ; Generate an input signal.
      axn vco 1, icps, 1

      ; Filter the input signal.
      ayn biquada axn, ab0, ab1, ab2, aa0, aa1, aa2
      outs ayn*iamp/2, ayn*iamp/2
    endin

    </CsInstruments>
    <CsScore>

    ; Table #1, a sine wave.
    f 1 0 16384 10 1

    ;    Sta  Dur  Amp    Pitch
    i 1  0.0  5.0  20000  6.00
    e

    </CsScore>
    </CsoundSynthesizer>

## See Also

biquad

## Credits

Author: John ffitch after Hans Mikelson
August 2001

New in Csound version 4.13

Prev | Up | Next
biquad | Home | birnd