Tchebyshev Analysis and Synthesis.

Tchebyshev Synthesis

This states that we can create a function between two limits by adding terms called Tchebyshev functions (of the first order), each of different amplitude. These are different shapes to the sin/cos of Fourier, but actually give better approximations across the range when you limit the number of terms. Fourier gives significantly bigger errors near these extremes. The Tchebyshev functions can be expressed in many ways, including as polynomials, and so a (truncated) series of Tchebyshev components can be quickly evaluated from some constants and polynomials, giving a significant speed advantage. The first component is again DC, ie zero frequency, and the following terms oscillate increasingly rapidly

Wikipedia is helpful as-ever, with the following definitions.

Since one of the definitions of the Tchebyshev functions is as a polynomial, once you know the amplitude of each Tchebyshev term you can add the various powers of x to give a simple polynomial which will be fast to evaluate.. The first image shows in turn the Tchebyshev components. A DC term and oscillatory terms a BIT like sin/cos.

The next image shows the arbitrary target waveform, and the improving accuracy as each further term is added.

Tchebyshev Analysis

Of course, to synthesize a wave of shape that we want, we need the reverse process, ie given our chosen waveform- say a triangle wave- what components are needed to make it?

Demonstration program

This program has functions to generate the Tchebyshev functions of the first order. It calculates amplitude of the first 8 terms and draws the successively improving approximation. Several possible functions are included- try your own odd, even o asymmetric functions.

    nomainwin

    '   use only up to first 8 Tchebyshev terms ( 0 to 7)
    '   synthesises a cos curve between limits

    n       =200

    global pi: pi =4 *atn( 1)

    for c =0 to 7
        c( c) =0
        for k =0 to n
            xk      =cos( ( ( 2 *k +1) /(2 *( n +1))) *pi)

            if c =0 then
                c( c)   =c( c) +( 1 /( n +1)) *funcn( xk)
            else
                c( c)   =c( c) +( 2 /( n +1)) *funcn( xk) *Tchebyshev( c, xk)
            end if

        next k
        'print using( "##.####", c( c))
    next c

    print

    WindowWidth  =840
    WindowHeight =460

    open "Tchebyshev" for graphics_nsb as #wg

    #wg "trapclose quit"

    #wg "down ; fill darkblue"
    #wg "color white"
    for h =0 to 9
        if h =4 then #wg "size 2" else #wg "size 1"
        #wg "up ; goto  0 "; 10 +50 *h; " ; down ; goto 420 "; 10 +50 *h
    next h

    for v =0 to 2
        if v =1 then #wg "size 2" else #wg "size 1"
        #wg "up ; goto "; 10 +200 *v; " 0 ; down ; goto "; 10 +200 *v; " 420"
    next v

    for x =-1 to 1 step 0.005
        print using( "##.##", x), using( "##.####",funcn( x)),
        #wg "color 255 255 0 ; set "; int( ( x +1) *200 +10); " "; int( 210 -funcn( x) *50)
        t =0
        for c =0 to 7
            t =t +c( c) *Tchebyshev( c, x)
        next c
        print using( "##.####", t)
        #wg "color 255 0 255 ; set "; int( ( x +1) *200 +10); " "; int( 210 -t *50)
    next x

    #wg "color white ; backcolor darkblue"

    for i =0 to 7
        #wg "up ; goto 450 "; 50 +i *20
        #wg "down"
        #wg "\"; i; "  "; using( "##.######", c( i))
    next i

    wait'_____________________________________________________________________

    function Tchebyshev( n, x)
        select case
            case x >1
                Tchebyshev =cosh( n *arcCosh( x))
            case x <-1
                Tchebyshev =cos(  n *arcCosh( x))
            case ( ( x >=-1) and ( x <=1))
                Tchebyshev =cos(  n *acs(     x))
        end select
    end function

    function cosh( x)
        cosh    =0.5 *( exp( x) +exp( 0 -x))
    end function

    function arcCosh( x)
        if x >1 then arcCosh =log( x +( x^2 -1)^0.5)
    end function

    sub quit h$
        close #wg
        end
    end sub

    sub delay t
        timer t *1000, [o]
        wait
        [o]
        timer 0
    end sub

    function funcn( x)
        funcn =cos( x)
        'funcn4 *sin( x)^2
        'funcn =exp( x)  '   1.2661  1.1302  0.2715  0.0443 is expected
        'funcn =4 *x^2
        'funcn =4 *sin( pi *x)
    end function