chebyshevpoly — Efficiently evaluates the sum of Chebyshev polynomials of arbitrary order.


The chebyshevpoly opcode calculates the value of a polynomial expression with a single a-rate input variable that is made up of a linear combination of the first N Chebyshev polynomials of the first kind. Each Chebyshev polynomial, Tn(x), is weighted by a k-rate coefficient, kn, so that the opcode is calculating a sum of any number of terms in the form kn*Tn(x). Thus, the chebyshevpoly opcode allows for the waveshaping of an audio signal with a dynamic transfer function that gives precise control over the harmonic content of the output.


aout chebyshevpoly ain, k0 [, k1 [, k2 [...]]]


ain -- the input signal used as the independent variable of the Chebyshev polynomials ("x").

aout -- the output signal ("y").

k0, k1, k2, ... -- k-rate multipliers for each Chebyshev polynomial.

This opcode is very useful for dynamic waveshaping of an audio signal. Traditional waveshaping techniques utilize a lookup table for the transfer function -- usually a sum of Chebyshev polynomials. When a sine wave at full-scale amplitude is used as an index to read the table, the precise harmonic spectrum as defined by the weights of the Chebyshev polynomials is produced. A dynamic spectrum is acheived by varying the amplitude of the input sine wave, but this produces a non-linear change in the spectrum.

By directly calculating the Chebyshev polynomials, the chebyshevpoly opcode allows more control over the spectrum and the number of harmonic partials added to the input can be varied with time. The value of each kn coefficient directly controls the amplitude of the nth harmonic partial if the input ain is a sine wave with amplitude = 1.0. This makes chebyshevpoly an efficient additive synthesis engine for N partials that requires only one oscillator instead of N oscillators. The amplitude or waveform of the input signal can also be changed for different waveshaping effects.

If we consider the input parameter ain to be "x" and the output aout to be "y", then the chebyshevpoly opcode calculates the following equation:

        y = k0*T0(x) + k1*T1(x) + k2*T2(x) + k3*T3(x) + ...

where the Tn(x) are defined by the recurrence relation

        T0(x) = 1,
        T1(x) = x, 
        Tn(x) = 2x*T[n-1](x) - T[n-2](x)

More information about Chebyshev polynomials can be found on Wikipedia at


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

Example 135. Example of the chebyshevpoly 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     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o chebyshevpoly.wav -W ;;; for file output any platform

sr = 44100
ksmps = 32
nchnls = 2

; time-varying mixture of first six harmonics
instr 1
	; According to the GEN13 manual entry,
	; the pattern + - - + + - - for the signs of 
	; the chebyshev coefficients has nice properties.
	; these six lines control the relative powers of the harmonics
	k1         line           1.0, p3, 0.0
	k2         line           -0.5, p3, 0.0
	k3         line           -0.333, p3, -1.0
	k4         line           0.0, p3, 0.5
	k5         line           0.0, p3, 0.7
	k6         line           0.0, p3, -1.0
	; play the sine wave at a frequency of 256 Hz with amplitude = 1.0
	ax         oscili         1, 256, 1
	; waveshape it
	ay         chebyshevpoly  ax, 0, k1, k2, k3, k4, k5, k6
	; avoid clicks, scale final amplitude, and output
	adeclick   linseg         0.0, 0.05, 1.0, p3 - 0.1, 1.0, 0.05, 0.0
	           outs           ay * adeclick * 10000, ay * adeclick * 10000

f1 0 32768 10 1	; a sine wave

i1 0 5


See also


Opcode Equivalents of Functions


Author: Anthony Kozar
January 2008

New in Csound version 5.08