View Raw SPL
/*****************************************************************************
*                                                                            *
*   GCHEBWIN.SPL  Copyright (C) 2012 DSP Development Corporation             *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Generates a Dolph-Chebyshev window                          *
*                                                                            *
*   Revisions:    6 Jan 2012  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_GCHEBWIN

    GCHEBWIN

    Purpose: Generates a Dolph-Chebyshev window.

    Syntax:  GCHEBWIN(N, spacing, attn)

                    N  - An integer, the number of points to generate.

               spacing - A real, the spacing between points.

                  attn - Optional. A real, the sidelobe attenuation
                         in dB from the mainlobe. Defaults to -100.

    Returns: A series.

    Example:
             gchebwin(100, .01)

             Creates a 100-point Dolph-Chebyshev window with points
             spaced at an interval of 0.01.  The sidelobe attenuation
             is -100 dB.

    Example:
             gchebwin(100, .01, -65)

             Creates a 100-point Dolph-Chebyshev window with points
             spaced at an interval of 0.01.  The sidelobe attenuation
             is -65 dB.

    Example:
             W1: gchebwin(100, 1, -60)
             W2: magspec(w1, 8192);20*log10(curr/max(curr));

             W1 Creates a 100 point Dolph-Chebyshev window where the
             sidelobe attenuation is -60 dB. W2 displays the normalized
             frequency response.

    Remarks:
             The frequency response of an Nth order Dolph-Chebyshev
             window with an attenuation of attn decibels is given by:

             W(k) = Cheb(N-1, beta * cos(pi * k / (N-1))) / Cheb(N-1, beta)

             where:

             Cheb(m, x) is the mth order Chebyshev polynomial and

             beta = cosh(acosh(10 ^ (attn / 20)) / (N-1))

             The time domain response is determined by computing the 
             inverse Fourier transform and scaling the result to a
             unitary maximum.

             The Dolph-Chebyshev windows minimizes the Chebyshev norm of
             the sidelobes for a given mainlobe width.

             The Dolph-Chebyshev window can be regarded as the impulse
             response of an optimal Chebyshev lowpass filter having a
             zero-width passband.

             Because the Dolph-Chebyshev window yields equiripple constant
             magnitude sidelobes, impulses may result at the end points of
             the time domain response.

             Use CHEBWIN to automatically create and multiply
             a Dolph-Chebyshev window with a series. For example:

               chebwin(w2, -60)

             multiplies Window 2 with a Dolph-Chebyshev window with an
             attenuation of -60 dB.

    See Also:
             CHEBWIN
             FFT
             GHAMMIMG
             GHANNING
             GKAISER
             GTAYLORWIN
             PSD
             SPECTRUM
#endif


/* multiply a series with a Dolph-Chebyshev window */
gchebwin(N, dx, attn)
{
        local alpha, beta, L, g, k, W;

        if (argc < 3)
        {
                if (argc < 2)
                {
                        if (argc < 1) N = 100;

                        dx = 1.0;
                }

                attn = 100;
        }

        if ((L = int(N - 1)) > 0)
        {
                /* sidelobe parameter */
                alpha = abs(attn) / 20;

                /* sequence values */
                k = 0..(L - 1);

                /* beta */
                beta = cosh(acosh(10.0 ^ alpha) / L);

                /* Dolph-Chebyshev frequency response */
                W = (-1)^k * cos(L * acos(beta * cos(pi * k / L)));
        
                /* convert to time domain */
                W = real((ifft(w)));

                /* normalize */
                W[1] = W[1] / 2;
                W[N] = W[1];
 
                W /= max(W);
        }
        else 
        {
                /* single point or empty */
                W = (N > 0) ? {1} : {};
        }

        setxoffset(W, 0.0);
        setdeltax(W, dx);

        return(W);
}