Compute and apply window to input signal
DSP System Toolbox / Signal Operations
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.
In
— Input signalInput signal, specified as a vector, matrix, or an N-D array. When the input is fixed point, it can be signed only.
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
Out
— OutputOutput signal, returned as a vector, matrix, or an N-D array.
The Out port is enabled only when Operation is set to:
Apply window to input
–– The block computes an
M-by-1 window vector w and applies it to
the M-by-N input, where
M is the number of rows in the input signal.
Generate and apply window
–– The block generates
an M-by-1 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 outputWindow 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
Operation
— Modes of operationApply 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 M-by-1 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 M-by-N matrix u, the window is multiplied element-wise 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:
A length-M unoriented vector input is treated as an M-by-1 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 M-by-1 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 M-by-1 window vector w.
When the input is an M-by-N matrix u, the window is multiplied element-wise 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:
A length-M 1-D vector input is treated as an M-by-1 vector.
Window type
— Type of windowHamming
(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 user-defined window function specified by the entry
in the Window function name parameter,
w = usrwin(M) % Window takes no extra parameters w = usrwin(M,x1,...,xn) % Window takes extra parameters {x1 ... xn} |
Sampling
— Type of samplingSymmetric
(default) | Periodic
Specify the window sampling for generalized-cosine windows.
For the generalized-cosine 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.
This parameter is visible only when you select
Blackman
, Hamming
,
Hann
, or Hanning
for the
Window type parameter.
Sample mode
— Sample modeContinuous
(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.
This parameter is visible only when you select Generate
window
for the Operation parameter.
Sample time
— Sample time1
(default) | real scalarSpecify 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.
This parameter is visible only when you set Sample mode to
Discrete
.
Window length
— Length of window64
(default) | positive integerSpecify the length of the window to apply.
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 dB50
(default) | nonnegative scalarSpecify the level of stopband attenuation Rs in decibels.
Tunable (Simulink) in simulation only.
This parameter is visible only when you select
Chebyshev
for the Window type
parameter.
Beta
— Kaiser window β parameter10
(default) | real scalarSpecify 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.
This parameter is visible only when you select Kaiser
for the Window type parameter.
Number of sidelobes
— Number of sidelobesSpecify the number of sidelobes as a scalar integer value greater than zero.
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 zeroSpecify 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 visible only when you select Taylor
for the Window type parameter.
Window function name
— Window function namehamming
(default) | character vectorSpecify the name of the user-defined window function to be calculated by the
block. The output window vector returned by the custom window function must be of data
type double
.
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 functionSelect to enable the Cell array of additional arguments parameter, when the user-defined window requires parameters other than the window length.
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 arraySpecify the extra parameters required by the user-defined 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.
When the Operation parameter on the Main tab
is set to Generate window
, the following parameters
appear.
Window data type
— Window data typedouble
(default) | single
| Fixed-point
| User-defined
| Inherit via back propagation
Specify the window data type in one of the following ways:
double
single
Fixed-point
–– To specify the window data type
and scaling in the Signed, Word
length, Set fraction length in output to, and
Fraction length parameters.
User-defined
–– To specify the window data type
and scaling in the User-defined 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 signedSelect to output a signed fixed-point signal. Otherwise, the signal is unsigned.
This parameter appears only when you set Window data type
to Fixed-point
.
Word length
— Word length16
(default) | positive integer in the range [2 128]Specify the word length of the fixed-point window data type in bits.
This parameter is visible only when you set Window data
type to Fixed-point
.
User-defined data type (e.g. sfix(16), float('single))
— user-defined data typesfix(16)
(default) | built-in data type | fixed-point data typeSpecify any built-in or fixed-point data type. You can specify fixed-point data
types using the Fixed-Point Designer™ functions sfix
(Simulink), ufix
(Simulink), sint
(Simulink), uint
(Simulink), sfrac
(Simulink), and ufrac
(Simulink).
This parameter is only visible when you set Window data
type to User-defined
.
Set fraction length in output to
— Scaling of fixed-point window data typeBest precision
(default) | User-defined
Specify the scaling of the fixed-point 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 User-defined
to specify the window data
type scaling in the Fraction length parameter.
This parameter is visible only when you set Window data
type to Fixed-point
or
User-defined
, and when the specified window data type
is a fixed-point data type.
Fraction length
— User-defined fraction length15
(default) | integerSpecify the fraction length of the fixed-point window data type in bits.
This parameter is visible only when you set Window data
type to Fixed-point
or
User-defined
, and when you set Set fraction
length in output to to User-defined
.
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 modeFloor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Simplest
| Zero
Select the rounding mode for fixed-point 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 full-precision mode.
Overflow mode
— Overflow modeWrap
(default) | Saturate
Select the overflow mode for fixed-point operations.
The window vector w does not obey this parameter. It is always saturated.
Window
— Window data typeSame 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 power-of-two 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 typeInherit 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
power-of-two slope and a bias of zero.
Output
— Output data typeSame 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 power-of-two
slope and a bias of zero.
Lock data type settings against changes by the fixed-point tools
— Prevent fixed-point tools from overriding data typesoff
(default) | on
Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block dialog.
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Generated code relies on memcpy
or
memset
functions (string.h
) under certain
conditions.
If the input is fixed point, it must be signed integer or signed fixed point with power-of-two slope and zero bias.
The following diagram shows the data types used within the Window Function block for fixed-point signals for each of the three operating modes.
You can set the window, product output, and output data types in the block dialog box.