Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Contents

Window Function

Compute and/or apply window to input signal

Library

Signal Operations

dspsigops

Description

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 N-D array.

Operation Modes

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 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 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 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 matrix.

Window Type

The following table lists the available window types. For complete information about the window functions, consult the Signal Processing Toolbox™ documentation.

Window TypeDescription

Bartlett

Computes a Bartlett window.

w = bartlett(M)

Blackman

Computes a Blackman window.

w = blackman(M)

Boxcar

Computes a rectangular window.

w = rectwin(M)

Chebyshev

Computes a Chebyshev window with stopband ripple R.

w = chebwin(M,R)

Hamming

Computes a Hamming window.

w = hamming(M)

Hann

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 Hann Window type instead of Hanning whenever possible.

Kaiser

Computes a Kaiser window with the Kaiser parameter beta.

w = kaiser(M,beta)

Taylor

Computes a Taylor window.

w = taylorwin(M)

Triang

Computes a triangular window.

w = triang(M)

User Defined

Computes the user-defined window function specified by the entry in the Window function name parameter, usrwin.

w = usrwin(M) % Window takes no extra parameters
w = usrwin(M,x1,...,xn) % Window takes extra 
parameters {x1 ... xn}

Window Sampling

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)

Fixed-Point Data Types

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. For more information see the Dialog Box section.

Examples

The following model uses the Window Function block to generate and apply a Hamming window to a 3-dimensional 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.

Dialog Box

The Main pane of the Window Function block dialog appears as follows.

Operation

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.

Window type

Specify the window type to apply, as listed in Window Type. Tunable in simulation only.

Sampling

Specify the window sampling for generalized-cosine windows. This parameter is only visible when you select Blackman, Hamming, Hann, or Hanning for the Window type parameter. Tunable in simulation only.

Sample Mode

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.

Sample time

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.

Window length

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.

Stopband attenuation in dB

Specify the level of stopband attenuation, Rs, in decibels. This parameter is only visible when you select Chebyshev for the Window type parameter. Tunable in simulation only.

Beta

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.

Number of sidelobes

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.

Maximum sidelobe level relative to mainlobe (dB)

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.

Window function name

Specify the name of the user-defined window function to be calculated by the block. This parameter is only visible when you select User defined for the Window type parameter.

Specify additional arguments to the hamming function

Select to enable the Cell array of additional arguments parameter, when the user-defined window requires parameters other than the window length. This parameter is only visible when you select User defined for the Window type parameter.

Cell array of additional arguments

Specify 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.

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

Parameters for Generate Window Only Mode

The Data Types pane of the Window Function block dialog appears as follows when the Operation parameter is set to Generate window.

Window data type

Specify the window data type in one of the following ways:

  • Choose double or single from the list.

  • Choose 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.

  • Choose 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.

  • Choose Inherit via back propagation to set the window data type and scaling to match the following block.

Signed

Select to output a signed fixed-point signal. Otherwise, the signal is unsigned.

Word length

Specify the word length, in bits, of the fixed-point window data type. This parameter is only visible when you select Fixed-point for the Window data type parameter.

User-defined data type

Specify any built-in or fixed-point data type. You can specify fixed-point data types using the Fixed-Point Designer™ functions sfix, ufix, sint, uint, sfrac, and ufrac. This parameter is only visible when you select User-defined for the Window data type parameter.

Set fraction length in output to

Specify the scaling of the fixed-point 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 User-defined to specify the window data type scaling in the Fraction length parameter.

This parameter is only visible when you select Fixed-point or User-defined for the Window data type parameter, and when the specified window data type is a fixed-point data type.

Fraction length

Specify the fraction length, in bits, of the fixed-point window data type. This parameter is only visible when you select Fixed-point or User-defined for the Window data type parameter and User-defined for the Set fraction length in output to parameter.

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 either Apply window to input or Generate and apply window.

Rounding mode

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 the following conditions exist:

    • Product output data type is Inherit via internal rule

    • Output data type is Same as product output

    With these data type settings, the block is effectively operating in full precision mode.

Overflow mode

Select the overflow mode for fixed-point operations.

The window vector w does not obey this parameter; it is always saturated.

Window

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 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

Use this parameter to specify how you want to designate the product output word and fraction lengths. See Fixed-Point 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 power-of-two slope and a bias of zero.

Output

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 power-of-two slope and a bias of zero.

Lock data type settings against changes by the fixed-point tools

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block mask.

Supported Data Types

PortSupported Data Types

Input

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point (signed only)

  • 8-, 16-, and 32-bit signed integers

Output

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point (signed only)

  • 8-, 16-, and 32-bit signed integers

Win

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

  • 8-, 16-, and 32-bit integers

See Also

FFTDSP System Toolbox
bartlettSignal Processing Toolbox
blackmanSignal Processing Toolbox
rectwinSignal Processing Toolbox
chebwinSignal Processing Toolbox
hammingSignal Processing Toolbox
hannSignal Processing Toolbox
kaiserSignal Processing Toolbox
taylorwinSignal Processing Toolbox
triangSignal Processing Toolbox

Was this topic helpful?