Compute and/or apply window to input signal
Signal Operations
dspsigops
The Window Function block computes a window and/or applies a window to an input signal. The input signal can be a matrix or an ND array.
The Window Function block has three modes of operation that you can select via the Operation parameter. In each mode, the block first creates a window vector w by sampling the window specified in the Window type parameter at M discrete points. The operation modes are:
Apply window to input
In this mode, the block computes an Mby1 window vector w and applies it to the input. The output y always has the same dimension as the input.
When the input is an MbyN matrix u, the window is multiplied elementwise with each of the N channels in the input matrix u. This is equivalent to the following MATLAB^{®} code:
y = repmat(w,1,N) .* u % Equivalent MATLAB code
The window is always applied to the first dimension:
$$y(i,j,\mathrm{...},k)=w(i)*u(i,j,\mathrm{...},k)\text{}i=1,\mathrm{...},M,\text{}j=1,\mathrm{...},N,\text{}\mathrm{...},\text{}k=1,\mathrm{...},P$$
A lengthM unoriented vector input is treated as an Mby1 matrix.
Generate window
In this mode, the block generates an unoriented window vector w with length M specified by the Window length parameter. The In port is disabled for this mode.
Generate and apply window
In this mode, the block generates an Mby1 window vector w and applies it to the input. The block produces two outputs:
At the Out port, the block produces the result of the multiplication y, which has the same dimension as the input.
At the Win port, the block produces the Mby1 window vector w.
When the input is an MbyN matrix u, the window is multiplied elementwise with each of the N channels in the input matrix u. This is equivalent to the following MATLAB code:
y = repmat(w,1,N) .* u % Equivalent MATLAB code
The window is always applied to the first dimension:
$$y(i,j,\mathrm{...},k)=w(i)*u(i,j,\mathrm{...},k)\text{}i=1,\mathrm{...},M,\text{}j=1,\mathrm{...},N,\text{}\mathrm{...},\text{}k=1,\mathrm{...},P$$
A lengthM 1D vector input is treated as an Mby1 matrix.
The following table lists the available window types. For complete information about the window functions, consult the Signal Processing Toolbox™ documentation.
Window Type  Description 

Computes a Bartlett window. w = bartlett(M)  
Computes a Blackman window. w = blackman(M)  
Computes a rectangular window. w = rectwin(M)  
Computes a Chebyshev window with stopband ripple w = chebwin(M,R)  
Computes a Hamming window. w = hamming(M)  
Computes a Hann window (also known as a Hanning window). w = hann(M)  
Hanning  Obsolete. This window type is included only for compatibility
with older models. Use the 
Computes a Kaiser window with the Kaiser parameter w = kaiser(M,beta)  
Computes a Taylor window. w = taylorwin(M)  
Computes a triangular window. w = triang(M)  
User Defined  Computes the userdefined window function specified by
the entry in the Window function name parameter, w = usrwin(M) % Window takes no extra parameters w = usrwin(M,x_{1},...,x_{n}) % Window takes extra parameters {x_{1} ... x_{n}} 
For the generalizedcosine windows (Blackman
, Hamming
, Hann
,
and Hanning
), the Sampling parameter
determines whether the window samples are computed in a periodic or
a symmetric manner. For example, when Sampling is
set to Symmetric
, a Hamming window of length M is
computed as
w = hamming(M) % Symmetric (aperiodic) window
When Sampling is set to Periodic
,
the same window is computed as
w = hamming(M+1) % Periodic (asymmetric) window w = w(1:M)
The following diagram shows the data types used within the Window Function block for fixedpoint signals for each of the three operating modes.
You can set the window, product output, and output data types in the block dialog box. For more information see the Dialog Box section.
The following model uses the Window Function block to generate and apply a Hamming window to a 3dimensional input array.
In this example, set the Operation mode
of the Window Function block to Generate and apply window
,
so the block provides two outputs: the window vector w at
the Win port, and the result of the multiplication y at
the Out port.
Open the model by typing ex_windowfunction_refex_windowfunction_ref
at
the MATLAB command line, and run it.
The length of the first dimension of the input array
is 10, so the Window Function block generates and outputs a Hamming
window vector of length 10. To see the window vector generated by
the Window Function block, type w
at the MATLAB command
line.
To see the result of the multiplication, type y
at
the MATLAB command line.
The Main pane of the Window Function block dialog appears as follows.
Specify the block's operation, as discussed in Operation Modes. The port configuration of the block is updated to match the setting of this parameter.
Specify the window type to apply, as listed in Window Type. Tunable in simulation only.
Specify the window sampling for generalizedcosine windows.
This parameter is only visible when you select Blackman
, Hamming
, Hann
,
or Hanning
for the Window type parameter. Tunable in
simulation only.
Specify the sample mode for the block, Continuous
or Discrete
,
when it is in Generate Window
mode. In
the Apply window to output
and Generate
and apply window
modes, the block inherits the sample
time from its driving block. Therefore, this parameter is only visible
when you select Generate window
for the Operation parameter.
Specify the sample time for the block when it is in Generate
window
and Discrete
modes.
In Apply window to output
and Generate
and apply window
modes, the block inherits the sample
time from its driving block. This parameter is only visible when you
select Discrete
for the Sample
Mode parameter.
Specify the length of the window to apply. This parameter is
only visible when you select Generate window
for
the Operation parameter. Otherwise, the window
vector length is computed to match the length of the first dimension
of the input.
Specify the level of stopband attenuation, R_{s},
in decibels. This parameter is only visible when you select Chebyshev
for
the Window type parameter. Tunable in
simulation only.
Specify the Kaiser
window β parameter.
Increasing β widens the mainlobe and decreases
the amplitude of the window sidelobes in the window's frequency magnitude
response. This parameter is only visible when you select Kaiser
for
the Window type parameter. Tunable in
simulation only.
Specify the number of sidelobes as a scalar integer value greater
than zero. This parameter is only visible when you select Taylor
for
the Window type parameter.
Specify, in decibels, the maximum sidelobe level relative to
the mainlobe. This parameter must be a scalar less than or equal to
zero. The default value of –30 produces sidelobes with peaks
30 dB down from the mainlobe peak. This parameter is only visible
when you select Taylor
for the Window
type parameter.
Specify the name of the userdefined window function to be calculated
by the block. This parameter is only visible when you select User
defined
for the Window type parameter.
Select to enable the Cell array of additional arguments parameter,
when the userdefined window requires parameters other than the window
length. This parameter is only visible when you select User
defined
for the Window type parameter.
Specify the extra parameters required by the userdefined window function, besides the window length. This parameter is only available when you select the Specify additional arguments to the hamming function parameter. The entry must be a cell array.
The Data Types pane of the Window Function block dialog is discussed in the following sections:
Parameters for Generate Window Only Mode
Parameters for Apply Window Modes
The Data Types pane of the Window
Function block dialog appears as follows when the Operation parameter
is set to Generate window
.
Specify the window data type in one of the following ways:
Choose double
or single
from
the list.
Choose Fixedpoint
to specify
the window data type and scaling in the Signed, Word
length, Set fraction length in output to, and Fraction
length parameters.
Choose Userdefined
to
specify the window data type and scaling in the Userdefined
data type, Set fraction length in output to, and Fraction
length parameters.
Choose Inherit via back propagation
to
set the window data type and scaling to match the following block.
Select to output a signed fixedpoint signal. Otherwise, the signal is unsigned.
Specify the word length, in bits, of the fixedpoint window
data type. This parameter is only visible when you select Fixedpoint
for
the Window data type parameter.
Specify any builtin or fixedpoint data type. You can specify
fixedpoint data types using the FixedPoint Designer™ functions sfix
, ufix
, sint
, uint
, sfrac
, and ufrac
.
This parameter is only visible when you select Userdefined
for
the Window data type parameter.
Specify the scaling of the fixedpoint window data type by either of the following two methods:
Choose Best precision
to
have the window data type scaling automatically set such that the
output signal has the best possible precision.
Choose Userdefined
to
specify the window data type scaling in the Fraction length parameter.
This parameter is only visible when you select Fixedpoint
or Userdefined
for
the Window data type parameter, and when the
specified window data type is a fixedpoint data type.
Specify the fraction length, in bits, of the fixedpoint window
data type. This parameter is only visible when you select Fixedpoint
or Userdefined
for
the Window data type parameter and Userdefined
for
the Set fraction length in output to parameter.
The Data Types pane of the Window
Function block dialog appears as follows when the Operation parameter
is set to either Apply window to input
or Generate
and apply window
.
Select the rounding mode for fixedpoint operations.
The window vector w does not obey this parameter;
it always rounds to Nearest
.
Note: The Rounding mode and Overflow mode settings have no effect on numerical results when both of the following conditions exist:
With these data type settings, the block is effectively operating in full precision mode. 
Select the overflow mode for fixedpoint operations.
The window vector w does not obey this parameter; it is always saturated.
Choose how you specify the word length and fraction length of the window vector w.
When you select Same word length as input
,
the word length of the window vector elements is the same as the word
length of the input. The fraction length is automatically set to the
best precision possible.
When you select Specify word length
,
you can enter the word length of the window vector elements in bits.
The fraction length is automatically set to the best precision possible.
When you select Binary point scaling
,
you can enter the word length and the fraction length of the window
vector elements in bits.
When you select Slope and bias scaling
,
you can enter the word length, in bits, and the slope of the window
vector elements. This block requires poweroftwo slope and a bias
of zero.
The window vector does not obey the Rounding mode and Overflow
mode parameters; it is always saturated and rounded to Nearest
.
Use this parameter to specify how you want to designate the product output word and fraction lengths. See FixedPoint Data Types for illustrations depicting the use of the product output data type in this block:
When you select Inherit via internal
rule
, the product output word length and fraction length
are calculated automatically. For information about how the product
output word and fraction lengths are calculated when an internal rule
is used, see Inherit via Internal Rule.
When you select Same as input
,
these characteristics match those of the input to the block.
When you select Binary point scaling
,
you can enter the word length and the fraction length of the product
output, in bits.
When you select Slope and bias scaling
,
you can enter the word length, in bits, and the slope of the product
output. This block requires poweroftwo slope and a bias of zero.
Choose how you specify the word length and fraction length of the output of the block:
When you select Same as product output
,
these characteristics match those of the product output.
When you select Same as input
,
these characteristics match those of the input to the block.
When you select Binary point scaling
,
you can enter the word length and the fraction length of the output,
in bits.
When you select Slope and bias scaling
,
you can enter the word length, in bits, and the slope of the output.
This block requires poweroftwo slope and a bias of zero.
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify on the block mask.
Port  Supported Data Types 

Input 

Output 

Win 

FFT  DSP System Toolbox 
bartlett  Signal Processing Toolbox 
blackman  Signal Processing Toolbox 
rectwin  Signal Processing Toolbox 
chebwin  Signal Processing Toolbox 
hamming  Signal Processing Toolbox 
hann  Signal Processing Toolbox 
kaiser  Signal Processing Toolbox 
taylorwin  Signal Processing Toolbox 
triang  Signal Processing Toolbox 