Language Reference

TFWINDOW Function

TFWINDOW (len <, type> <, params> ) ;

This function is supported by the IML procedure and the iml action.

In signal processing, a window function is useful for smoothing spectra. The TFWINDOW function returns a window of a requested shape and length. For more information about the window functions that are implemented by the TFWINDOW function, see  Harris (1978).

The input arguments are as follows:

len

specifies the length of the window.

type

specifies the type of the window to be created. The default is a HANNING window. The value of the type argument is case-insensitive, and you can abbreviate it. For the "Bartlett_Hahn" and "Blackman_Harris" windows, you must type the first nine characters. For all other windows, you must type at least the first four characters. For example, "Chebyshev" and "CHEB" specify the same window.

params

specifies parameters to be used for creating windows. Not all windows require parameters. When params is missing, the default values of params are used.

The TFWINDOW function supports the following (case-insensitive) values for the type argument. In the following descriptions, N denotes the length of the window, and the N values that define a window are given by w left-bracket 0 right-bracket comma ellipsis comma w left-bracket upper N minus 1 right-bracket. Some windows need additional parameters.

BARTLETT

specifies a Bartlett window, which does not require any parameters. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket 2nd Column equals 1 minus StartAbsoluteValue StartFraction 2 i Over upper N minus 1 EndFraction minus 1 EndAbsoluteValue comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

BARTLETT_HANN

specifies a Bartlett-Hann window, which does not require any parameters. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket 2nd Column equals 0.62 minus 0.48 StartAbsoluteValue StartFraction i Over upper N minus 1 EndFraction minus 0.5 EndAbsoluteValue minus 0.38 cosine StartFraction 2 pi i Over upper N minus 1 EndFraction comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

BLACKMAN

specifies a Blackman window, which does not require any parameters. This window is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket 2nd Column equals 0.42 minus 0.5 cosine StartFraction 2 pi i Over upper N minus 1 EndFraction plus 0.08 cosine StartFraction 4 pi i Over upper N minus 1 EndFraction comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

BLACKMAN_HARRIS

specifies a Blackman-Harris window, which does not require any parameters. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket equals 2nd Column 0.35875 minus 0.48829 cosine StartFraction 2 pi i Over upper N minus 1 EndFraction plus 0.14128 cosine StartFraction 4 pi i Over upper N minus 1 EndFraction 2nd Row 1st Column Blank 2nd Column minus 0.01168 cosine StartFraction 6 pi i Over upper N minus 1 EndFraction comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

BOHMAN

specifies a Bohman window, which does not require any parameters. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket 0 right-bracket equals 2nd Column w left-bracket upper N minus 1 right-bracket equals 0 2nd Row 1st Column w left-bracket i right-bracket equals 2nd Column left-parenthesis 1 minus StartAbsoluteValue 1 minus StartFraction 2 i Over upper N minus 1 EndFraction EndAbsoluteValue right-parenthesis cosine left-parenthesis pi StartAbsoluteValue 1 minus StartFraction 2 i Over upper N minus 1 EndFraction EndAbsoluteValue right-parenthesis 3rd Row 1st Column Blank 2nd Column plus StartFraction 1 Over pi EndFraction sine left-parenthesis pi StartAbsoluteValue 1 minus StartFraction 2 i Over upper N minus 1 EndFraction EndAbsoluteValue right-parenthesis comma for 1 less-than-or-equal-to i less-than-or-equal-to upper N minus 2 EndLayout

CHEBYSHEV

specifies a Chebyshev window, which requires one parameter, att, whose default value is 100. This window is defined in terms of the nth-degree Chebyshev polynomial, upper T Subscript n, which is the unique polynomial such that upper T Subscript n Baseline left-parenthesis cosine theta right-parenthesis equals cosine n theta for all values of theta. upper T Subscript n Baseline left-parenthesis x right-parenthesis can be computed as

upper T Subscript n Baseline left-parenthesis x right-parenthesis equals StartLayout Enlarged left-brace 1st Row  cosine left-parenthesis n cosine Superscript negative 1 Baseline x right-parenthesis comma StartAbsoluteValue x EndAbsoluteValue less-than-or-equal-to 1 2nd Row  hyperbolic cosine left-parenthesis n a c o s h left-parenthesis x right-parenthesis right-parenthesis comma x greater-than 1 3rd Row  left-parenthesis negative 1 right-parenthesis Superscript n Baseline upper T Subscript n Baseline left-parenthesis negative x right-parenthesis comma x less-than negative 1 EndLayout

For odd N (say, upper N equals 2 upper M plus 1) with upper M greater-than 0, the Chebyshev window of length N can be defined as

w left-bracket i right-bracket equals c left-parenthesis 1 plus StartFraction 2 Over upper T Subscript 2 upper M Baseline left-parenthesis beta right-parenthesis EndFraction sigma-summation Underscript k equals 1 Overscript upper M Endscripts upper T Subscript 2 upper M Baseline left-parenthesis beta cosine left-parenthesis k pi slash upper N right-parenthesis right-parenthesis cosine left-parenthesis 2 pi k left-parenthesis i minus upper M right-parenthesis slash upper N right-parenthesis right-parenthesis comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1

where beta equals hyperbolic cosine left-parenthesis a c o s h left-parenthesis 10 Superscript sans-serif-italic att slash 20 Baseline right-parenthesis slash left-parenthesis upper N minus 1 right-parenthesis right-parenthesis and c is chosen to make the largest term of w equal to 1.

For even N, the Chebyshev window of length N can be defined as

w left-bracket i right-bracket equals c sigma-summation Underscript k equals 0 Overscript upper N minus 1 Endscripts left-parenthesis negative 1 right-parenthesis Superscript k Baseline upper T Subscript upper N minus 1 Baseline left-parenthesis beta cosine left-parenthesis k pi slash upper N right-parenthesis right-parenthesis cosine left-parenthesis pi k left-parenthesis 2 i plus 1 right-parenthesis slash upper N right-parenthesis comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1

where c is chosen to make the largest term of w equal to 1.

FLAT_TOP

specifies a flat-top window, which does not require any parameters. This window is function defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket equals 2nd Column 0.21557895 minus 0.41663158 cosine StartFraction 2 pi i Over upper N minus 1 EndFraction plus 0.277263158 cosine StartFraction 4 pi i Over upper N minus 1 EndFraction 2nd Row 1st Column Blank 2nd Column minus 0.083578947 cosine StartFraction 6 pi i Over upper N minus 1 EndFraction plus 0.006947368 cosine StartFraction 8 pi i Over upper N minus 1 EndFraction comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

GAUSSIAN

specifies a Gaussian window, which requires one parameter, c, whose default value is 2.5. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket 2nd Column equals exp left-parenthesis minus StartFraction c squared Over 2 EndFraction left-parenthesis StartFraction i minus left-parenthesis upper N minus 1 right-parenthesis slash 2 Over left-parenthesis upper N minus 1 right-parenthesis slash 2 EndFraction right-parenthesis squared right-parenthesis comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

HAMMING

specifies a Hamming window, which does not require any parameters. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket 2nd Column equals 0.54 minus 0.46 cosine StartFraction 2 pi i Over upper N minus 1 EndFraction comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

HANNING

specifies a Hanning window, which does not require any parameters. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket 2nd Column equals one-half left-parenthesis 1 minus cosine StartFraction 2 pi i Over upper N minus 1 EndFraction right-parenthesis comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

KAISER

specifies a Kaiser window, which requires one parameter, beta, whose default value is 0.5. This window function is defined as

StartLayout 1st Row 1st Column w left-bracket i right-bracket 2nd Column equals StartFraction upper I 0 left-parenthesis beta StartRoot 1 minus left-parenthesis 1 minus 2 i slash left-parenthesis upper N minus 1 right-parenthesis right-parenthesis squared EndRoot right-parenthesis Over upper I 0 left-parenthesis beta right-parenthesis EndFraction comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

where upper I 0 left-parenthesis dot right-parenthesis is the modified Bessel function of the first kind of order 0, which is defined as

StartLayout 1st Row  upper I 0 left-parenthesis x right-parenthesis equals sigma-summation Underscript m equals 0 Overscript normal infinity Endscripts StartFraction left-parenthesis x slash 2 right-parenthesis Superscript 2 m Baseline Over m factorial Superscript 2 Baseline EndFraction EndLayout

PARZEN

specifies a Parzen window, which does not require any parameters. This window function is defined as

w left-bracket i right-bracket equals StartLayout Enlarged left-brace 1st Row  2 left-parenthesis 1 minus StartFraction StartAbsoluteValue 2 i minus left-parenthesis upper N minus 1 right-parenthesis EndAbsoluteValue Over upper N EndFraction right-parenthesis cubed comma 0 less-than-or-equal-to i less-than StartFraction upper N minus 1 Over 4 EndFraction 2nd Row  1 minus 6 left-parenthesis StartFraction StartAbsoluteValue 2 i minus left-parenthesis upper N minus 1 right-parenthesis EndAbsoluteValue Over upper N EndFraction right-parenthesis squared plus 6 left-parenthesis StartFraction StartAbsoluteValue 2 i minus left-parenthesis upper N minus 1 right-parenthesis EndAbsoluteValue Over upper N EndFraction right-parenthesis cubed comma StartFraction upper N minus 1 Over 4 EndFraction less-than-or-equal-to i less-than-or-equal-to StartFraction upper N minus 1 Over 2 EndFraction 3rd Row  upper W left-bracket upper N minus i minus 1 right-bracket comma StartFraction upper N minus 1 Over 2 EndFraction less-than i less-than-or-equal-to upper N minus 1 EndLayout

The last half of the window is defined by symmetry, which implies w left-bracket i right-bracket equals w left-bracket upper N minus i minus 1 right-bracket for 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1.

RECTANGULAR

specifies a rectangular window, which does not require any parameters. This window function is defined as

StartLayout 1st Row  w left-bracket i right-bracket equals 1 comma 0 less-than-or-equal-to i less-than-or-equal-to upper N minus 1 EndLayout

TUKEY

specifies a Tukey window, which requires one parameter, alpha, whose default value is 0.5. Let epsilon equals 10 Superscript negative 12. If alpha greater-than-or-equal-to 1, then a Hanning window is returned; if alpha less-than-or-equal-to epsilon, a rectangular window is returned. For epsilon less-than alpha less-than 1, this window function is defined as

w left-bracket i right-bracket equals StartLayout Enlarged left-brace 1st Row  one-half left-parenthesis 1 plus cosine left-parenthesis StartFraction pi Over alpha EndFraction left-parenthesis StartFraction 2 i Over upper N minus 1 EndFraction minus alpha right-parenthesis right-parenthesis right-parenthesis comma 0 less-than-or-equal-to i less-than alpha left-parenthesis upper N minus 1 right-parenthesis slash 2 2nd Row  1 comma alpha left-parenthesis upper N minus 1 right-parenthesis slash 2 less-than-or-equal-to i less-than-or-equal-to left-parenthesis upper N minus 1 right-parenthesis slash 2 3rd Row  w left-bracket upper N minus i minus 1 right-bracket comma left-parenthesis upper N minus 1 right-parenthesis slash 2 less-than i less-than equals upper N minus 1 EndLayout

The last half of the window is defined by symmetry.

The following statements demonstrate the TFWINDOW function by generating and plotting four different windows:

names = {"Bartlett" "Blackman" "Hanning" "Hamming"};
len = 11;
window = j(len, ncol(names));
do j = 1 to ncol(names);
   window[,j] = tfwindow(len, names[j]);
end;
run WideToLong(t, w, winName,
               window, , names);
title "Signal Processing Windows";
call series(t, w) group=winName grid={X Y};

Figure 474: Window Functions for Signal Processing

Window Functions for Signal Processing


Last updated: May 07, 2026