View Raw SPL
/*****************************************************************************
*                                                                            *
*   GTAYLORWIN.SPL  Copyright (C) 2011 DSP Development Corporation           *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Generates a Taylor window                                   *
*                                                                            *
*   Revisions:   20 Dec 2011  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_GTAYLORWIN

    GTAYLORWIN

    Purpose: Generates a Taylor window.

    Syntax:  GTAYLORWIN(N, spacing, nbar, attn)

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

               spacing - A real, the spacing between points.

                  nbar - Optional. An integer, the number of approximate
                         constant level sidelobes adjacent to the mainlobe.
                         Defaults to 4.

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

    Returns: A series.

    Example:
             gtaylorwin(100, .01)

             Creates a 100-point Taylor window with points spaced at an
             interval of 0.01. The number of approximately constant
             level sidelobes is 4 and the sidelobe attenuation is -30 dB.

    Example:
             W1: gtaylorwin(100, .01, 5, -35)
             W2: magspec(w1, 8192);20*log10(curr/max(curr))

             W1 creates a 100 point Taylor window with points spaced at
             an interval of 0.01. The number of approximately constant
             level sidelobes is 5 and the sidelobe attenuation is -35
             dB. W2 displays the frequnecy response.

    Remarks:
             Taylor windows are similar to Dolph-Chebyshev windows. 
             The Taylor window approximates the minimization of the
             main lobe width in the Dolph-Chebyshev window, but allows
             the sidelobe levels to decrease beyond a certain
             frequency.

             Because the Taylor distribution avoids edge
             discontinuities, the window sidelobes decrease
             monotonically.

             The Taylor window coefficients are not normalized.

             Taylor windows are typically used in radar applications,
             such as weighting synthetic aperature radar images,
             circular array antennas and antenna design.

             NBAR is the number of approximately equal sidelobes adjacent
             to the mainlobe and should satisfy:

               NBAR >= 2 * A^2 + 0.5 

             where
             
               A = acosh(10^(-attn / 20)) / pi

             otherwise the sidelobe level specified is not guaranteed.

             attn specifies the maximum sidelobe level in dB relative
             to the mainlobe level.

             Use TAYLORWIN to automatically create and multiply
             a Taylor window with a series. For example:

               taylorwin(w2)

             multiplies Window 2 with a Taylor window calculated to the same
             length and spacing as the series in W2.

             See GCHEBWIN to create a Dolph-Chebyshev window.

    See Also:
             FFT
             GCHEBWIN
             GHAMMIMG
             GHANNING
             GKAISER
             PSD
             SPECTRUM
             TAYLORWIN
#endif


/* generate an N point Taylor window */
gtaylorwin(N, dx, nbar, attn)
{
        local A, sp2, w, fm, summation, k, xi, m;

        if (argc < 4)
        {
                if (argc < 3)
                {
                        if (argc < 2)
                        {
                                if (argc < 1) error("gtaylorwin - input length required");

                                dx = 1.0;
                        }

                        nbar = 4;

                }

                attn = 30;

        }

        attn = abs(attn);

        /* make integer */
        N    = castint(n);
        nbar = castint(nbar);

        if (nbar <= 0)
        {
                error("gtaylorwin - number of nearly constant level sidelobes (nbar) must be positive");
        }

        A = acosh(10 ^ (attn / 20)) / pi;

        /* dilation factor */
        sp2 = nbar ^ 2 / (A ^ 2 + (nbar - 0.5) ^ 2);

        w         = ones(N, 1);
        fm        = zeros(nbar - 1, 1);
        summation = 0;
        k         = 0..(N - 1);
        xi        = (k - 0.5 * N + 0.5) / N;

        loop (m = 1..(nbar - 1))
        {
                fm[m]     = gtaylorwin_fm(m, sp2, A, nbar);
                summation = fm[m] * cos(2 * pi * m * xi) + summation;
        }

        w += 2 * summation;

        setdeltax(w, dx);

        return(w);
}


/* Calculate taylorwin cosine weights */
gtaylorwin_fm(m, sp2, A, nbar)
{
        local n, p, num, den, fm;

        n = 1..(nbar - 1);
        p = {1..(m - 1), m + 1..(nbar - 1)};

        num = prod((1 - (m ^ 2 / sp2) / (A ^ 2 + (n - 0.5) ^ 2)));
        den = prod((1 - m ^ 2 / p ^ 2));

        fm = ((-1) ^ (m + 1) * num) / (2 * den);

        return(fm);
}