Window Function
Compute and apply window to input signal
Libraries:
DSP System Toolbox /
Signal Operations
Description
The Window Function block has three modes of operation that enable you to apply a window, or compute a window, or compute and apply a window to an input signal. You can select the mode 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.
Examples
Generate and Apply Hamming Window
Generates and applies a Hamming window using Window Function block.
Ports
Input
In — Input signal
vector  matrix  ND array
Input signal, specified as a vector, matrix, or an ND array.
If the input is fixed point, it must be a signed integer or a signed fixed point value with a poweroftwo slope and zero bias.
This port is enabled only when you set Operation to either
Apply window to input
or Generate and apply
window
.
This port is unnamed when you set Operation to
Apply window to input
.
Data Types: single
 double
 int8
 int16
 int32
 fixed point
Output
Out — Output
vector  matrix  ND array
Output signal, returned as a vector, matrix, or an ND array.
The Out port is enabled only when Operation is set to:
Apply window to input
–– The block computes an Mby1 window vector w and applies it to the MbyN input, where M is the number of rows in the input signal.Generate and apply window
–– The block generates an Mby1 window vector w and applies it to the input.
The output signal has the same dimensions as the input signal. For more details, see Operation.
Data Types: single
 double
 int8
 int16
 int32
 fixed point
Win — Window output
vector
Window output, returned as a vector. When Operation is set to
Apply window to input
or Generate and apply
window
, the window vector is of the same length as the number of rows
in the input signal. When Operation is set to
Generate window
, the length of window vector is
determined by the Window length parameter.
Data Types: single
 double
 int8
 int16
 int32
 fixed point
Parameters
Main
Operation — Modes of operation
Apply window to input
(default)  Generate window
 Generate and apply window
The Window Function block has three modes of operation that you can select through 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 vector.
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 vector.
Window type — Type of window
Hamming
(default)  Bartlett
 Blackman
 ...
This table lists the available window types.
Window Type  Description 

Bartlett  Computes a Bartlett window. w = 
Blackman  Computes a Blackman window. w = 
Boxcar  Computes a rectangular window. w = 
Chebyshev  Computes a Chebyshev window with stopband ripple
w = 
Hamming  Computes a Hamming window. w = 
Hann  Computes a Hann window (also known as a Hanning window). w = 
Hanning  Obsolete. This window type is included only for compatibility
with older models. Use the 
Kaiser  Computes a Kaiser window with the Kaiser parameter
w = 
Taylor  Computes a Taylor window. w = 
Triang  Computes a triangular window. w = 
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}} 
Sampling — Type of sampling
Symmetric
(default)  Periodic
Specify the window sampling for generalizedcosine windows.
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)
Tunable (Simulink) in simulation only.
Dependencies
This parameter is visible only when you select
Blackman
, Hamming
,
Hann
, or Hanning
for the
Window type parameter.
Sample mode — Sample mode
Continuous
(default)  Discrete
Specify the sample mode for the block, Continuous
or
Discrete
, when it is in the Generate
window
mode. In the Apply window to input
and Generate and apply window
modes, the block inherits the
sample mode from its driving block.
Dependencies
This parameter is visible only when you select Generate
window
for the Operation parameter.
Sample time — Sample time
1
(default)  real scalar
Specify the sample time for the block when Operation is set
to Generate window
and Sample mode is
set to Discrete
. When Operation is set
to Apply window to input
and Generate and
apply window
, the block inherits the sample time from its driving
block.
Dependencies
This parameter is visible only when you set Sample mode to
Discrete
.
Window length — Length of window
64
(default)  positive integer
Specify the length of the window to apply.
Dependencies
This parameter is visible only 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.
Stopband attenuation in dB — Stopband attenuation in dB
50
(default)  nonnegative scalar
Specify the level of stopband attenuation R_{s} in decibels.
Tunable (Simulink) in simulation only.
Dependencies
This parameter is visible only when you select
Chebyshev
for the Window type
parameter.
Beta — Kaiser window β parameter
10
(default)  real scalar
Specify the Kaiser
window β
parameter. Increasing β widens the mainlobe and decreases the
amplitude of the window sidelobes in the window's frequency magnitude response.
Tunable (Simulink) in simulation only.
Dependencies
This parameter is visible only when you select Kaiser
for the Window type parameter.
Number of sidelobes — Number of sidelobes
4 (default)  positive integer
Specify the number of sidelobes as a scalar integer value greater than zero.
Dependencies
This parameter is visible only when you select Taylor
for the Window type parameter.
Maximum sidelobe level relative to mainlobe (dB) — Maximum sidelobe level relative to mainlobe
30
(default)  scalar less than or equal to zero
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.
Dependencies
This parameter is visible only when you select Taylor
for the Window type parameter.
Window function name — Window function name
hamming
(default)  character vector
Specify the name of the userdefined window function to be calculated by the
block. The output window vector returned by the custom window function must be of data
type double
.
Dependencies
This parameter is visible only when you select User
defined
for the Window type parameter.
Specify additional arguments to the hamming function — Specify additional arguments to the window function
off (default)  on
Select to enable the Cell array of additional arguments parameter, when the userdefined window requires parameters other than the window length.
Dependencies
This parameter is visible only when you select User
defined
for the Window type parameter.
Cell array of additional arguments — Additional arguments
{'symmetric'}
(default)  cell array
Specify the extra parameters required by the userdefined window function, besides the window length.
Dependencies
This parameter is only available when you select the Specify additional arguments to the hamming function parameter. The entry must be a cell array.
Data Types
When the Operation parameter on the Main tab
is set to Generate window
, the following parameters
appear.
Window data type — Window data type
double
(default)  single
 Fixedpoint
 Userdefined
 Inherit via back propagation
Specify the window data type in one of the following ways:
double
single
Fixedpoint
–– To specify the window data type and scaling in the Signed, Word length, Set fraction length in output to, and Fraction length parameters.Userdefined
–– To specify the window data type and scaling in the Userdefined data type, Set fraction length in output to, and Fraction length parameters.Inherit via back propagation
–– To set the window data type and scaling to match the following block.
Signed — Window output is signed
on (default)  off
Select to output a signed fixedpoint signal. Otherwise, the signal is unsigned.
Dependencies
This parameter appears only when you set Window data type
to Fixedpoint
.
Word length — Word length
16
(default)  positive integer in the range [2 128]
Specify the word length of the fixedpoint window data type in bits.
Dependencies
This parameter is visible only when you set Window data
type to Fixedpoint
.
Userdefined data type (e.g. sfix(16), float('single)) — userdefined data type
sfix(16)
(default)  builtin data type  fixedpoint data type
Specify any builtin or fixedpoint data type. You can specify fixedpoint data
types using the fixdt
(Simulink) function.
Dependencies
This parameter is only visible when you set Window data
type to Userdefined
.
Set fraction length in output to — Scaling of fixedpoint window data type
Best precision
(default)  Userdefined
Specify the scaling of the fixedpoint window data type by using either of these 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.
Dependencies
This parameter is visible only when you set Window data
type to Fixedpoint
or
Userdefined
, and when the specified window data type
is a fixedpoint data type.
Fraction length — Userdefined fraction length
15
(default)  integer
Specify the fraction length of the fixedpoint window data type in bits.
Dependencies
This parameter is visible only when you set Window data
type to Fixedpoint
or
Userdefined
, and when you set Set fraction
length in output to to Userdefined
.
When the Operation parameter on the Main tab
is set to either Apply window to input
or Generate
and apply window
, the following parameters appear.
Rounding mode — Rounding mode
Floor
(default)  Ceiling
 Convergent
 Nearest
 Round
 Simplest
 Zero
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 these conditions exist:
Product output is
Inherit via internal rule
Output is
Same as product output
With these data type settings, the block is effectively operating in a fullprecision mode.
Overflow mode — Overflow mode
Wrap
(default)  Saturate
Select the overflow mode for fixedpoint operations.
The window vector w does not obey this parameter. It is always saturated.
Window — Window data type
Same word length as input
(default)  Specify word length
 Binary point scaling
 Slope and bias scaling
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.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.Binary point scaling
–– You can enter the word length and the fraction length of the window vector elements in bits.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
.
Product output — Product output data type
Inherit via internal rule
(default)  Same as input
 Binary point scaling
 Slope and bias scaling
Use this parameter to specify how you want to designate the product output word and fraction lengths.
When you select:
Inherit via internal rule
–– The product output word length and fraction length are calculated automatically. For information on how the product output word and fraction lengths are calculated when an internal rule is used, see Inherit via Internal Rule.Same as input
–– These characteristics match those of the input to the block.Binary point scaling
–– You can enter the word length and the fraction length of the product output in bits.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.
Output — Output data type
Same as product output
(default)  Same as input
 Binary point scaling
 Slope and bias scaling
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.Same as input
–– These characteristics match those of the input to the block.Binary point scaling
–– You can enter the word length and the fraction length of the output in bits.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.
Lock data type settings against changes by the fixedpoint tools — Prevent fixedpoint tools from overriding data types
off
(default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify in the block dialog box.
Block Characteristics
Data Types 

Direct Feedthrough 

Multidimensional Signals 

VariableSize Signals 

ZeroCrossing Detection 

More About
FixedPoint Data Types
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.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Generated code relies on the memcpy
or
memset
function (string.h
) under certain
conditions.
FixedPoint Conversion
Design and simulate fixedpoint systems using FixedPoint Designer™.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)