View Raw SPL
/*****************************************************************************
*                                                                            *
*   HANNING.SPL   Copyright (C) 2000, 2010 DSP Development Corporation       *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:       Randy Race                                                 *
*                                                                            *
*   Synopsis:     Multiplies a series with a Hamming Window                  *
*                                                                            *
*   Revisions:    17 Feb 2000  RRR  Creation                                 *
*                 21 Jul 2010  RRR  symmetry flag                            *
*                                                                            *
*****************************************************************************/


#if @HELP_HANNING

    HANNING

    Purpose: Multiplies a series with a Hamming window

    Syntax:  HANNING(s, ampflag, "sym")

                    s - A series or array

              ampflag - Optional, an integer, the correction factor.

                        0: do not correct amplitude (default)
                        1: correct amplitude
                        2: correct RMS 
                        3: correct mean squared amplitude

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

                        "symmetric" : Starting and ending points are equal,
                                      but the leading zero and trailing zero 
                                      are removed (default).

                        "periodic"  : Periodic window where the leading zero
                                      is preserved but the trailing zero is
                                      removed. Conforms to ISO standard.

                        "direct"    : Starting and ending points are equal,
                                      leading and trailing zeros are preserved.

   Alternate Syntax:  
             
             HANNING(N, ampflag, "sym")

                    N - An integer, the length of the window.

              ampflag - Optional, an integer, the correction factor.

                        0: do not correct amplitude (default)
                        1: correct amplitude
                        2: correct RMS 
                        3: correct mean squared amplitude

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

                        "symmetric" : Starting and ending points are equal,
                                      but leading and trailing zeros are 
                                      removed (default).

                        "direct"    : Starting and ending points are equal,
                                      leading and trailing zeros are preserved.

                        "periodic"  : Periodic window where the leading zero
                                      is preserved but the trailing zero is
                                      removed. Conforms to ISO standard.

    Returns: A series or array

    Example:
             W1: gsin(1000, .001, 45)
             W2: spectrum(hanning(W1))
             W3: spectrum(hanning(W1, 1))

             The MAX of W2 == 0.539 and the MAX of W3 == 1.0. The amplitude
             of the spectrum in W3 has been corrected to take into account
             amplitude effects of the Hamming window.

   Example:
             hanning(1000, "periodic")

             returns a 1000 point periodic hanning window.

    Remarks:

             If the input is an integer rather than a series, the N
             point hanning window is returned.

             If ampflag == 1, the correction factor is the mean of
             the spectral window. This assures that the spectrum of a
             sinusoid of amplitude 1.0 has a peak of 1.0.

             If ampflag == 2, the correction is applied as follows:

             w = hanning(s) * rms(s) / rms(hanning(s))

             sqrt(area(psd(w))) == rms(s)    approximately

             If ampflag == 3, the correction is applied as follows:

             w = hanning(s) / sqrt(win * win / length(win))

             where win is the windowing function.

             The "sym" flag controls the window symmetry as follows: 

             "Symmetric" (the default) removes the leading and trailing
             zeros.

             "Periodic" or "iso" creates a periodic window function
             useful in spectrum analysis applications where the
             starting zero is preserved and the trailing zero is
             removed.  "Periodic" or "iso" conforms to the ISO 18431-1
             standard for windowing functions.

             "Direct" implements the core window function where any
             leading and trailing zeros are preserved.

    See Also
             Hanning
             Kaiser
             winfunc
#endif

/* undefine macro definition */
#undef HANNING


/* multiply series with a hanning window */
SERIES hanning(s, ampflag, sym)
{
        return(winfunc(1, s, ampflag, sym));
}