WINDOW Instruction |
WINDOW( options ) cseries start end newcseries newstart
WINDOW smooths periodograms and cross-periodograms to compute spectral estimates. Smoothing is required because the periodogram itself is an inconsistent estimate of the spectrum: the variance does not go to zero as the number of data points increases. Smoothing trades some bias for a decrease in variance.
Parameters
|
cseries |
complex series to smooth |
|
start, end |
Range of entries to smooth. This defaults to the defined range of cseries. It should always be the range used for the Fourier transform. |
|
newcseries |
result series, by default, overwrite cseries |
|
newstart |
start for newcseries, by default start |
Options
TYPE=[FLAT]/TENT/QUADRATIC/TRIANGULAR
FORM=VECTOR giving the form of the window [unused]
TYPE selects from the types of windows that RATS provides: flat, tent-shaped, or quadratic. FORM allows you to choose your own form for the window. See “The Window Options” for details.
WIDTH=window width [\(.75 \sqrt N\)]
The width of the window. It must be odd. WINDOW will round an even value up to the next odd number.
MASK=masking series [unused]
Use this option when you are going to apply a mask to the bands of the spectrum. The smoothing transformation for entries near a masked-out band becomes increasingly one-sided so it gives no weight to the excluded ordinates. After WINDOW, you should multiply the smoothed series by the masking series.
Description
For a continuous spectral density there are two requirements for consistency:
•The window width must go to infinity as the number of data points increases (ensuring that the variance goes to zero).
•The window width must increase at a rate slower than the increase in the number of data points (ensuring that bias goes to zero).
RATS uses a default width based upon the square root of the number of ordinates. It offers several choices for the type of window, explained below. It uses the following formula to smooth series I to produce S:
\(S\left( j \right) = \sum\limits_{ - \left( {n - 1} \right)}^{n - 1} {{w_k}{\kern 1pt} I{\kern 1pt} {\kern 1pt} \left( {j + k} \right)} \)
where m is window width, \(n = \left( {m + 1} \right)/2\) and the w’s are the window weights. Series I is considered to be periodic of period end—in smoothing the last entries of I, the window wraps around to use entries 1,2, etc. when the formula above asks for end+1,end+2,etc.
For a mean zero series, the ordinate for frequency zero has, perforce, a value of zero. Since most spectral analysis is done with mean zero series, WINDOW treats zero frequency as if it were a masked entry. This means that the moving averages for ordinates near this point are adjusted so they give no weight to the zero value. To include the zero frequency of cseries in the moving averages, you must use a MASK option with a masking series that has ones in all entries. CSET is the easiest way to create such a series.
The Window Options
TYPE=[FLAT]/TENT/QUADRATIC/TRIANGULAR
FORM=VECTOR giving the form of the window [unused]
The window weights \(w_k\) are symmetric about \(k=0\) and add up to one. Using the notation m=window width, \(n = \left( {m + 1} \right)/2\), the windows provided through the TYPE option have the (unscaled) form:
\[{w_k} = \left\{ {\begin{array}{*{20}{c}} 1 & {{\rm{for}}\,\,\, - \left( {n - 1} \right) \le k \le \left( {n - 1} \right)} & {{\rm{(}}{WINDOW = FLAT})} \\ {n - {\kern 1pt} \left| k \right|} & {{\rm{for}}\,\,\, - \left( {n - 1} \right) \le k \le \left( {n - 1} \right)} & {\,\,\,({WINDOW = TENT, TRIANGULAR})} \\ {{n^2} - {k^2}} & {{\rm{for}}\,\,\, - \left( {n - 1} \right) \le k \le \left( {n - 1} \right)} & {{\rm{(}}{WINDOW = QUADRATIC})} \\ \end{array}} \right.\]
The actual weights are scaled to sum to one.
Use the FORM option for a general symmetric window. The VECTOR is dimension n and provides the values for \({w_0},{w_1}, \ldots ,{w_{n - 1}}\), that is, just one side of the window. RATS automatically reflects this for the negative k’s and scales so the weights sum to one. For instance, the quartic window of width 11 could be done by:
declare vector mytent(6) ;*6=(11+1)/2
ewise mytent(k)=6^4-(k-1)^4 ;*max at k=1, zero at k=7
window(form=mytent,width=11) 1 / 2
Comments
The choice of window type is largely a matter of personal preference. With relatively smooth time series, it makes little difference. When the spectrum is likely to have sharp features, the FLAT window, used in conjunction with a taper (instruction TAPER) is probably the best choice. If you are expecting some interesting features (such as peaks at the seasonals), it is usually a good idea to try several window widths, as very narrow peaks may get flattened by a window that is too wide.
Variables Defined
|
%EDF |
equivalent degrees of freedom (REAL) |
|
%EBW |
equivalent band width (REAL) |
The formulas for %EDF and %EBW are
\[{\rm{EDF}} = \left\{ {\begin{array}{*{20}{c}} m \hfill & {m = {\rm{window width}}} \hfill & {{\text{for }}{WINDOW = FLAT}} \hfill \\{3{n^3}/\left( {2{n^2} + 1} \right)} \hfill & {n = \left( {m + 1} \right)/2} \hfill & {{WINDOW = TENT,TRIANGULAR}} \hfill \\ {\frac{1}{{{\text{sum of squared weights}}}}} \hfill & {} \hfill & {{\text{in general}}} \hfill \\ \end{array}} \right.\]
\({\rm{EBW}} = \frac{{\pi {\kern 1pt} {\kern 1pt} {\rm{EDF}}}}{T}\) , where T is the number of ordinates
Note that for a padded series, the computed value for %EBW is correct, but %EDF must be corrected by multiplying by N/T where N is the number of actual data points.
Example
fft 1
cmult(scale=1.0/(2*%pi*%nobs)) 1 1
window(width=9) 1 / 2
window(width=15,type=triangular) 1 / 3
produces series 2 as the periodogram 1 smoothed with flat window of width 9 and series 3 as 1 smoothed with a tent, width 15.
Copyright © 2025 Thomas A. Doan