[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in IDL's hanning() window-generating function

In article <3B6B1D98.1665BFFE@rsinc.com>,
Harold Cline  <harold@rsinc.com> wrote:
>Just an FYI for everyone on this topic. ;-)
>Harold Cline
>IDL Product Manager
>The formula to compute the Hanning window has been changed
>from 0.5 * (1-Cos(2*!Pi*k/(N-1))) to 0.5 * (1-Cos(2*!Pi*k/N)).
>Because of the change from 1/(N-1) to 1/N, the Hanning window
>will no longer
>appear symmetric in the time domain, but will give improved results for
>spectral estimation.

     That's very good to know.
>Additional notes:
>When filters such as the Hanning are to be used as
>finite-impulse response
>(FIR) filtering in the time domain, it is useful to have the filter be
>symmetric, and go to zero at both ends. However, if you are

     First off, data filtering and data windowing (a.k.a. data
tapering) are two different things.  One can design an FIR data
filter by modifying a spectral window to pass or stop certain
frequency/wavenumber ranges as desired.  So a Hann spectral
window (i.e. FFT(HANNING(length_of_desired_filter))) could be
modified and then used as a time-domain filter.

>filtering your
>time series in preparation for doing spectral analysis, the
>filter should
>not be symmetric, and should not go to zero at one of the
>endpoints. Thus,

     That is correct.  Note, however, that one often wishes to
calculate a spectrum without filtering.  In my work, for example,
I have not filtered the data before applying the window and
taking the transform because I want to see all of the resolvable
spectrum.  A data window is still necessary to prevent generation
of spurious spectral power that would result from the break in
"continuity" at the data segment boundaries.
     IMHO, IDL's DIGITAL_FILTER() provides a much better filter
than it is possible to contrive from a Hann spectral window,
though it can take a bit of experimentation to find good values
to specify for "A" (maximum level Gibbs ringing.)  With the
right value for "A", DIGITAL_FILTER() can even outperform a
filter based upon the sinc function (FT of a boxcar window) at
the same filter order.  For those who want to try this, code a
fairly wide filter size and code 43.93125 for the A argument to
DIGITAL_FILTER().  Then generate a sinc-based filter with the
same number of coefficients and compare the frequency responses
of the two filters.  IIRC, the sinc-based filter has a maximum
Gibbs ringing amplitude in the range of only 2%-3% and the
maximum ringing amplitude from the filter you get from
DIGITAL_FILTER() is about half that, while the transition ramps
of the two filters are practically indistinguishable.  (A look
at the code for DIGITAL_FILTER() looks like it might be a sinc
filter that's been tightened up a bit further by multiplying it
by a Kaiser-Bessel data window.  Pretty neat.)
     A caveat here:  certain configurations of arguments to
DIGITAL_FILTER() yield filters that should preserve the mean of
the data, but don't.  This can easily be fixed by normalizing
all the coefficients before convolving them with the data.  For

	filter = digital_filter(0., .00777778, 43.93125, 1125)
	filter = filter / total(filter)

>the new behavior of the HANNING function assumes it will be used for
>spectral analysis.
>Reference: Oppenheim & Schafer (Discrete-Time Signal Processing,
>1999), p.
     Thanks for fixing it.

                                  Scott Bennett, Comm. ASMELG, CFIAG
                                  College of Oceanic and Atmospheric
                                  Oregon State University
                                  Corvallis, Oregon 97331
* Internet:       sbennett at oce.orst.edu                           *
* "Lay then the axe to the root, and teach governments humanity.     *
* It is their sanguinary punishments which corrupt mankind."         *
*    -- _The_Rights_of_Man_ by Tom Paine (1791.)                     *