View Raw SPL
/*****************************************************************************
*                                                                            *
*   GFLATTOPWIN.SPL Copyright (C) 2010 DSP Development Corporation           *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Generates a MATLAB compatible Flattop window                *
*                                                                            *
*   Revisions:   13 Jul 2010  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_GFLATTOPWIN

    GFLATTOPWIN

    Purpose: Generates an alternate 4 point Flattop Window.

    Syntax:  GFLATTOPWIN(N, spacing, "sym")
 
                     N - Number of points to generate.

               spacing - Spacing between points.

                 "sym" - Optional. A string, the symmetry mode.

                          "symmetric" : Starting and ending points are equal
                                        (default).

                          "periodic"  : Periodically extended window.

                          "iso"       : Same as "periodic".
 
    Returns: A series.

    Example:
             gflattopwin(100, .01)

             Creates a 100-point symmetric Flattop window with points
             spaced with an interval of 0.01 using the following 4
             point formula:

             w[k]  = 0.21557895 - 0.416631580 * cos(2*pi*(k-1)/(N-1))
                                + 0.277263158 * cos(4*pi*(k-1)/(N-1))
                                - 0.083578947 * cos(6*pi*(k-1)/(N-1))
                                + 0.006947368 * cos(8*pi*(k-1)/(N-1))

             where k is the kth point (1 <= k <= N) and N is 100, the number
             of points to generate. The spacing between points is set to 0.01.

    Example:
             gflattopwin(100, .01, "periodic")

             Creates a 100-point periodic Flattop window with points
             spaced with an interval of 0.01 using the following 4
             point formula:

             w[k]  = 0.21557895 - 0.416631580 * cos(2*pi*(k-1)/N)
                                + 0.277263158 * cos(4*pi*(k-1)/N)
                                - 0.083578947 * cos(6*pi*(k-1)/N)
                                + 0.006947368 * cos(8*pi*(k-1)/N)

             where k is the kth point (1 <= k <= N) and N is 100, the number
             of points to generate. The spacing between points is set to 0.01.

    Remarks:
             The Flattop window preserves the amplitude of a series
             at the expense of frequency resolution. It will accurately
             measure the amplitude of a series at any frequency, even
             if the frequency lies between FFT bins.

             This form of the flattop window does not conform to the
             ISO 18431-1 standard.  See GFLATTOP to generate a four term
             Flattop window based on the ISO 18431-1 standard.

             Use the FLATTOPWIN function to automatically create and multiply
             a Flattop window with a series. For example:

               flattopwin(w2)

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

             Hamming, Hanning, Kaiser and Flattop windows are useful in
             creating FIR filters and in preprocessing series for FFT
             calculations.

    See Also:
             FFT
             GFLATTOP
             GHAMMING
             GHANNING
             GKAISER
             PSD
             SPECTRUM
#endif



/* generate an N point Flattop window based on alternate 4 point formula */
gflattopwin(n, dx, sym)
{
        local w;

        /* generate matlab compatible flattop window */
        w = gflattop(n, dx, 2, sym);
        
        return(w);
}