DSP Blks
DSP Blks
Blockset
®
For Use with Simulink
Modeling
Simulation
Implementation
User’s Guide
Version 4
How to Contact The MathWorks:
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
508-647-7000 Phone
508-647-7001 Fax
For contact information about worldwide offices, see the MathWorks Web site.
i
Working with Signals
3
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
ii Contents
Displaying Signals in the Time-Domain . . . . . . . . . . . . . . . . . . 3-80
Displaying Signals in the Frequency-Domain . . . . . . . . . . . . . 3-82
Displaying Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-83
DSP Operations
4
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Adaptive Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Filter Designs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Multirate Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10
Using the FFT and IFFT Blocks . . . . . . . . . . . . . . . . . . . . . . . . 4-10
Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
Running Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23
iii
Queues Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26
Sigma-Delta A/D Conversion Demo . . . . . . . . . . . . . . . . . . . . . 4-26
Sine Wave Generation Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26
Spectral Analysis Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26
Statistical Functions Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26
Wavelets Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26
iv Contents
Constant Diagonal Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-82
Constant Ramp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-84
Contiguous Copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-86
Convert 1-D to 2-D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-88
Convert 2-D to 1-D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-90
Convert Complex DSP To Simulink . . . . . . . . . . . . . . . . . . . . . 5-91
Convert Complex Simulink To DSP . . . . . . . . . . . . . . . . . . . . . 5-93
Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-95
Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-97
Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-99
Covariance AR Estimator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-106
Covariance Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-108
Create Diagonal Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-110
Cumulative Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-111
dB Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-113
dB Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-115
DCT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-117
Delay Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-119
Detrend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-123
Difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-124
Digital Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-126
Direct-Form II Transpose Filter . . . . . . . . . . . . . . . . . . . . . . . 5-129
Discrete Impulse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-133
Downsample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-136
DSP Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-143
Dyadic Analysis Filter Bank . . . . . . . . . . . . . . . . . . . . . . . . . . 5-146
Dyadic Synthesis Filter Bank . . . . . . . . . . . . . . . . . . . . . . . . . 5-154
Edge Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-161
Event-Count Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-163
Extract Diagonal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-165
Extract Triangular Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-166
FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-168
Filter Realization Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-178
FIR Decimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-188
FIR Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-195
FIR Rate Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-202
Flip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-206
Forward Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-208
Frame Status Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-210
From Wave Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-212
v
From Wave File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-217
Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-219
IDCT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-223
Identity Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-225
IFFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-227
Inherit Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-234
Integer Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-236
Kalman Adaptive Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-244
LDL Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-249
LDL Inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-252
LDL Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-254
Least Squares Polynomial Fit . . . . . . . . . . . . . . . . . . . . . . . . . 5-256
Levinson-Durbin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-259
LMS Adaptive Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-263
LU Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-267
LU Inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-269
LU Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-270
Magnitude FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-272
Matrix 1-Norm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-275
Matrix Multiply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-277
Matrix Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-279
Matrix Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-281
Matrix Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-283
Matrix Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-285
Matrix Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-287
Maximum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-293
Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-298
Median . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-302
Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-304
Modified Covariance AR Estimator . . . . . . . . . . . . . . . . . . . . 5-309
Modified Covariance Method . . . . . . . . . . . . . . . . . . . . . . . . . . 5-311
Multiphase Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-314
Multiport Selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-317
N-Sample Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-320
N-Sample Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-322
Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-324
Overlap-Add FFT Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-326
Overlap-Save FFT Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-329
Pad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-332
Permute Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-334
vi Contents
Polynomial Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-338
Polynomial Stability Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-340
Pseudoinverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-342
QR Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-344
QR Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-346
Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-348
Random Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-353
Real Cepstrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-360
Reciprocal Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-362
Repeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-364
RLS Adaptive Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-370
RMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-374
Sample and Hold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-378
Short-Time FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-380
Signal From Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-383
Signal To Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-387
Sine Wave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-393
Singular Value Decomposition . . . . . . . . . . . . . . . . . . . . . . . . 5-400
Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-402
Spectrum Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-404
Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-408
Standard Deviation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-413
Submatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-417
SVD Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-425
Time Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-427
Time-Varying Direct-Form II Transpose Filter . . . . . . . . . . . 5-428
Time-Varying Lattice Filter . . . . . . . . . . . . . . . . . . . . . . . . . . 5-433
Toeplitz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-437
To Wave Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-439
To Wave File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-444
Transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-446
Triggered Delay Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-448
Triggered Signal From Workspace . . . . . . . . . . . . . . . . . . . . . 5-451
Triggered To Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-455
Unbuffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-458
Uniform Decoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-461
Uniform Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-465
Unwrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-469
Upsample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-479
Variable Fractional Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-486
vii
Variable Integer Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-491
Variable Selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-499
Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-502
Vector Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-506
Wavelet Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-524
Wavelet Synthesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-530
Window Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-536
Yule-Walker AR Estimator . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-541
Yule-Walker Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-544
Zero Pad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-547
viii Contents
1
Introduction
Welcome to the DSP Blockset . . . . . . . . . . . . 1-2
The DSP Blockset brings the full power of Simulink® to DSP system design and
prototyping by providing key DSP algorithms and components in Simulink’s
adaptable block format. From buffers to linear algebra solvers, from dyadic
filter banks to parametric estimators, the blockset gives you all the core
components to rapidly and efficiently assemble complex DSP systems.
Use the DSP Blockset and Simulink to develop your DSP concepts, and to
efficiently revise and test until your design is production-ready. Use the DSP
Blockset together with the Real-Time Workshop® to automatically generate
code for real-time execution on DSP hardware.
We hope you enjoy using the DSP Blockset, and we look forward to hearing
your comments and suggestions.
support@mathworks.com Technical support
suggest@mathworks.com Product enhancement suggestions
bugs@mathworks.com Bug reports
doc@mathworks.com Documentation error reports
1-2
What Is the DSP Blockset?
Key Features
The DSP Blockset extends the Simulink environment by providing core
components and algorithms for DSP systems. You can use blocks from the DSP
Blockset in the same way that you would use any other Simulink blocks,
combining them with blocks from other libraries to create sophisticated DSP
systems.
A few of the important features are described in the following sections:
• “Frame-Based Operations”
• “Matrix Support”
• “Adaptive and Multirate Filtering”
• “Statistical Operations”
• “Linear Algebra”
• “Parametric Estimation”
• “Real-Time Code Generation”
Frame-Based Operations
Most real-time DSP systems optimize throughput rates by processing data in
“batch” or “frame-based” mode, where each batch or frame is a collection of
consecutive signal samples that have been buffered into a single unit. By
propagating these multisample frames instead of the individual signal
samples, the DSP system can best take advantage of the speed of DSP
algorithm execution, while simultaneously reducing the demands placed on the
data acquisition (DAQ) hardware.
The DSP Blockset delivers this same high level of performance for both
simulation and code generation by incorporating frame-processing capability
1-3
1 Introduction
into all of its blocks. A completely frame-based model can run several times
faster than the same model processing sample-by-sample; faster still if data
sources are frame based.
See “Sample Rates and Frame Rates” on page 3-16 for more information.
Matrix Support
The DSP Blockset takes full advantage of Simulink’s matrix format. Some
typical uses of matrices in DSP simulations are:
See the following sections for more information about working with matrices:
1-4
What Is the DSP Blockset?
Statistical Operations
Use the blocks in the Statistics library for basic statistical analysis. These
blocks calculate measures of central tendency and spread (e.g., mean, standard
deviation, and so on), as well as the frequency distribution of input values
(histograms).
Linear Algebra
The Matrices and Linear Algebra library provides a wide variety of matrix
factorization methods, and equation solvers based on these methods. The
popular Cholesky, LU, LDL, and QR factorizations are all available.
Parametric Estimation
The Parametric Estimation library provides a number of methods for modeling
a signal as the output of an AR system. The methods include the Burg AR
Estimator, Covariance AR Estimator, Modified Covariance AR Estimator, and
Yule-Walker AR Estimator, which allow you to compute the AR system
parameters based on forward error minimization, backward error
minimization, or both.
1-5
1 Introduction
See the Simulink documentation for complete information about the Library
Browser. To access the blockset through its own window (rather than through
the Library Browser), type
dsplib
1-6
What Is in the DSP Blockset?
Double-click on a demo in the list to open that model, and select Start from the
model window’s Simulation menu to run it.
For a complete list of all the blocks in the DSP Blockset by library, see “Block
Library Contents” on page 5-10.
Installation
The DSP Blockset follows the same installation procedure as the MATLAB
toolboxes. See the MATLAB Installation Guide for your platform.
1-7
1 Introduction
at the command line. Expand the DSP Blockset library tree in the Simulink
Library Browser by clicking the symbol next to the DSP Blockset entry. You
can drag blocks directly from the Library Browser into a Simulink model.
Alternatively, you can open the DSP Blockset in its own window by typing
dsplib
at the MATLAB command line. Double-click on any library in the DSP Blockset
window to view its contents, and double-click on a block to access its parameter
dialog box.
The following sections provide additional information to help get you started
with the DSP Blockset:
• Block Help – Press the Help button in any block dialog box to view the online
reference documentation for that block.
• Simulink Library Browser – Right-click on a block to access the help for that
block.
1-8
Getting Started with the DSP Blockset
• Help browser – Select Full Product Family Help from the Help menu, or
type doc or helpdesk at the command line to display the Help browser. Select
DSP Blockset in the Contents pane.
• Command Line – Type doc('block name') at the command line to access the
help for a block with the name block name. Spaces and capitalization in the
block name are ignored.
• Help Desk (remote) – Use a Web browser or the Help browser to connect to
the MathWorks Web site at www.mathworks.com. Follow the Documentation
link on the Support Web page for remote access to the documentation.
• Release Information – Select Full Product Family Help from the Help
menu, or type whatsnew at the MATLAB command line and select the DSP
Blockset Release Notes from the Contents pane of the Help browser. The
Release notes contain information about new features and recent changes to
the version of the DSP Blockset that you are using. You can also type
info dspblks at the MATLAB command line to view detailed release
information related to bug fixes and enhancements.
Use this guide in conjunction with the software to learn about the powerful
features that the DSP Blockset provides.
1-9
1 Introduction
Technical Conventions
The following sections provides a brief overview of the technical conventions
used in this guide, and provides pointers to more detailed information:
u = 1 2 3
4 5 6
In the online help, matrix elements are indexed using either subscript notation
or MATLAB notation. For example, u23 and u(2,3) both refer to the element
in the third column of the second row. The number of channels in a frame-based
matrix is the number of columns, N. More information about matrices can be
found in “Multichannel Signals” on page 3-11.
1-10
Getting Started with the DSP Blockset
The size or length of a vector, M for a column vector or N for a row vector, is the
number of elements that it contains. There is no MATLAB equivalent for a 1-D
Simulink vector (i.e., all MATLAB vectors have either a row or column
orientation), and most blocks in the DSP Blockset treat a 1-D vector as a
column vector.
Sampling Nomenclature
Important sampling-related notational conventions are listed in “Sample Rates
and Frame Rates” on page 3-16.
1-11
1 Introduction
Typographical Conventions
This manual uses some or all of these conventions.
Menu names, menu items, and Boldface with an initial Choose the File menu.
controls capital letter
1-12
R12 Related Products
Note The toolboxes listed below all include functions that extend MATLAB’s
capabilities. The blocksets all include blocks that extend Simulink’s
capabilities. The DSP Blockset requires MATLAB, Simulink, and Signal
Processing Toolbox.
Product Description
1-13
1 Introduction
Product Description
1-14
2
Simulink and the
DSP Blockset
Overview . . . . . . . . . . . . . . . . . . . . . 2-2
Overview
This chapter will help you get started building DSP models with Simulink and
the DSP Blockset. It contains the following sections:
The first section provides a brief overview of the Simulink environment. The
second section provides guidance in tailoring the environment for DSP system
simulation.
2-2
The Simulink Environment
• “Starting Simulink”
• “Getting Started with Simulink”
• “Learning More About Simulink”
Starting Simulink
To start Simulink, click the icon in the MATLAB toolbar, or type
simulink
Simulink on PC Platforms
On PC platforms, the Simulink Library Browser opens when you start
Simulink. The left pane contains a list of all of the blocksets that you currently
have installed.
2-3
2 Simulink and the DSP Blockset
The first item in the list is the Simulink blockset itself, which is already
expanded to show the available Simulink libraries. Click the symbol to the
left of any blockset name to expand the hierarchical list and display that
blockset’s libraries within the browser.
See the Simulink documentation for a complete description of the Library
Browser.
2-4
The Simulink Environment
The following tutorial makes use of the Simulink Library Browser, available
only on PC platforms. If you are working on a UNIX platform, instead of
clicking the symbol in the Library Browser to open a library, simply
double-click the appropriate library in the main Simulink or DSP Blockset
windows. To open the DSP Blockset window from the MATLAB command line,
type dsplib.
• “Model Definition”
• “Model Simulation”
Model Definition
Simulink is a model definition environment. You define a model by creating a
block diagram that represents the computations and data flow of your system
or application. Try building a simple model that adds two sine waves and
displays the result.
2-5
2 Simulink and the DSP Blockset
One of the things that dspstartup does is set the Stop time value in the
Simulation parameters dialog box to inf for all new models. The inf
setting instructs Simulink to run the model until you click the simulation
stop button. You can access this dialog box and enter a different Stop time
value by selecting Simulation parameters from the model window’s
Simulation menu.
3 Select New > Model from the File menu in the Library Browser. A new
model window appears on your screen.
2-6
The Simulink Environment
a Click Sinks (in the Simulink tree) to view the blocks in the Simulink
Sinks library.
b Drag the Scope block from the Sinks library into the model window. (The
Simulink Scope block is the same as the Time Scope block in the DSP
Sinks library.)
a Position the pointer near the output port of the Sine Wave block. Hold
down the mouse button (the left button for a multibutton mouse) and
drag the line that appears until it touches the input port of the Matrix
Sum block. Release the mouse button.
b Using the same technique, connect the output of the Matrix Sum block to
the input port of the Scope block.
a Double-click on the Sine Wave block. The dialog box that appears allows
you to set the block’s parameters. Parameters are defining values that tell
the block how to operate.
For this example, configure the block to generate a 10 Hz sine wave and
a 20 Hz sine wave by entering [10 20] for the Frequency parameter.
Both sinusoids will have the default amplitude of 1 and phase of 0
specified by the Amplitude and Phase offset parameters. They also both
share the default sample period of 0.001 seconds specified by the Sample
time parameter, which represents a sample rate of 1000 Hz.
2-7
2 Simulink and the DSP Blockset
Model Simulation
Simulink is also a model simulation environment. You can run the simulation
block diagram that you have built to see how the system behaves. To do this:
1 Select Signal dimensions from the Format menu (optional). The symbol
“[1x2]” appears on the output line from Sine Wave indicating that the
output is a 1-by-2 matrix.
At each sample time, the output matrix contains one sample from each of the
two sinusoids. The Matrix Sum block adds the two matrix elements together
2-8
The Simulink Environment
to produce a scalar output. Thus, the input to the Scope block is the
point-by-point sum of the two sinusoids.
2 Double-click on the Scope block if the Scope window is not already open on
your screen. The scope window appears.
3 Select Start from the Simulation menu in the block diagram window. The
signal containing the summed 10 Hz and 20 Hz component sinusoids is
plotted on the scope.
a While the simulation is running, right-click on the y-axis of the scope and
select Autoscale. The vertical range of the scope is adjusted to better fit
the signal.
b Click the Properties button on the scope, , and enter 0.1 for Time
range. This resizes the scope’s time axis to display only one cycle of the
signal.
Note that the sample rate of both sinusoids is 1000 Hz, so aliasing will
occur for sinusoid frequencies above 500 Hz. You can increase the sample
rate by entering a smaller value in the Sine Wave block’s Sample time
parameter. This parameter is not tunable (see below), so you will need to
stop the simulation before making any adjustment.
2-9
2 Simulink and the DSP Blockset
Running a Simulation from an M-File. You can also modify and run a Simulink
simulation from within a MATLAB M-file. By doing this, you can automate the
variation of model parameters to explore a large number of simulation
conditions rapidly and efficiently. For information on how to do this, see “Delay
and Latency” on page 3-85 and “Running a Simulation from the Command
Line” in the Simulink documentation.
2-10
Configuring Simulink for DSP Systems
• “Using dspstartup.m”
• “Customizing dspstartup.m”
• “Performance-Related Settings”
• “Miscellaneous Settings”
2-11
2 Simulink and the DSP Blockset
Using dspstartup.m
There are two ways to use the dspstartup M-file to preconfigure Simulink for
DSP simulations:
If you do not have a startup.m file on your path, you can create one from the
startupsav.m template in the toolbox/local directory.
dspstartup;
The default settings in dspstartup will now be in effect every time you launch
Simulink.
For more information about performing automated tasks at startup, see the
documentation for the startup command in the “MATLAB Function
Reference.”
Customizing dspstartup.m
You can edit the dspstartup M-file to change any of the settings above or to
add your own custom settings. For example, you can change the 'StopTime'
option to a value that is better suited to your particular simulations, or set the
'SaveTime' option to 'on' if you prefer to record the simulation sample times.
2-12
Configuring Simulink for DSP Systems
Performance-Related Settings
A number of the settings in the dspstartup M-file are chosen to improve the
performance of the simulation:
2-13
2 Simulink and the DSP Blockset
precomputed
2-14
Configuring Simulink for DSP Systems
of servicing the loop in cases when inline code can be used with only a modest
increase in the file size.
However, because typical DSP processors offer zero-overhead looping, code
size is the primary optimization constraint in most designs. It is therefore
more efficient to minimize code size by generating a loop for every instance
of iteration, regardless of the number of repetitions. This is what the
'RTWOptions' loop-rolling setting in dspstartup accomplishes.
Miscellaneous Settings
The dspstartup M-file adjusts several other parameters to make it easier to
run DSP simulations. Two of the important settings are:
• 'StopTime' is set to 'inf', which allows the simulation to run until you
manually stop it by selecting Stop from the Simulation menu, or by pressing
the Stop Simulation button on the toolbar. To set a finite stop time, enter a
value for the Stop time parameter in the Simulation Parameters dialog
box.
2-15
2 Simulink and the DSP Blockset
2-16
3
Overview
The first part of this chapter will help you understand how signals are
represented in Simulink. It covers a number of topics that are especially
important in DSP simulations, such as sample rates and frame-based
processing:
• “Signal Concepts”
• “Sample Rates and Frame Rates”
The second part of the chapter explains the practical aspects of how to create,
construct, import, export, and view signals:
• “Creating Signals”
• “Constructing Signals”
• “Deconstructing Signals”
• “Importing Signals”
• “Exporting Signals”
• “Viewing Signals”
The last part of the chapter deals with the advanced topic of delay and latency:
• “Delay and Latency”
3-2
Signal Concepts
Signal Concepts
Simulink models can process both discrete-time and continuous-time signals,
although models that are built with the DSP Blockset are often intended to
process only discrete-time signals. The next few sections cover the following
topics:
Discrete-Time Signals
A discrete-time signal is a sequence of values that correspond to particular
instants in time. The time instants at which the signal is defined are the
signal’s sample times, and the associated signal values are the signal’s samples.
Traditionally, a discrete-time signal is considered to be undefined at points in
time between the sample times. For a periodically sampled signal, the equal
interval between any pair of consecutive sample times is the signal’s sample
period, Ts. The sample rate, Fs, is the reciprocal of the sample period, or 1/Ts.
The sample rate is the number of samples in the signal per second.
For example, the 7.5-second triangle wave segment below has a sample period
of 0.5 seconds, and sample times of 0.0, 0.5, 1.0, 1.5, ...,7.5. The sample rate of
the sequence is therefore 1/0.5, or 2 Hz.
Ts
0 1 2 3 4 5 6 7 time (s)
3-3
3 Working with Signals
3-4
Signal Concepts
Note In the block dialog boxes, the term sample time is used to refer to the
sample period, Ts. An example is the Sample time parameter in the Signal
From Workspace block, which specifies the imported signal’s sample period.
3-5
3 Working with Signals
The following sections explain the parameters available in this dialog box:
You can automatically set the above solver options for all new models by
running the dspstartup M-file. See “Configuring Simulink for DSP Systems”
on page 2-11 for more information.
In Fixed-step SingleTasking mode, discrete-time signals differ from the
prototype described in “Discrete-Time Signals” on page 3-3 by remaining
defined between sample times. For example, the representation of the
discrete-time triangle wave looks like this.
Ts
0 1 2 3 4 5 6 7 time (s)
The above signal’s value at t=3.112 seconds is the same as the signal’s value at
t=3 seconds. In Fixed-step SingleTasking mode, a signal’s sample times are
the instants where the signal is allowed to change values, rather than where
the signal is defined. Between the sample times, the signal takes on the value
at the previous sample time.
As a result, in Fixed-step SingleTasking mode, Simulink permits cross-rate
operations such as the addition of two signals of different rates. This is
explained further in “Cross-Rate Operations in Variable-Step and Fixed-Step
SingleTasking Modes” on page 3-7.
3-6
Signal Concepts
3-7
3 Working with Signals
Example: Cross-Rate Operations. Consider the model below, which sums two
signals having different sample periods. The fast signal (Ts=1) has sample
times 1, 2, 3, ..., and the slow signal (Ts=2) has sample times 1, 3, 5, ....
This example will generate an error under the dspstartup settings, as
explained in the previous Note.
Ts = 1
Ts = 2
The output, yout, is a matrix containing the fast signal (Ts=1) in the first
column, the slow signal (Ts=2) in the second column, and the sum of the two in
the third column.
yout =
1 1 2
2 1 3
3 2 5
4 2 6
5 3 8
6 3 9
7 4 11
8 4 12
9 5 14
10 5 15
As expected, the slow signal (second column) changes once every two seconds,
half as often as the fast signal. Nevertheless, it has a defined value at every
3-8
Signal Concepts
Sample Time Offsets. Simulink offers the ability to shift a signal’s sample times
by an arbitrary value, which is equivalent to shifting the signal’s phase by a
fractional sample period. However, sample-time offsets are rarely used in DSP
systems, and blocks from the DSP Blockset do not support them.
Continuous-Time Signals
Most signals in a DSP model are discrete-time signals, and all of the blocks in
the DSP Blockset accept discrete-time inputs. However, many blocks can also
operate on continuous-time signals, whose values vary continuously with time.
Similarly, most blocks generate discrete-time signals, but some also generate
continuous-time signals.
The sampling behavior of a particular block (continuous or discrete)
determines which other blocks you can connect as an input or output. The
following sections describe the behavior for two types of blocks:
• “Source Blocks”
• “Nonsource Blocks”
See Chapter 5, “DSP Block Reference,” for information about the particular
sample characteristics of each block in the blockset.
Source Blocks
Source blocks are those blocks that generate or import signals in a model. Most
source blocks appear in the DSP Sources library. See section “Importing
Signals” on page 3-62 to fully explore the features of these blocks.
3-9
3 Working with Signals
Correct:
Nonsource Blocks
All nonsource blocks in the DSP Blockset accept discrete signals, and inherit
the sample period of the input. Others additionally accept continuous-time
discrete signals.
3-10
Signal Concepts
Multichannel Signals
The following figure shows the prototypical discrete-time signal discussed in
“Discrete-Time Signals” on page 3-3. If this signal were propagated through a
model sample-by-sample, rather than in batches of samples, it would be called
sample-based. It would also be called single-channel, because there is only one
independent sequence of numbers.
Ts
0 1 2 3 4 5 6 7 time (s)
3-11
3 Working with Signals
See the following sections for information about working with sample-based
multichannel signals:
3-12
Signal Concepts
(or time slice) from N distinct signal channels, and each matrix column
represents M consecutive samples from a single channel.
This is a simple structure, as illustrated below for a sample 6-by-4 frame
matrix.
1 1 1 1
2 2 2 2 Frame matrix:
3 3 3 3 4 channels,
4 4 4 4 1 frame per channel,
5 5 5 5 6 samples per frame
6 6 6 6
sample 1 1 1 1 1
frame 1 (u t=0)
sample 2 2 2 2 2
See the following sections for information about working with frame-based
multichannel signals:
3-13
3 Working with Signals
3-14
Signal Concepts
Sample-based operation
ISR
time
acquire sample
Frame-based operation
time
latency
Accelerating Simulations
Simulation also benefits from frame-based processing. In this case, it is the
overhead of block-to-block communications that is reduced by propagating
frames rather than individual samples.
3-15
3 Working with Signals
Ts = Tf ⁄ M
More specifically, the sample periods of inputs (Tsi) and outputs (Tso) are
related to their respective frame periods by
T si = T fi ⁄ M i
T so = T fo ⁄ M o
3-16
Sample Rates and Frame Rates
where Mi and Mo are the input and output frame sizes, respectively.
The illustration below shows a one-channel frame-based signal with a frame
size (Mi) of 4 and a frame period (Tfi) of 1. The sample period, Tsi, is therefore 1/
4, or 0.25 seconds. A Probe block connected to this signal would display the
frame period Tfi = 1.
Tfi = 1
first input frame
13 9 5 1
Tsi = 0.25
14 10 6 2
15 11 7 3
16 12 8 4
In most cases, the sequence sample period Tsi is of primary interest, while the
frame rate is simply a consequence of the frame size that you choose for the
signal. For a sequence with a given sample period, a larger frame size
corresponds to a slower frame rate, and vice versa.
For information on converting a signal from one sample rate or frame rate to
another, see “Converting Sample Rates and Frame Rates” on page 3-20.
3-17
3 Working with Signals
The block displays the label Ts or Tf, followed by a two-element vector. The
first (left) element is the period of the signal being measured. The second
(right) is the signal’s sample time offset, which is usually 0, as explained in
“Sample Time Offsets” on page 3-9.
For sample-based signals, the value shown in the Probe block icon is the
sample period of the sequence, Ts. For frame-based signals, the value shown in
the Probe block icon is the frame period, Tf. The difference between sample
rates and frame rates is explained in “Sample Rate and Frame Rate Concepts”
on page 3-16.
Probe Block Example: Sample-Based. The three Probe blocks in the sample-based
model below verify that the signal’s sample period is halved with each
upsample operation: The output from the Signal From Workspace block has a
sample period of 1 second, the output from the first Upsample block has a
sample period of 0.5 seconds, and the output from the second Upsample block
has a sample period of 0.25 seconds.
Probe Block Example: Frame-Based. The three Probe blocks in the frame-based
model below again verify that the signal’s sample period is halved with each
upsample operation: The output from the Signal From Workspace block has a
frame period of 16 seconds, the output from the first Upsample block has a
frame period of 8 seconds, and the output from the second Upsample block has
a sample period of 4 seconds.
3-18
Sample Rates and Frame Rates
Note that the sample rate conversion is implemented through a change in the
frame period rather than the frame size. This is because the Frame-based
mode parameter in the Upsample blocks is set to Maintain input frame size
rather than Maintain input frame rate. See “Converting Sample Rates and
Frame Rates” on page 3-20 for more information.
Sample Time Color Coding Example: Sample-Based. Here is the sample-based model
from “Probe Block Example: Sample-Based” on page 3-18 with the Probe blocks
removed and sample time color coding turned on.
Since every sample-based signal in this model has a different sample rate, each
signal is assigned a different color.
Sample Time Color Coding Example: Frame-Based. Here’s the frame-based model
from “Probe Block Example: Frame-Based” on page 3-18 with the Probe blocks
removed and sample time color coding turned on.
3-19
3 Working with Signals
For more information about sample time color coding, see “Sample Time
Colors” in the Simulink documentation.
T si = T fi ⁄ M i
T so = T fo ⁄ M o
where Mi and Mo are the input and output frame sizes, respectively.
The buffering and rate-conversion capabilities of the DSP Blockset generally
allow you to independently vary any two of the three parameters (Tso, Tfo, Mo).
In most cases, the sample period and the frame size are the two parameters of
primary interest; the frame period is simply a consequence of your choices for
the other two.
There are two common types of operations that impact the frame and sample
rates of a signal:
3-20
Sample Rates and Frame Rates
Both operations are discussed in the following sections, along with ways to
avoid unintentional rate conversions:
You may also want to look at the Sample Rate Conversion demo,
dspsrcnv.mdl.
• Maintain input frame rate: Change the sample rate by changing the frame
size (i.e., Mo ≠ Mi), but keep the frame rate constant (i.e., Tfo = Tfi)
• Maintain input frame size: Change the sample rate by changing the output
frame rate (i.e., Tfo ≠ Tfi), but keep the frame size constant (i.e., Mo = Mi)
3-21
3 Working with Signals
Rate Conversion Blocks. The following table lists the principal rate conversion
blocks in the DSP Blockset. Blocks marked with an asterisk (*) offer the option
of changing the rate by either adjusting the frame size or frame rate.
Block Library
The following examples illustrate the two sample rate conversion modes:
3-22
Sample Rates and Frame Rates
The sample period and frame size of the original signal are set to 0.125 seconds
and 8 samples per frame, respectively, by the Sample time and Samples per
frame parameters in the Signal From Workspace block. This results in a frame
rate of 1 second (0.125∗8), as shown by the first Probe block.
The Downsample block is configured to downsample the signal by changing the
frame rate rather than the frame size. The dialog box with this setting is shown
below.
The second Probe block in the model verifies that the output from the
Downsample block has a frame period of 2, twice that of the input (i.e., half the
rate). As a result, the sequence sample period is doubled to 0.25 seconds
without any change to the frame size.
Example: Rate Conversion by Frame-Size Adjustment. The model from “Example: Rate
Conversion by Frame-Rate Adjustment” on page 3-22 is shown again below,
but this time with the rate conversion implemented by adjusting the frame
size, rather than the frame rate.
3-23
3 Working with Signals
As before, the frame rate of the original signal is 1 second (0.125∗8), shown by
the first Probe block. Now the Downsample block is configured to downsample
the signal by changing the frame size rather than the frame rate. The dialog
box with this setting is shown below.
The line width display on the Downsample output port verifies that the
downsampled output has a frame size of 4, half that of the input. As a result,
the sequence sample period is doubled to 0.25 seconds without any change to
the frame rate.
Frame Rebuffering
Buffering operations provide another mechanism for rate changes in DSP
models. The purpose of many buffering operations is to adjust the frame size of
the signal, M, without altering the sequence sample rate Ts. This usually
results in a change to the signal’s frame rate, Tf, according to the relation
T f = MT s
3-24
Sample Rates and Frame Rates
However, this is only true when the original signal is preserved in the buffering
operation, with no samples added or deleted. Buffering operations that
generate overlapping frames, or that only partially unbuffer frames, alter the
data sequence by adding or deleting samples. In such cases, the above relation
is not valid.
Buffering Blocks. The following table lists the principal buffering blocks in the
DSP Blockset.
Block Library
Buffering with Preservation of the Signal. There are various reasons that you may
need to rebuffer a signal to a new frame size at some point in a model. For
example, your data acquisition hardware may internally buffer the sampled
signal to a frame size that is not optimal for the DSP algorithm in the model.
In this case, you would want to rebuffer the signal to a frame size more
appropriate for the intended operations, but without introducing any change to
the data or sample rate.
There are two blocks in the Buffers library that can be used to change a signal’s
frame size without altering the signal itself:
• Buffer – redistributes signal samples to a larger or smaller frame size
• Unbuffer – unbuffers a frame-based signal to a sample-based signal (frame
size = 1)
3-25
3 Working with Signals
The Buffer block preserves the signal’s data and sample period only when its
Buffer overlap parameter is set to 0. The output frame period, Tfo, is
M o T fi
T fo = ----------------
Mi
where Tfi is the input frame period, Mi is the input frame size, and Mo is the
output frame size specified by the Buffer size parameter.
The Unbuffer block is specialized for completely unbuffering a frame-based
signal to its sample-based equivalent, and always preserves the signal’s data
and sample period:
T so = T fi ⁄ M i
where Tfi and Mi are the period and size, respectively, of the frame-based input.
Both the Buffer and Unbuffer blocks preserve the sample period of the
sequence in the conversion (Tso = Tsi).
Example: Buffering with Preservation of the Signal. In the model below, a signal with
a sample period of 0.125 seconds is rebuffered from a frame size of 8 to a frame
size of 16. This doubles the frame period from 1 to 2 seconds, but does not
change the sample period of the signal (Tso = Tsi = 0.125).
Buffering with Alteration of the Signal. Some forms of buffering alter the signal’s
data or sample period, in addition to adjusting the frame size. There are many
instances when this type of buffering is desirable, for example when creating
sliding windows by overlapping consecutive frames of a signal, or selecting a
subset of samples from each input frame for processing.
The blocks that alter a signal while adjusting its frame size are listed below. In
this list, Tsi is the input sequence sample period, and Tfi and Tfo are the input
and output frame periods, respectively.
3-26
Sample Rates and Frame Rates
where Mo is the output frame size specified by the Buffer size parameter. As
a result, the new output sample period is
( M o – L )T si
T so = -------------------------------
Mo
• Delay Line adds duplicate samples to the sequence when the Delay line size
parameter, Mo, is greater than 1. The output and input frame periods are the
same, Tfo = Tfi = Tsi, and the new output sample period is
T si
T so = --------
Mo
• Variable Selector can remove, add, and/or rearrange samples in the input
frame when Select is set to Rows. The output and input frame periods are
the same, Tfo = Tfi, and the new output sample period is
M i T si
T so = ----------------
Mo
3-27
3 Working with Signals
Example: Buffering with Alteration of the Signal. In the model below, a signal with a
sample period of 0.125 seconds is rebuffered from a frame size of 8 to a frame
size of 16 with an overlap of 4.
The relation for the output frame period for the Buffer block is
T fo = ( M o – L )T si
Example 1: No Rate Conversion. The model below plots the magnitude FFT of a
signal composed of two sine waves, with frequencies of 1 Hz and 2 Hz.
3-28
Sample Rates and Frame Rates
To build the model, configure one Sine Wave block with Frequency = 1, and
the other with Frequency = 2. In addition, both Sine Wave blocks should have
the following settings:
The frame period of the resulting summed sinusoid is 12.8 seconds (i.e.,
128∗0.1), which is confirmed by the Probe block when the model is updated.
Select Inherit FFT length from input dimensions in the Magnitude FFT
block. This setting instructs the block to use the input frame size (128) as the
FFT length (which is also the output size).
Configure the Vector Scope block as follows:
3-29
3 Working with Signals
The Vector Scope block uses the input frame size (128) and period (12.8) to
deduce the original signal’s sample period (0.1), which allows it to correctly
display the peaks at 1 Hz and 2 Hz.
Example 2: Unintended Rate Conversion. Now alter the previous example by setting
the Magnitude FFT block parameters as follows:
• Deselect the Inherit FFT length from input dimensions check box.
• Set the FFT length parameter to 256.
This setting instructs the block to zero-pad the length-128 input frame to a
length of 256 before performing the FFT. The signal dimension display on the
new version of the model shows that the output of the Magnitude FFT block is
now a length-256 frame.
3-30
Sample Rates and Frame Rates
In this case, based on the input frame size (256) and period (12.8), the Vector
Scope block calculates the original signal’s sample period to be 0.05 seconds
(12.8/256), which is wrong. As a result, the spectral peaks appear at the
incorrect frequencies, 2 Hz and 4 Hz rather than 1 Hz and 2 Hz.
The problem is that the zero-pad operation performed by the Magnitude FFT
block halves the sample period of the sequence by appending 128 zeros to each
frame. The Vector Scope block, however, needs to know the sample period of
the original signal. The problem is easily solved by changing the Sample time
of original time series setting in the Axis properties panel of the Vector
Scope block to the actual sample period of 0.1. The plot generated with this
setting is identical to the first Vector Scope plot above.
In general, be aware that when you do zero-padding or overlapping buffering
you are changing the sample period of the signal. As long as you keep this in
mind, you should be able to anticipate and correct problems like the one above.
3-31
3 Working with Signals
The Output signal parameter (or the signal at the optional Ref input port)
determines the frame status of the output If the frame status of the input
differs from the Output signal setting, then the frame status is altered as
specified. If the frame status of the input is the same as that specified by the
Output signal parameter, then no change is made to the signal.
The block’s input and output port rates are the same, and because the block
does not make any sample rate accommodation, the sample rate of the signal
is generally not preserved under a change of frame status. (The exception to
this rule occurs when a sample-based signal is converted to a frame-based
signal with frame size 1, or vice versa.)
See the Frame Status Conversion block’s reference page for complete
information.
3-32
Creating Signals
Creating Signals
There are a variety of different ways to create signals using Simulink and DSP
blocks. The following sections explore the most common techniques:
3-33
3 Working with Signals
• “Creating Signals Using the Signal From Workspace Block” on page 3-38
As with all numerical parameters, you can also enter any valid MATLAB
variable or expression that evaluates to a matrix. See the MATLAB
documentation for a thorough introduction to constructing and indexing
matrices.
The Interpret vector parameters as 1-D and Frame-based output
parameters are discussed following the example below. See the DSP Constant
block’s reference page for information about the Sample mode and Sample
time parameters.
The model below shows five DSP Constant blocks, each generating one of the
constant signals listed above. Two of the blocks have non-default settings for
the other parameters: The third block (DSP Constant2) has the Frame-based
3-34
Creating Signals
output check box selected, and the fourth block (DSP Constant3) has the
Interpret vector parameters as 1-D check box selected.
Sample-based matrix
(6 channels)
Sample-based matrix
(6 channels)
Frame-based matrix
(3 channels)
1-D vector
Frame-based matrix
(1 channel)
In addition to the various output dimensions in the model, you can observe
three different kinds of signals:
• Sample-based matrix signal – The DSP Constant and DSP Constant1 blocks
generate sample-based matrices (2-by-3 and 3-by-2, respectively) because
the Frame-based output check box in those blocks is not selected. The
sample-based matrices can each be considered to each have six independent
channels.
• Frame-based matrix signal – The DSP Constant2 and DSP Constant4 blocks
generate frame-based matrices (2-by-3 and 3-by-1, respectively, and
represented by double lines) because the Frame-based output check box in
those blocks is selected. The 2-by-3 frame-based matrix is considered to have
three independent channels, each containing two consecutive samples. The
3-by-1 frame-based matrix (column vector) is considered to have one
independent channel, containing three consecutive samples.
• 1-D vector signal – The DSP Constant3 block generates a length-3 1-D vector
signal because the Interpret vector parameters as 1-D check box in that
3-35
3 Working with Signals
block is selected. This means that the output is not a matrix. However, most
nonsource DSP blocks interpret a length-M 1-D vector as an M-by-1 matrix
(column vector).
See “Multichannel Signals” on page 3-11 for more information about the
representation of sample-based and frame-based data.
• Chirp
• Counter
• Discrete Impulse
• Multiphase Clock
• N-Sample Enable
• Sine Wave
One of the most commonly used of these is the Sine Wave block, which is
discussed further in the example below. See Chapter 5, “DSP Block Reference,”
for a complete explanation of the other signal generation blocks. The Simulink
Sources library offers a collection of continuous-time signal generation blocks
that you may also find useful. Consult the Simulink documentation for more
information.
For more information about creating signals, see the following sections:
3-36
Creating Signals
• Amplitude
• Frequency
• Phase offset
• Sample time
• Samples per frame
In the model below, a Sine Wave block generates a frame-based (multichannel)
matrix containing three independent signals:
Each channel has a frame size of 64 samples. The three signals are summed
point-by-point by a Matrix Sum block, and exported to the workspace.
To build the model, set the Sum along parameter of the Matrix Sum block to
Rows, and make the following parameter settings in the Sine Wave block:
After running the model, you can look at a portion of the resulting summed
sinusoid by typing
plot(yout(1:100))
3-37
3 Working with Signals
−2
−4
−6
0 20 40 60 80 100
See “Multichannel Signals” on page 3-11 for more information about the
representation of sample-based and frame-based data.
As the name implies, the Signal From Workspace block is more commonly used
to import custom signals from the workspace. See the following sections for
more information:
3-38
Creating Signals
For more information about creating signals, see the following sections:
• Channel 1: 1, 2, 3, 0, 0,...
• Channel 2: -1, -2, -3, 0, 0,...
• Channel 3: 0, 0, 0, 0, 0,...
• Channel 4: 5, 5, 5, 0, 0,...
00 3 –3 2 –2 1 –1
00 0 5 0 5 0 5
To create the model, specify the following parameter values in the Signal From
Workspace block:
The Sample time setting of 1 yields a sample-based output with sample period
of 1 second. Each of the four elements in the matrix signal represents an
independent channel (the channel numbering is arbitrary). The Form output
after final data value parameter setting specifies that all outputs after the
third are zero.
3-39
3 Working with Signals
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
0 0 9 1 5 1 1 1
0 0 10 1 6 1 2 1
0 0 0 0 7 0 3 0
0 0 0 0 8 0 4 0
t=12 t=8 t=4 t=0
To create the model, specify the following parameter values in the Signal From
Workspace block:
The Sample time setting of 1 and the Samples per frame setting of 4 yield a
frame-based output with a frame size of 4 samples and a frame period of
4 seconds. The Form output after final data value parameter setting
specifies that all outputs after the third frame are zero.
Note that the output of the To Workspace block, yout, is the original signal
with appended zeros in each channel.
3-40
Creating Signals
yout =
1 1
2 1
3 0
4 0
5 1
6 1
7 0
8 0
9 1
10 1
0 0
0 0
3-41
3 Working with Signals
Constructing Signals
When you want to perform a given sequence of operations on several
independent signals, it is frequently very convenient to group those signals
together as a multichannel signal. Most DSP blocks accept multichannel
signals, and process each channel independently. By taking advantage of this
capability, you can do the same job with fewer blocks and have a cleaner, leaner
model.
For example, if you need to filter each of four independent signals using a
direct-form II transpose filter with the same coefficients, combine the signals
into a multichannel signal, and run that multichannel signal into a
Direct-Form II Transpose Filter block. The block will apply the filter to each
channel independently.
The following sections explain how to construct multichannel signals from
existing independent signals:
For information about creating multichannel signals using source blocks, see
the following sections:
3-42
Constructing Signals
3-43
3 Working with Signals
Each 4-by-1 output from the Matrix Concatenation block contains one sample
from each of the four input signals. All four samples in the output correspond
to the same instant in time. The Reshape block simply rearranges the samples
into a 2-by-2 matrix. Note that the Reshape block works columnwise, so that a
column vector input is reshaped as shown below.
1
2 1 3
3 2 4
4
The 4-by-1 matrix and the 2-by-2 matrix in the above model represent the same
sample-based four-channel signal. In some cases one representation may be
more useful than the other. See “Sample-Based Multichannel Signals” on
page 3-11 for more about sample-based signals.
3-44
Constructing Signals
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
3-45
3 Working with Signals
frame-based signals using the Buffer block in the Buffers library (in Signal
Management).
sample 1 1 1 1 1
sample 2 2 2 2 2
sample 3 3 3 3 3 1 1 1 1
2 2 2 2
sample 4 4 4 4 4
3 3 3 3
sample 5 5 5 5 5 4 4 4 4
5 5 5 5
sample 6 6 6 6 6 6 6 6 6
3-46
Constructing Signals
1 –1
2 –2
3 –3
4 –4 1 –1 5
2 –2 5
3 –3 5
5 4 –4 5
5
5
5
• “Creating Signals Using the Signal From Workspace Block” on page 3-38
• “Importing a Multichannel Frame-Based Signal” on page 3-68
3-47
3 Working with Signals
T fo = ( M o – L )T si
where Mo is the Output buffer size (per channel), and L is the Buffer
overlap.
As a result, the new output sample period, Tso, is
( M o – L )T si
T so = -------------------------------
Mo
Clearly, this is equal to the input sample period only when the Buffer overlap
is zero. See “Converting Sample Rates and Frame Rates” on page 3-20 for more
information about rate conversions.
The following sections provide examples of buffering, and explore related
buffering issues:
3-48
Constructing Signals
1 –1
[4 -4] [3 -3] [2 -2] [1 -1] 2 –2
3 –3
t=3 t=2 t=1 t=0 4 –4
• “Creating Signals Using the Signal From Workspace Block” on page 3-38
3-49
3 Working with Signals
Overlapping Buffers. In some cases it is useful to work with data that represents
overlapping sections of an original sample-based or frame-based signal. In
estimating the power spectrum of a signal, for example, it is often desirable to
compute the FFT of overlapping sections of data. Overlapping buffers are also
needed in computing statistics on a sliding window, or for adaptive filtering.
The Buffer overlap parameter of the Buffer block specifies the number of
overlap points, L.
In the overlap case (L > 0), the frame period for the output is (Mo-L)∗Tsi, where
Tsi is the input sample period and Mo is the Buffer size.
Note Set the Buffer overlap parameter to a negative value to achieve output
frame rates slower than in the nonoverlapping case. The output frame period
is still Tsi∗(Mo-L), but now with L < 0. Only the Mo newest inputs are included
in the output buffer; the previous L inputs are discarded.
3-50
Constructing Signals
ch2 ch3
ch1 ch4
Sample-based input,
t=5 6 1 5 –6 sample period = Tsi
Tsi = 1
t=4 5 1 5 –5
Frame-based output ,
t=3 4 0 5 –4 frame period = (Mo-L)∗Tsi
first
t=2 3 0 5 –3
first sample-based frame-based
t=1 2 1 5 –2 input output
ch1
ch2
ch3
ch4
ch1
ch2
ch3
ch4
ch1
ch2
ch3
ch4
t=0 1 1 5 –1
4 0 5 –4 2 1 5 –2 0 0 0 0 0000
5 1 5 –5 3 0 5 –3 1 1 5 –1 0000
6 1 5 –6 4 0 5 –4 2 1 5 –2 0000
To build the model, define the following variable in the MATLAB workspace.
A = [1 1 5 -1;2 1 5 -2;3 0 5 -3;4 0 5 -4;5 1 5 -5;6 1 5 -6];
3-51
3 Working with Signals
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
5 1 1 1
6 1 2 1 51 30 11 00 00 00
7 0 3 0 61 40 21 00 00 00
8 0 4 0 70 51 30 11 00 00
t=4 t=0 (Mo=3, L=1) t=10 t=8 t=6 t=4 t=2 t=0
To build the model, define the following variable in the MATLAB workspace.
A = [1 1;2 1;3 0;4 0;5 1;6 1;7 0;8 0];
3-52
Constructing Signals
Buffering Delay and Initial Conditions. In both of the previous buffering examples
the input signal is delayed by a certain number of samples. In “Example:
Buffering Sample-Based Signals with Overlap” the delay is four samples. In
“Example: Buffering Frame-Based Signals with Overlap” the delay is eight
samples. The initial output samples adopt the value specified for the Initial
condition parameter, which is zero in both examples above.
In fact, under most conditions the Buffer and Unbuffer blocks have some
amount of latency. This latency depends on both the block parameter settings
and Simulink’s tasking mode. You can use the rebuffer_delay function to
determine the length of the block’s latency for any combination of frame size
and overlap.
The syntax rebuffer_delay(f,n,m) returns the delay (in samples) introduced
by the buffering and unbuffering blocks in multitasking operations, where f is
the input frame size, n is the Buffer size parameter setting, and m is the Buffer
overlap parameter setting.
For example, if you had run the frame-based example model in multitasking
mode, you could compute the latency by entering the following command at the
MATLAB command line.
d = rebuffer_delay(4,3,1)
d =
8
This agrees with the block’s output in that example. See “Delay and Latency”
on page 3-85 and the “Latency” section on each block reference page for more
information.
3-53
3 Working with Signals
Deconstructing Signals
Multichannel signals, represented by matrices in Simulink, are frequently
used in DSP models for efficiency and compactness. An M-by-N sample-based
multichannel signal represents M*N independent signals (one sample from
each), whereas an M-by-N frame-based multichannel signal represents N
independent channels (M consecutive samples from each). See “Multichannel
Signals” on page 3-11 for more information about the matrix format.
Even though most of the DSP blocks can process multichannel signals, you may
sometimes need to access just one channel or a particular range of samples in
a multichannel signal. There are a variety of ways to deconstruct multichannel
signals, the most common of which are explained in the following sections:
3-54
Deconstructing Signals
in the Indexing library (in Signal Management). Any subset of rows or columns
can be selected for propagation to a given output port.
• Selector (Simulink)
• Submatrix
3-55
3 Working with Signals
• Variable Selector
The next section provides an example of using the Submatrix block to extract
a portion of a multichannel sample-based signal. The Submatrix block is the
most versatile of the above blocks in that it allows you to make completely
arbitrary channel selections.
3-56
Deconstructing Signals
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
3-57
3 Working with Signals
sample 6 6 6 6 6
sample 5 5 5 5 5
1 1 1 1 sample 4 4 4 4 4
2 2 2 2
sample 3 3 3 3 3
3 3 3 3
4 4 4 4 sample 2 2 2 2 2
5 5 5 5
6 6 6 6 sample 1 1 1 1 1
The final section explains how to reorder the channels in a frame-based signal
without splitting the channels apart:
• “Reordering Channels in a Frame-Based Multichannel Signal” on page 3-61
3-58
Deconstructing Signals
1 5
2 5
3 5
1 –1 5 4 5
2 –2 5
3 –3 5
–1
4 –4 5
–2
–3
–4
• “Creating Signals Using the Signal From Workspace Block” on page 3-38
• “Importing a Multichannel Frame-Based Signal” on page 3-68
3-59
3 Working with Signals
T so = T fi ⁄ M i
The Unbuffer block always preserves the signal’s sample period (Tso = Tsi). See
“Converting Sample Rates and Frame Rates” on page 3-20 for more
information about rate conversions.
1 –1
2 –2 [4 -4] [3 -3] [2 -2] [1 -1]
3 –3
4 –4 t=7 t=6 t=5 t=4
3-60
Deconstructing Signals
Note The Unbuffer block generates initial conditions (not shown in the figure
above) with the value specified by the Initial conditions parameter. See the
Unbuffer reference page for information about the number of initial conditions
that appear in the output.
3-61
3 Working with Signals
Importing Signals
Although a number of signal generation blocks are available in Simulink and
the DSP Blockset, it is very common to import custom signals from the
MATLAB workspace as well. The following sections explain how to do this:
3-62
Importing Signals
sample 6 6 6 6 6
sample 5 5 5 5 5
1 1 1 1 sample 4 4 4 4 4
2 2 2 2
sample 3 3 3 3 3
3 3 3 3
4 4 4 4 sample 2 2 2 2 2
5 5 5 5
6 6 6 6 sample 1 1 1 1 1
As the figure above suggests, the output of the Signal From Workspace block
can only be a valid sample-based signal (having N independent channels) if the
M-by-N workspace matrix A in fact represents N independent channels, each
3-63
3 Working with Signals
Example: Importing a Sample-Based Vector Signal. In the model below, the Signal
From Workspace creates a three-channel sample-based signal with the
following data:
[4 -4 5] [3 -3 5] [2 -2 5] [1 -1 5]
To create the model, define the following variables at the MATLAB command
line
A = [1:100;-1:-1:-100]'; % 100-by-2 matrix
B = 5*ones(100,1); % 100-by-1 column vector
• Signal = [A B]
• Sample time = 1
• Samples per frame = 1
3-64
Importing Signals
The Sample time setting of 1 yields a sample-based output with sample period
of 1 second. The Form output after final data value parameter setting
specifies that all outputs after the third are zero.
3-65
3 Working with Signals
4 4 4 4
4 4 4 4
4 4 2 2
3 3 3 3
4 4 2 2
3 3 3 3
5 5 5 5 4 4 2
2
3 23 2
5 4 2 4 2 4 2 4 4 4 2 22 2 2 2
3 3 3 2 2
5 4 2 2 23 2 23 2 3 2 2 2 2
2 2 2 2 sample 4 3 3 2 2
4 3 2 22 2 22 2 2 2 2 2 2
5 2
3 2 1 2 1 2 1 2 1 3 3 2 21 1 1 1
5 4 2 2 22 2 22 2 2 2 2 2 2
3 2 1 2 1 2 1 2 1 sample 3 1 1 1 1
5 4 2 2 22 2 22 2 2 2 2 2 2
2 1 2 1 2 1 2 1 1 1 1 1
4 3 2 2 2 2 2 2 2 2 2 2
3 2 21 2 21 2 1
2 2 1 1 1 1 1
sample 2
2 1 2 1 2 1 2 1 1 1 1 1
1 1 1 1 1 1 1 1
sample 1
As the figure above suggests, the output of the Signal From Workspace block
can only be a valid sample-based signal (having M∗N independent channels) if
the M-by-N-by-P workspace array A in fact represents M∗N independent
channels, each having P samples. In other words, the workspace array must be
oriented to have time running along its third (P) dimension.
When the block has output all of the pages available in the specified array, it
can start again at the beginning of the array, or simply repeat the final page
(or generate zero-matrices) until the end of the simulation. This behavior is
controlled by the Form output after final data value by parameter. See the
Signal From Workspace reference page for more information.
The following example illustrates how the Signal From Workspace block can be
used to import a sample-based matrix signal into a model.
Example: Importing a Sample-Based Matrix Signal. In the model below, the Signal
From Workspace imports a four-channel sample-based signal with the
following data:
3-66
Importing Signals
• Channel 3: 0, 0, 0, 0, 0,...
• Channel 4: 5, 5, 5,..., 0, 0, 0,...
4 –4 3 –3 2 –2 1 –1
0 5 0 5 0 5 0 5
To create the model, define the following variables at the MATLAB command
line.
sig1 = reshape(1:100,[1 1 100]) % 1-by-1-by-100 array
sig2 = reshape(-1:-1:-100,[1 1 100]) % 1-by-1-by-100 array
sig3 = zeros(1,1,100) % 1-by-1-by-100 array
sig4 = 5*ones(1,1,100) % 1-by-1-by-100 array
sig12 = cat(2,sig1,sig2) % 1-by-2-by-100 array
sig34 = cat(2,sig3,sig4) % 1-by-2-by-100 array
• Signal = A
• Sample time = 1
• Samples per frame = 1
• Form output after final data value = Setting to zero
The Sample time and Samples per frame settings of 1 yield a sample-based
output with sample period of 1 second. Each of the four elements in the matrix
represents an independent channel. The Form output after final data value
parameter setting specifies that all outputs after the one-hundredth are zero.
The following two sections may also be of interest:
• “Creating Signals Using the Signal From Workspace Block” on page 3-38
3-67
3 Working with Signals
3-68
Importing Signals
Beginning with the first M rows of the matrix, the block releases M rows of the
matrix (i.e., one frame from each channel) to the output every M∗Ts seconds.
Therefore, if the Signal parameter specifies a W-by-N workspace matrix, the
output of the Signal From Workspace block is an M-by-N matrix representing
N channels.
The figure below illustrates this for a 6-by-4 workspace matrix, A, and a frame
size of 2.
sample 5 5 5 5 5
1 1 1 1
sample 6 6 6 6 6
2 2 2 2
3 3 3 3 sample 3 3 3 3 3
4 4 4 4 sample 4 4 4 4 4
5 5 5 5
sample 1 1 1 1 1
6 6 6 6
sample 2 2 2 2 2
ch1 ch2 ch3 ch4
ch1 ch2 ch3 ch4
As the figure above suggests, the output of the Signal From Workspace block
can only be a valid frame-based signal (having N independent channels) if the
W-by-N workspace matrix A in fact represents N independent channels. In
other words, the workspace matrix must be oriented so as to have the
independent channels as its columns.
When the block has output all of the rows available in the specified variable, it
can start again at the beginning of the signal, or simply repeat the final value
(or generate zeros) until the end of the simulation. This behavior is controlled
3-69
3 Working with Signals
by the Form output after final data value by parameter. See the Signal From
Workspace reference page for more information.
The following example illustrates how the Signal From Workspace block is
used to import a frame-based multichannel signal into a model.
Example: Importing a Frame-Based Signal. In the model below, the Signal From
Workspace creates a three-channel frame-based signal with the following data:
To create the model, define the following variables at the MATLAB command
line.
A = [1:100;-1:-1:-100]'; % 100-by-2 matrix
B = 5*ones(100,1); % 100-by-1 column vector
• Signal = [A B]
• Sample time = 1
• Samples per frame = 4
• Form output after final data value = Setting to zero
3-70
Importing Signals
The Sample time setting of 1 and Samples per frame setting of 4 yield a
frame-based output with sample period of 1 second and frame period of
4 seconds. The Form output after final data value parameter setting
specifies that all samples after the hundredth are zero.
3-71
3 Working with Signals
Exporting Signals
The To Workspace and Triggered To Workspace blocks are the primary
conduits for exporting signals from a Simulink model to the MATLAB
workspace. The following sections explain how to use these important blocks:
3-72
Exporting Signals
• “Creating Signals Using the Signal From Workspace Block” on page 3-38
• “Constructing Multichannel Sample-Based Signals” on page 3-42
3-73
3 Working with Signals
1 1 1 1
1 1 1 1
1 1 1 1
2 2 2 2
11 1 1
2 2 2 2
1 1 1 1 5 5 5 5
2 2 2 2
3 3 3 31 1 1 1 sample 1 5 4 2 4 2 4 2 4
2 2 2 2 3
3 3 2 2 5 4 2 2 23 2 23 2 3
2 2 2 2 3 2 2 2 2
3 3 2 2 5 4 2 2 22 2 22 2 2
4 4 4 42 2 2 2 2 1 2 1 1 2 1
3 3 2 2 sample 2 4 3 2 22 2 22
2
2 2
4 4 2 2 5 2
3 2 1 2 1 2 1 2 1
3 3 3 3 5 4 2 2 22 2 22 2 2
4 4 2 2 2 1 2 1 2 1 2 1
3 3 3 3 sample 3 4 3 2 2 2 2 2 2
4 4 2 2
3 2 21 2 21 2 1
2 2 1
4 4 4 4 2 1 2 1 2 1 2 1
4 4 4 4 sample 4 1 1 1 1
The workspace array always has time running along its third (P) dimension.
Samples are saved along the P dimension whether the input is a matrix, vector,
or scalar (single channel).
The following example illustrates how the To Workspace block can be used to
export a sample-based matrix signal to the MATLAB workspace.
3-74
Exporting Signals
4 –4 3 –3 2 –2 1 –1
0 5 0 5 0 5 0 5
To create the model, define the following variables at the MATLAB command
line.
sig1 = reshape(1:100,[1 1 100]) % 1-by-1-by-100 array
sig2 = reshape(-1:-1:-100,[1 1 100]) % 1-by-1-by-100 array
sig3 = zeros(1,1,100) % 1-by-1-by-100 array
sig4 = 5*ones(1,1,100) % 1-by-1-by-100 array
sig12 = cat(2,sig1,sig2) % 1-by-2-by-100 array
sig34 = cat(2,sig3,sig4) % 1-by-2-by-100 array
• Signal = A
• Sample time = 1
• Samples per frame = 1
• Form output after final data value = Setting to zero
Run the model, and look at output yout. The first four samples (pages) are
shown below.
3-75
3 Working with Signals
yout(:,:,1:4)
ans(:,:,1) =
1 -1
0 5
ans(:,:,2) =
2 -2
0 5
ans(:,:,3) =
3 -3
0 5
ans(:,:,4) =
4 -4
0 5
3-76
Exporting Signals
1 1 1 1 sample 1 1 1 1 1
2 2 2 2 sample 2 2 2 2 2
3 3 3 3
3 3 3 3 sample 3
4 4 4 4 sample 4 4 4 4 4
5 5 5 5
5 5 5 5 sample 5 6 6 6 6
6 6 6 6 sample 6
ch1 ch2 ch3 ch4
ch1 ch2 ch3 ch4
The workspace matrix always has time running along its first (P) dimension.
Samples are saved along the P dimension whether the input is a matrix, vector,
or scalar (single channel).
The following example illustrates how the To Workspace block can be used to
export a frame-based multichannel signal to the MATLAB workspace.
3-77
3 Working with Signals
To create the model, define the following variables at the MATLAB command
line.
A = [1:100;-1:-1:-100]'; % 100-by-2 matrix
B = 5*ones(100,1); % 100-by-1 column vector
• Signal = [A B]
• Sample time = 1
• Samples per frame = 4
• Form output after final data value = Setting to zero
The Sample time setting of 1 and Samples per frame setting of 4 yield a
frame-based output with sample period of 1 second and frame period of
4 seconds.
Specify the following parameter values in the To Workspace block:
Run the model, and look at output yout. The first 10 samples (rows) are shown.
yout =
1 -1 5
2 -2 5
3 -3 5
4 -4 5
5 -5 5
6 -6 5
7 -7 5
8 -8 5
9 -9 5
10 -10 5
3-78
Exporting Signals
• “Creating Signals Using the Signal From Workspace Block” on page 3-38
• “Constructing Multichannel Sample-Based Signals” on page 3-42
• To Wave Device
• To Wave File
The To Wave Device and To Wave File blocks are limited to one-channel (mono)
or two-channel (stereo) inputs, selectable in the Stereo check box. See the
reference pages for complete information.
The following demos may also be of interest:
3-79
3 Working with Signals
Viewing Signals
The following blocks in the DSP Sinks library are the key blocks for displaying
signals:
• Matrix Viewer
• Spectrum Scope
• Time Scope (Simulink Scope)
• Vector Scope
3-80
Viewing Signals
Specify the following parameter values in the Signal From Workspace block:
• Signal = mtlb
• Sample time = 1
• Samples per frame = 16
• Form output after final data value = Cyclic Repetition
Specify the following parameter values in the Digital Filter Design block:
Specify the following parameter values in the Scope properties pane of the
Vector Scope block:
When you run the model, the Vector Scope block plots two consecutive frames
of each channel at each update. You may want to set the Stop time in the
Simulation Parameters dialog box to inf to allow the simulation to run
longer. The following section provides a few tips for improving the display.
Improving the Appearance of the Display. You may want to alter the appearance of
the scope display by making some of the following adjustments from the
right-click popup menu. To access the right-click menu, click with the right
mouse button anywhere in the plot region. These options are also available
from the Axes and Channels menus that are visible at the top of the window
when Compact display is not selected. You can make all of these changes
while the simulation is running:
• Select Autoscale at any time from the right-click menu to rescale the vertical
axis to best fit the most recently displayed data.
3-81
3 Working with Signals
• Select Compact display from the right-click menu to allow the scope to use
all the available space in the window.
• Select CH 1 from the right-click menu, and then select Marker and “o” from
the submenus, to mark the data points on the channel 1 signal with circles.
• Select CH 1 from the right-click menu, and then select Color and Blue from
the submenus, to code the channel 1 signal with the color blue.
• Select CH 2 from the right-click menu, and then select Marker and
Diamond from the submenus, to mark the data points on the channel 2
signal with diamonds.
Specify the following parameter values in the Signal From Workspace block:
• Signal = mtlb
• Sample time = 1
• Samples per frame = 16
• Form output after final data value = Cyclic Repetition
Specify the following parameter values in the Digital Filter Design block:
3-82
Viewing Signals
Specify the following parameter values in the Scope properties pane of the
Spectrum Scope block:
• Buffer input =
• Buffer size = 128
• Buffer overlap = 64
• Specify FFT length =
• Number of spectral averages = 2
With these settings, the Spectrum Scope block buffers each input channel to a
new frame size of 128 (from the original frame size of 16) with an overlap of 64
samples between consecutive frames. Because Specify FFT length is not
selected, the frame size of 128 is used as the number of frequency points in the
FFT. This is the number of points plotted for each channel every time the scope
display is updated.
You may want to set the Stop time in the Simulation Parameters dialog box
to inf to allow the simulation to run longer. See “Improving the Appearance of
the Display” on page 3-81 for some tips on improving the scope display.
Displaying Matrices
The Matrix Viewer block provides general matrix display capabilities that can
be used with all matrix signals (frame-based and sample-based).
3-83
3 Working with Signals
To build the model, specify the following parameter values in the Sine Wave
block:
• Amplitude = 1
• Frequency = 100
• Phase offset = 0:pi/64:pi
3-84
Delay and Latency
The following sections explain how you can configure Simulink to minimize
both varieties of delay and increase simulation performance.
Computational Delay
The computational delay of a block or subsystem is related to the number of
operations involved in executing that component. For example, an FFT block
operating on a 256-sample input requires Simulink to perform a certain
number of multiplications for each input frame. The actual amount of time that
these operations consume (as measured in a benchmark test, for example)
depends heavily on the performance of both the computer hardware and
underlying software layers, such as MATLAB and the operating system.
Computational delay for a particular model therefore typically varies from one
computer platform to another.
The simulation time represented on a model’s status bar (which can be
accessed via Simulink’s Digital Clock block) does not provide any information
about computational delay. For example, according to the Simulink timer, the
FFT mentioned above executes instantaneously, with no delay whatsoever. An
input to the FFT block at simulation time t=25.0 is processed and output at
time t=25.0, regardless of the number of operations performed by the FFT
algorithm. The Simulink timer reflects only algorithmic delay (described
below), not computational delay.
The next section discussed methods of reducing computational delay.
3-85
3 Working with Signals
Algorithmic Delay
Algorithmic delay is delay that is intrinsic to the algorithm of a block or
subsystem, and is independent of CPU speed. In Chapter 5, “DSP Block
Reference,” and elsewhere in this guide, the algorithmic delay of a block is
referred to simply as the block’s delay. It is generally expressed in terms of the
number of samples by which a block’s output lags behind the corresponding
3-86
Delay and Latency
input. This delay is directly related to the time elapsed on the Simulink timer
during that block’s execution.
The algorithmic delay of a particular block may depend on both the block’s
parameter settings and the general Simulink settings. To simplify matters, it
is helpful to categorize a block’s delay using the following levels:
The following sections explain the different levels of delay, and how the
simulation and parameter settings can affect the level of delay that a
particular block experiences.
Example: Zero Algorithmic Delay. Create the model below to observe the operation
of the zero-delay Normalization block.
3-87
3 Working with Signals
Use the default settings for the Normalization, Digital Clock, Mux, and To
Workspace blocks, and adjust the Signal From Workspace block parameters as
follows:
• Signal = 1:100
• Sample time = 1/4
• Samples per frame = 4
Select Sample-based from the Output signal menu in the Frame Status
Conversion block.
Note that the current value of the Simulink timer (from the Digital Clock block)
is prepended to each output frame. The frame-based signal is converted to a
sample-based signal by the Frame Status Conversion so that the output in the
command window will be more easily readable.
In the example, the Signal From Workspace block generates a new frame
containing four samples once every second (Tfo = ¼∗4). The first few output
frames are shown below.
(t=0) [ 1 2 3 4]'
(t=1) [ 5 6 7 8]'
(t=2) [ 9 10 11 12]'
(t=3) [13 14 15 16]'
(t=4) [17 18 19 20]'
When you run the simulation, the normalized output, yout, is saved in a
workspace array. To convert the array to an easier-to-read matrix format, type
squeeze(yout)'
The first few samples of the result, ans, are shown below.
ans =
3-88
Delay and Latency
The first column of ans is the Simulink time provided by the Digital Clock
block. You can see that the squared 2-norm of the first input,
[1 2 3 4]' ./ sum([1 2 3 4]'.^2)
appears in the first row of the output (at time t=0), the same time step that the
input was received by the block. This indicates that the Normalization block
has zero algorithmic delay.
Zero Algorithmic Delay and Algebraic Loops. When several blocks with zero
algorithmic delay are connected in a feedback loop, Simulink may report an
algebraic loop error and performance may generally suffer. You can prevent
algebraic loops by injecting at least one sample of delay into a feedback loop (for
example, by including an Integer Delay block with Delay > 0). See the
Simulink documentation for more information about algebraic loops.
The input to the Delay port of the block specifies the number of sample periods
that should elapse before an input to the In port is released to the output. This
value represents the block’s algorithmic delay. For example, if the input to the
Delay port is a constant 3, and the sample period at both ports is 1, then a
sample that arrives at the block’s In port at time t=0 is released to the output
at time t=3.
Example: Basic Algorithmic Delay. Create the model shown below to observe the
operation of a block with basic delay.
3-89
3 Working with Signals
Use the default settings for the Digital Clock, Mux, and To Workspace blocks,
and adjust the Signal From Workspace block’s parameters to the values below:
• Signal = 1:100
• Sample time = 1
• Samples per frame = 1
Set the DSP Constant block’s Constant value parameter to 3, and set the
Variable Integer Delay block’s Initial conditions parameter to -1.
Now run the simulation and look at the output, yout. The first few samples are
shown below.
yout =
0 -1
1 -1
2 -1
3 1
4 2
5 3
time
The first column of yout is the Simulink time provided by the Digital Clock
block, and the second column is the delayed input. As expected, the input to the
block at t=0 is delayed three samples, and appears as the fourth output sample,
at t=3. You can also see that the first three outputs from the Variable Integer
Delay block inherit the value of the block’s Initial conditions parameter, -1.
This period of time, from the start of the simulation until the first input is
propagated to the output, is sometimes called the initial delay of the block.
Many blocks in the DSP Blockset have some degree of fixed or adjustable
algorithmic delay. These include any blocks whose algorithms rely on delay or
storage elements, such as filters or buffers. Often (but not always), such blocks
provide an Initial conditions parameter that allows you to specify the output
values generated by the block during the initial delay. In other cases, the initial
conditions are internally fixed at 0.
Consult “DSP Block Reference” on page 5-1 for the delay characteristics of
particular DSP blocks.
3-90
Delay and Latency
• Single-tasking
• Multitasking
Block Rate Type. A block is called single-rate when all of its input and output
ports operate at the same frame rate (as indicated by identical Probe block
measurements or sample time color coding on the input and output lines). A
3-91
3 Working with Signals
block is called multirate when at least one input or output port has a different
frame rate than the others.
Many blocks are permanently single-rate, which means that all input and
output ports always have the same frame rate. For other blocks, the block
parameter settings determine whether the block is single-rate or multirate.
Only multirate blocks are subject to tasking latency.
Note Simulink may report an algebraic loop error if it detects a feedback loop
composed entirely of multirate blocks. To break such an algebraic loop, insert
a single-rate block with nonzero delay, such as a Unit Delay block. For more
information about algebraic loops, see “Algebraic Loops” in the Simulink
documentation.
Model Rate Type. When all ports of all blocks in a model operate at a single frame
rate, the model is called single-rate. When the model contains blocks with
differing frame rates, or at least one multirate block, the model is called
multirate. Note that Simulink prevents a single-rate model from running in
multitasking mode by generating an error.
3-92
Delay and Latency
• Type = Fixed-step
• Mode = MultiTasking
Use the default settings for the Mux and To Workspace blocks. Adjust the other
blocks’ parameter settings as follows:
• Set the Signal From Workspace block’s parameters to the values below.
- Signal = 1:100
- Sample time = 1/4
- Samples per frame = 4
• Set the Upsample block’s parameters to the values below. The Maintain
input frame size setting of the Frame-based mode parameter makes the
block (and model) multirate since the input and output frame rates will not
be equal.
- Upsample factor = 4
- Sample offset = 0
- Initial condition = -1
- Frame-based mode = Maintain input frame size
• Set the Sample time parameter of the Digital Clock block to 0.25 to match
the sample period of the Upsample block’s output.
3-93
3 Working with Signals
• Set the Output signal parameter of the Frame Status Conversion block to
Sample-based.
Notice that the current value of the Simulink timer (from the Digital Clock
block) is prepended to each output frame. The frame-based signal is converted
to a sample-based signal by the Frame Status Conversion block so that the
output in the command window will be easily readable.
In the example, the Signal From Workspace block generates a new frame
containing four samples once every second (Tfo = ¼∗4). The first few output
frames are shown below.
(t=0) [ 1 2 3 4]
(t=1) [ 5 6 7 8]
(t=2) [ 9 10 11 12]
(t=3) [13 14 15 16]
(t=4) [17 18 19 20]
The Upsample block upsamples the input by a factor of 4, inserting three zeros
between each input sample. The change in rates is confirmed by the Probe
blocks in the model, which show a decrease in the frame period from Tfi = 1 to
Tfo = 0.25.
Question: When does the first input sample appear in the output?
The “Latency and Initial Conditions” section of the reference page for the
Upsample block indicates that when Simulink is in multitasking mode, the
first sample of the block’s frame-based input appears in the output as
sample MiL+D+1, where Mi is the input frame size, L is the Upsample factor,
and D is the Sample offset. This formula therefore predicts that the first input
in this example should appear as output sample 17 (i.e., 4∗4+0+1).
To verify this, look at the output from the simulation, saved in the workspace
array yout. To convert the array to a easier-to-read matrix format, type
squeeze(yout)'
The first few samples of the result, ans, are shown below.
3-94
Delay and Latency
ans =
The first column of yout is the Simulink time provided by the Digital Clock
block. The four values to the right of each time are the values in the output
frame at that time. You can see that the first sample in each of the first four
output frames inherits the value of the block’s Initial conditions parameter.
As a result of the tasking latency, the first input value appears only as the first
sample of the 5th output frame (at t=1), which is sample 17.
Example: Zero Tasking Latency. Now try the previous example in Simulink’s
single-tasking mode. The model and all of the block parameter settings are the
same.
• Type = Fixed-step
• Mode = SingleTasking
3-95
3 Working with Signals
The “Latency and Initial Conditions” section of the reference page for
Upsample indicates that the block has zero latency for all multirate operations
in Simulink’s single-tasking mode. To verify this, look at the output from the
simulation, squeeze(yout)'. The first few samples are shown below.
ans =
The first column of yout is the Simulink time provided by the Digital Clock
block. The four values to the right of each time are the values in the output
frame at that time.
You can see that the first input value appears as the first sample of the first
output frame (at t=0), as expected for zero-latency operation. Running this
model under Simulink’s single-tasking mode therefore eliminates the
17-sample delay that the model experiences under Simulink’s multitasking
mode (for the particular parameter settings in the example).
3-96
4
DSP Operations
Overview . . . . . . . . . . . . . . . . . . . . . 4-2
Filters . . . . . . . . . . . . . . . . . . . . . . . 4-3
Transforms . . . . . . . . . . . . . . . . . . . . 4-10
Statistics . . . . . . . . . . . . . . . . . . . . . 4-21
DSP Blockset Demos Overview . . . . . . . . . . . 4-24
4 DSP Operations
Overview
This chapter discusses some basic DSP operations, and how they can be
implemented using the DSP Blockset. The following topics are covered:
• “Filters”
• “Transforms”
• “Power Spectrum Estimation”
• “Linear Algebra”
• “Statistics”
The discussion and examples included in these sections should help you
become familiar with the standard operations involved in simulating DSP
models. See Chapter 3, “Working with Signals” for more basic information on
sample rates, matrices, and frame-based processing.
A final section, “DSP Blockset Demos Overview” on page 4-24, provides a look
at the demonstration models that accompany the DSP Blockset.
4-2
Filters
Filters
Filtering is one of the most important operations in signal processing, and is
supported in the DSP Blockset with three libraries of filtering blocks. The
following sections present a brief overview of these libraries:
Adaptive Filters
Adaptive filters are filters whose transfer function coefficients or taps change
over time in response to an external error signal. The Adaptive Filters library
contains the following blocks:
Open the demos by clicking on the demo names above in the MATLAB Help
browser. Alternatively, open the demos by typing the demo name (provided in
parentheses above) at the MATLAB command line.
4-3
4 DSP Operations
Filter Designs
Filter Designs library blocks apply specified filters to an input signal and
output the result. Depending on the block, you specify a filter with its filter
coefficients, or by setting filter specification parameters. The following table
categorizes Filter Designs library blocks by the types of filters they implement.
Digital Filter Design Implements a variety of digital FIR and IIR filters. You specify the
filter using the Filter Design and Analysis Tool (FDATool)
graphical user interface.
Biquadratic Filter and These blocks are included in the library for backward compatibility
Direct-Form II Transpose of models using blocks from pervious DSP Blockset versions. To
Filter implement biquadratic and direct-form II transpose filters in new
models, use the Digital Filter Design block.
Digital Time-Varying Time-Domain Filter Blocks
Overlap-Add FFT Filter Implements frequency-domain filters with the overlap-add method.
4-4
Filters
For details about a particular block, consult its reference page. Also see the rest
of this section, which discuss the following topics in detail:
4-5
4 DSP Operations
The FDATool GUI Opened from the Digital Filter Design Block
4-6
Filters
where y(k) and u(k) are, respectively, the output and input at the current time
step, y(k-1) and u(k-1) are the output and input at the previous time step, and
so on. The values b1, b2, ..., bm, and a2, ..., an are the filter coefficients, or taps.
Every realizable filter is therefore fundamentally a collection of
multiplications, additions, and delays. The order in which these assorted
operations are implemented in practice determines the filter structure (also
known as the filter realization, architecture, or implementation).
Implementations may differ from each other in terms of speed, memory
requirements, delay, and quantization error. See “Linear System Models” in
the Signal Processing Toolbox documentation for more information about
common filter structures.
The Filter Designs library provides a number of blocks for designing filters
with various filter structures:
• Digital Filter Design
• Filter Realization Wizard
• Overlap-Add FFT Filter
• Overlap-Save FFT Filter
• Time-Varying Direct-Form II Transpose Filter
• Time-Varying Lattice Filter
See the following demos, which make use of many of the filter structure blocks:
Open the demos by clicking on the demo names above in the MATLAB Help
browser. Alternatively, open the demos by typing the demo name (provided in
parentheses above) at the MATLAB command line.
4-7
4 DSP Operations
you specify a filter order. The other available parameters depend on the filter
type and band configuration, as shown in the table below.
where:
Ωp = passband edge frequency
Ωp1 = lower passband edge frequency
Ωp2 = upper cutoff frequency
Ωs = stopband edge frequency
Ωs1 = lower stopband edge frequency
Ωs2 = upper stopband edge frequency
Rp = passband ripple in decibels
Rs = stopband attenuation in decibels
For all of the analog filter designs, frequency parameters are in units of radians
per second.
The block uses a state-space filter representation, and applies the filter using
the State-Space block in the Simulink Continuous library. All of the design
methods use Signal Processing Toolbox functions to design the filter:
The Analog Filter Design block is built on the filter design capabilities of the
Signal Processing Toolbox. For more information on the filter design
algorithms, see the Filter Designs section of the Signal Processing Toolbox
documentation.
4-8
Filters
Note The Analog Filter Design block does not work with Simulink’s discrete
solver, which is enabled when the discrete option is selected in the Solver
panel of the Simulation Parameters dialog box. Select one of the continuous
solvers (e.g., ode4) instead.
Multirate Filters
Multirate filters are those which alter the sample rate of the input signal
during the filtering process. Such filters are useful in both rate conversion and
filter bank applications.
The Multirate Filters library provides a number of blocks for multirate
applications:
The DSP Blockset additionally provides a number of demos that make use of
the multirate filter blocks:
• Denoising (dspwdnois)
• Multistage Multirate Filtering Suite (dspmrf_menu)
• Interpolation of a Sinusoidal Signal (dspintrp)
• Sample Rate Conversion (dspsrcnv)
• Sigma-Delta A/D Converter (dspsdadc)
• Three-Channel Wavelet Transmultiplexer (dspwvtrnsmx)
• Wavelet Perfect Reconstruction Filter Bank (dspwpr1)
• Wavelet Reconstruction (dspwlet)
4-9
4 DSP Operations
Transforms
The Transforms library provides blocks for a number of transforms that are of
particular importance in DSP applications:
• Analytic Signal
• Complex Cepstrum
• DCT
• FFT
• IDCT
• IFFT
• Real Cepstrum
First and foremost among these are of course the FFT and IFFT blocks, which
respectively implement the fast Fourier transform and its inverse. These
blocks are discussed further in the next section.
The first example loosely follows the example in the “Discrete Fourier
Transform” section of the Signal Processing Toolbox documentation, where you
can also find additional background information on these transform
operations.
4-10
Transforms
The scope shows the two peaks at 0.015 and 0.04 kHz, as expected.
4-11
4 DSP Operations
To build the model, make the following parameter settings (leave unlisted
parameters in their default settings):
4-12
Transforms
The flat line on the scope suggests that there is no difference between the two
signals, and that the IFFT block has perfectly reconstructed the original
time-domain signal from the frequency-domain input.
More precisely, the two signals are identical to within round-off error, which
can be seen by selecting Autoscale from the right-click menu on the scope. The
enlarged trace shows that the differences between the two signals are on the
order of 10-15.
4-13
4 DSP Operations
4-14
Power Spectrum Estimation
4-15
4 DSP Operations
Linear Algebra
The Matrices and Linear Algebra library provides three large sublibraries
containing blocks for linear algebra:
A third library, Matrix Operations, provides other essential blocks for working
with matrices. See “Multichannel Signals” on page 3-11 for more information
about matrix signals.
The following sections provide examples to help you get started with the linear
algebra blocks:
• Autocorrelation LPC
• Cholesky Solver
• Forward Substitution
• LDL Solver
• Levinson-Durbin
• LU Solver
• QR Solver
• SVD Solver
Some of the blocks offer particular strengths for certain classes of problems.
For example, the Cholesky Solver block is particularly adapted for a square
Hermitian positive definite matrix A, whereas the Backward Substitution
block is particularly suited for an upper triangular matrix A.
4-16
Linear Algebra
Example: LU Solver
In the model below, the LU Solver block solves the equation Ax = b, where
1 –2 3 1
A = 4 0 6 b = –2
2 –1 3 –1
• In the DSP Constant block, set Constant value = [1 -2 3;4 0 6;2 -1 3].
• In the DSP Constant1 block, set Constant value = [1 -2 -1]'.
You can verify the solution by using the Matrix Multiply block to perform the
multiplication Ax, as shown in the model below.
Factoring Matrices
The Matrix Factorizations library provides the following blocks for factoring
various kinds of matrices:
• Cholesky Factorization
• LDL Factorization
• LU Factorization
4-17
4 DSP Operations
• QR Factorization
• Singular Value Decomposition
Some of the blocks offer particular strengths for certain classes of problems.
For example, the Cholesky Factorization block is particularly suited to
factoring a Hermitian positive definite matrix into triangular components,
whereas the QR Factorization is particularly suited to factoring a rectangular
matrix into unitary and upper triangular components.
Example: LU Factorization
In the model below, the LU Factorization block factors a matrix Ap into upper
and lower triangular submatrices U and L, where Ap is row equivalent to input
matrix A, where
1 –2 3
A = 4 0 6
2 –1 3
To build the model, in the DSP Constant block, set the Constant value
parameter to [1 -2 3;4 0 6;2 -1 3].
The lower output of the LU Factorization, P, is the permutation index vector,
which indicates that the factored matrix Ap is generated from A by
interchanging the first and second rows.
4 0 6
Ap = 1 –2 3
2 –1 3
4-18
Linear Algebra
4 0 6 1 0 0
U = 0 –2 1.5 L = 0.25 1 0
0 0 – 0.75 0.5 0.5 1
You can check that LU = Ap with the Matrix Multiply block, as shown in the
model below.
Inverting Matrices
The Matrix Inverses library provides the following blocks for inverting various
kinds of matrices:
• Cholesky Inverse
• LDL Inverse
• LU Inverse
• Pseudoinverse
Example: LU Inverse
In the model below, the LU Inverse block computes the inverse of input
matrix A, where
1 –2 3
A = 4 0 6
2 –1 3
and then forms the product A-1A, which yields the identity matrix of order 3,
as expected.
4-19
4 DSP Operations
To build the model, in the DSP Constant block, set the Constant value
parameter to [1 -2 3;4 0 6;2 -1 3].
As shown above, the computed inverse is
– 1 – 0.5 2
–1
A = 0 0.5 –1
0.6667 0.5 – 1.333
4-20
Statistics
Statistics
The Statistics library provides fundamental statistical operations such as
minimum, maximum, mean, variance, and standard deviation. Most blocks in
the Statistics library support two types of operations:
• Basic operations
• Running operations
The blocks listed below toggle between basic and running modes using the
Running check box in the parameter dialog box:
• Histogram
• Mean
• RMS
• Standard Deviation
• Variance
An unchecked Running box means that the block is operating in basic mode,
while a checked Running box means that the block is operating in running
mode.
The Maximum and Minimum blocks are slightly different from the blocks
above, and provide a Mode parameter in the block dialog box to select the type
of operation. The Value and Index, Value, and Index options in the Mode
menu all specify basic operation, in each case enabling a different set of output
ports on the block. The Running option in the Mode menu selects running
operation.
The following sections explain how basic mode and running mode differ:
• “Basic Operations”
• “Running Operations”
The statsdem demo illustrates the operation of several blocks from the
Statistics library.
Basic Operations
A basic operation is one that processes each input independently of previous
and subsequent inputs. For example, in basic mode (with Value and Index
4-21
4 DSP Operations
selected, for example) the Maximum block finds the maximum value in each
column of the current input, and returns this result at the top output (Val).
Each consecutive Val output therefore has the same number of columns as the
input, but only one row. Furthermore, the values in a given output only depend
on the values in the corresponding input. The block repeats this operation for
each successive input.
This type of operation is exactly equivalent to the MATLAB command
val = max(u) % Equivalent MATLAB code
The Buffer block’s Buffer size (Mo) parameter determines the size of the
window. The Buffer overlap (L) parameter defines the “slide factor” for the
window. At each sample instant, the window slides by Mo-L points. The Buffer
overlap is often Mo-1 (the same as the Delay Line block), so that a new statistic
is computed for every new signal sample.
To build the model, make the following settings:
4-22
Statistics
Running Operations
A running operation is one that processes successive sample-based or
frame-based inputs, and computes a result that reflects both present and past
inputs. A reset port enables you to restart this tracking at any time. The
running statistic is computed for each input channel independently, so the
block’s output is the same size as the input.
For example, in running mode (Running selected from the Mode parameter)
the Maximum block outputs a record of the input’s maximum value over time.
The figure below illustrates how a Maximum block in running mode operates
on a frame-based 3-by-2 (two-channel) matrix input, u. The running maximum
is reset at t=2 by an impulse to the block’s optional Rst port.
In Rst Output
61 61
First
13 t=0 0 First output 63
input 39 69
–7 2 69
2 4 t=1 0 69
5 1 69
Simulation time
8 6 86
0 2 t=2 1 86 Reset
–1 5 86
–3 0 8 6
2 4 t=3 0 8 6
1 17 8 17
4-23
4 DSP Operations
at the MATLAB command line. In the Demos window that opens, expand the
Blocksets entry by double-clicking, and then click DSP to see the demos.
Explore all the demos to see how you can implement both basic and advanced
DSP algorithms with the DSP Blockset. You can also use the demos as a base
for building your own models. Simply select the section of the demo that you
want to build on and copy it into your own model.
The available demos are listed below by category.
4-24
DSP Blockset Demos Overview
• LPC analysis and synthesis: Uses the Levinson solver and Time-Varying
Lattice Filter for low-bandwidth transmission of speech.
• Waveform coding: This set of demos uses a variety of modulation methods to
code a waveform using one bit per message sample:
- ADPCM (Adaptive Differential Pulse Code Modulation)
- CVSD (Continuously Variable Slope Delta-modulation)
- LDM (Linear Delta Modulation)
- Comparison of LDM, CVSD, and ADPCM
Communications Demos
• SSB modulation: Demonstrates single sideband (SSB) modulation in
sample-based and frame-based modes.
• WWV digital receiver: WWV is the call sign of a US Government radio
station that transmits frequency reference standards and time code
information with a timing accuracy of 10 microseconds and a frequency
accuracy of 1 part in 100 billion. This demo simulates the transmission of a
WWV signal and demonstrates implementation of the subsequent receiver
and decoder blocks. The receiver design serves as a simple example of the use
of Simulink, DSP Blockset, Stateflow® and Real-Time Workshop.
Filtering Demos
• Multirate filtering suite: Uses FIR decimation blocks in multiple stages to
filter with very short bandwidths and low computational loads.
• FIR interpolation: Uses the FIR Interpolation block to demonstrate
interpolation of a delayed sine wave signal.
• Overlap add/save: Demonstrates filtering of a sinusoid using the
Overlap-Add and Overlap-Save FFT blocks.
• Sample rate conversion: Illustrates the efficiency of the FIR rate conversion
block by comparing the block with the equivalent process of separate
upsampling, FIR filtering, and downsampling.
4-25
4 DSP Operations
Queues Demo
• Demo uses a Queue block with a system of selection switches to illustrate
pushing and popping elements from a queue.
Wavelets Demos
• One-level PR filter bank: Uses the Dyadic Analysis and Dyadic Synthesis
blocks to implement a perfect reconstruction filter bank.
• Wavelet function: Uses a sequence of FIR interpolation blocks to reconstruct
a wavelet function from filter coefficients.
• Denoising: Uses Analysis and Synthesis blocks to remove noise from an
input signal.
• Wavelet transmultiplexer (WTM): Illustrates the perfect reconstruction
property of the discrete wavelet transform (DWT) by using a WTM to
reconstruct three independent combined signals transmitted over a single
communications link.
4-26
5
To learn the basic concepts behind building DSP models with Simulink, see
Chapter 2, “Simulink and the DSP Blockset.” To find out about using blocks
together for common DSP tasks, see Chapter 3, “Working with Signals.”
Section Description
“Supported The data types supported by the block. See the following
Data Types” section, “About Supported Data Types” for more
information.
5-2
Features of the Online DSP Block Reference
Correctly Defining Custom Data Types. Custom data types are user-defined data
types. You must define your custom data types by following the guidelines in
the Custom Data Types section in the “Implementing Block Features” section
of the “Writing S-Functions” Simulink documentation. If you do not follow the
Simulink guidelines for creating custom data types, the DSP Blockset blocks
will not support your custom data types.
5-3
5 DSP Block Reference
5-4
Features of the Online DSP Block Reference
Open the following model by clicking here in the MATLAB Help browser.
5-5
5 DSP Block Reference
Note All DSP Blockset blocks support generic real-time (GRT) code
generation.
Correlation Counter
dB Conversion dB Gain
5-6
Blocks Supporting Code Generation
Display Downsample
Mean Median
5-7
5 DSP Block Reference
Toeplitz Transpose
Unwrap Upsample
5-8
Block Library List
• DSP Sinks
• DSP Sources
• Estimation
- Estimation: Linear Prediction
- Estimation: Parametric Estimation
- Estimation: Power Spectrum Estimation
• Filtering
- Filtering: Adaptive Filters
- Filtering: Filter Designs
- Filtering: Multirate Filter
• Math Functions
- Matrices and Linear Algebra
• Linear System Solvers
• Matrix Factorizations
• Matrix Inverses
• Matrix Operations
- Math Functions: Math Operations
- Math Functions: Polynomial Functions
• Quantizers
• Signal Management
5-9
5 DSP Block Reference
Use the Simulink Library Browser to access the blockset directly through the
above hierarchical library list.
DSP Sinks
DSP Sources
5-10
Block Library List
Autocorrelation LPC
5-11
5 DSP Block Reference
FIR Interpolation
5-12
Block Library List
LU Factorization
5-13
5 DSP Block Reference
Matrix Product
dB Conversion Difference
Polynomial Evaluation
5-14
Block Library List
Quantizers
Uniform Decoder
Buffer Stack
Queue Unbuffer
Flip Submatrix
5-15
5 DSP Block Reference
Signal Operations
Convolution Unwrap
Downsample Upsample
Statistics
Autocorrelation Median
Correlation Minimum
Detrend RMS
Histogram Sort
Mean Variance
5-16
Block Library List
Transforms
FFT
5-17
Analog Filter Design
Description The Analog Filter Design block designs and implements a Butterworth,
Chebyshev type I, Chebyshev type II, or elliptic filter in a highpass, lowpass,
bandpass, or bandstop configuration.
The input must be a sample-based scalar signal.
The design and band configuration of the filter are selected from the Design
method and Filter type pop-up menus in the dialog box. For each combination
of design method and band configuration, an appropriate set of secondary
parameters is displayed.
The table below lists the available parameters for each design/band
combination. For lowpass and highpass band configurations, these parameters
include the passband edge frequency Ωp, the stopband edge frequency Ωs, the
passband ripple Rp, and the stopband attenuation Rs. For bandpass and
bandstop configurations, the parameters include the lower and upper
passband edge frequencies, Ωp1 and Ωp2, the lower and upper stopband edge
frequencies, Ωs1 and Ωs2, the passband ripple Rp, and the stopband
5-23
Analog Filter Design
attenuation Rs. Frequency values are in rad/s, and ripple and attenuation
values are in dB.
The analog filters are designed using the Signal Processing Toolbox’s filter
design commands buttap, cheb1ap, cheb2ap, and ellipap, and are
implemented in state-space form. Filters of order 8 or less are implemented in
controller canonical form for improved efficiency.
Dialog Box
The parameters displayed in the dialog box vary for different design/band
combinations. Only a portion of the parameters listed below are visible in the
dialog box at any one time.
Design method
The filter design method: Butterworth, Chebyshev type I, Chebyshev
type II, or Elliptic. Tunable.
5-24
Analog Filter Design
Filter type
The type of filter to design: Lowpass, Highpass, Bandpass, or Bandstop.
Tunable.
Filter order
The order of the filter, for lowpass and highpass configurations. For
bandpass and bandstop configurations, the order of the final filter is twice
this value.
Passband edge frequency
The passband edge frequency, in rad/s, for the highpass and lowpass
configurations of the Butterworth, Chebyshev type I, and elliptic designs.
Lower passband edge frequency
The lower passband frequency, in rad/s, for the bandpass and bandstop
configurations of the Butterworth, Chebyshev type I, and elliptic designs.
Upper passband edge frequency
The upper passband frequency, in rad/s, for the bandpass and bandstop
configurations of the Butterworth, Chebyshev type I, or elliptic designs.
Stopband edge frequency
The stopband edge frequency, in rad/s, for the highpass and lowpass band
configurations of the Chebyshev type II design.
Lower stopband edge frequency
The lower stopband edge frequency, in rad/s, for the bandpass and
bandstop configurations of the Chebyshev type II design.
Upper stopband edge frequency
The upper stopband edge frequency, in rad/s, for the bandpass and
bandstop filter configurations of the Chebyshev type II design.
Passband ripple in dB
The passband ripple, in dB, for the Chebyshev Type I and elliptic designs.
Stopband attenuation in dB
The stopband attenuation, in dB, for the Chebyshev Type II and elliptic
designs. Tunable.
5-25
Analog Filter Design
References Antoniou, A. Digital Filters: Analysis, Design, and Applications. 2nd ed. New
York, NY: McGraw-Hill, 1993.
5-26
Analytic Signal
Library Transforms
Description The Analytic Signal block computes the complex analytic signal corresponding
to each channel of the real M-by-N input, u.
y = u + jH { u }
where j = – 1 and H{⋅} denotes the Hilbert transform. The real part of the
output in each channel is a replica of the real input in that channel; the
imaginary part is the Hilbert transform of the input. In the frequency domain,
the analytic signal retains the positive frequency content of the original signal
while zeroing-out negative frequencies and doubling the DC component.
The block computes the Hilbert transform using an equiripple FIR filter with
the order specified by the Filter order parameter, n. The linear phase filter is
designed using the Remez exchange algorithm, and imposes a delay of n/2 on
the input samples.
The output has the same dimension and frame status as the input.
Sample-Based Operation
When the input is sample-based, each of the M∗N matrix elements represents
an independent channel. Thus, the block computes the analytic signal for each
channel (matrix element) over time.
Frame-Based Operation
When the input is frame-based, each of the N columns in the matrix contains
M sequential time samples from an independent channel, and the block
computes the analytic signal for each channel over time.
Dialog Box
5-27
Analytic Signal
Filter order
The length of the FIR filter used to compute the Hilbert transform.
5-28
Autocorrelation
Purpose 5Autocorrelation
Compute the autocorrelation of a vector input.
Library Statistics
where ∗ denotes the complex conjugate, and l represents the maximum lag.
Note that y1,j is the zero-lag element in the jth column. When All positive lags
is selected, l=M. Otherwise, l is specified as a nonnegative integer by the
Maximum positive lag parameter.
Input u is zero when indexed outside of its valid range. When the input is real,
the output is real; otherwise, the output is complex. If the input is a
sample-based vector (row, column, or 1-D), the output is sample-based, with
the same shape as the input and length l+1. The Autocorrelation block does not
accept a sample-based full-dimension matrix input.
The Scaling parameter controls the scaling that is applied to the output. The
following options are available:
biased y i, j
y i, j = --------
M
• Unbiased – Generates the unbiased estimate of the autocorrelation.
unbiased y i, j
y i, j = -------------
M–i
• Unity at zero-lag – Normalizes the estimate of the autocorrelation for each
channel so that the zero-lag sum is identically 1.
y 1, j = 1
5-29
Autocorrelation
Dialog Box
5-30
Autocorrelation LPC
uˆ M + 1 = – ( a 2 u M ) – ( a 3 u M – 1 ) – L – ( a N + 1 u M – N + 1 )
5-31
Autocorrelation LPC
min n Uã – b
ã ∈ ℜ
u1 0 L 0
u2 u1 O M
u2
M u2 O 0
u3
M
M O u1
a2 M
U = M M M u2 , ã = M , b = u
M
M M M M an + 1 0
uM M M M
M
0 O M M 0
M O O M
0 L 0 uM
r 1 r *2 L r *n a2 –r2
r2 r1 O M a3 –r3
=
M O O r *2 M M
a
rn L r2 r1 n + 1 –rn + 1
5-32
Autocorrelation LPC
Note that the solution to the LPC problem is very closely related to the
Yule-Walker AR method of spectral estimation. In that context, the normal
equations above are referred to as the Yule-Walker AR equations.
Dialog Box
Output(s)
The type of prediction coefficients output by the block. The block can output
polynomial coefficients (A), reflection coefficients (K), or both (A and K).
Output prediction error power (P)
When selected, enables port P, which outputs the output prediction error
power.
Inherit prediction order from input dimensions
When selected, the block inherits the prediction order from the input
dimensions.
Prediction order (N)
The prediction order, N. This parameter is disabled when Inherit
prediction order from input dimensions is selected.
References Haykin, S. Adaptive Filter Theory. 3rd ed. Englewood Cliffs, NJ: Prentice Hall,
1996.
Ljung, L. System Identification: Theory for the User. Englewood Cliffs, NJ:
Prentice Hall, 1987. Pgs. 278-280.
5-33
Autocorrelation LPC
5-34
Backward Substitution
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The Backward Substitution block solves the linear system UX=B by simple
backward substitution of variables, where U is the upper triangular M-by-M
matrix input to the U port, and B is the M-by-N matrix input to the B port. The
output is the solution of the equations, the M-by-N matrix X, and is always
sample-based.
The block uses only the elements in the upper triangle of input U; the lower
elements are ignored. When Force input to be unit-upper triangular is
selected, the block replaces the elements on the diagonal of U with ones. This
is useful when matrix U is the result of another operation, such as an LDL
decomposition, that uses the diagonal elements to represent the D matrix.
A length-M vector input at port B is treated as an M-by-1 matrix.
Dialog Box
5-35
Backward Substitution
5-36
Biquadratic Filter
The figure below illustrates the structure of a 4th-order biquadratic filter (L=2)
with states vik, where k is the section number.
b11 b12
u( nT s) Σ Σ y( nT s)
v11 v12
z-1 z-1
b21 a21 b22 a22
Σ Σ
v21 v22
z-1 z-1
b31 a31 b32 a32
Σ Σ
5-37
Biquadratic Filter
b 11 b 21 b 31 a 11 a 21 a 31
b 12 b 22 b 32 a 12 a 22 a 32
a 11 = a 12 = … = a 1L = 1
M M M M M M
b 1L b 2L b 3L a 1L a 2L a 3L
This is an L-by-6 matrix whose rows contain the numerator and denominator
coefficients bik and aik of each second-order section in H(z). Use the ss2sos and
tf2sos functions to convert a state-space or transfer-function description of the
filter into the second-order section description used by this block. Note that the
filter uses a value of 1 for the zero-delay denominator coefficients (a11 to a1L)
regardless of the value specified in the SOS matrix parameter.
The Initial conditions parameter sets the initial filter states, and can be
specified in the following different forms:
• Scalar to be used for all filter states (v11, v12, ..., v1L, v21 v22, ..., v2L) in all
channels. An empty vector, [], is the same as the scalar value 0.
• Vector of length 2∗L (row or column) to initialize the filter states for all
channels.
v 11 v 21 v 12 v 22 … v 1L v 2L
Each pair of elements specifies v1k and v2k for second-order section k in every
channel.
• Matrix of dimension (2∗L)-by-N containing the initial filter states for each of
the N channels.
5-38
Biquadratic Filter
Each pair of elements in a column specifies v1k and v2k for second-order
section k of the corresponding channel.
Dialog Box
SOS matrix
The second-order section matrix specifying the filter’s coefficients. This
matrix can be generated from state-space or transfer-function descriptions
by using the Signal Processing Toolbox functions ss2sos and tf2sos.
Initial conditions
The filter’s initial conditions, a scalar, vector, or matrix.
5-39
Biquadratic Filter
See “Designing Filters with Various Filter Structures” on page 4-6 for related
information.
5-40
Buffer
Purpose 5Buffer
Buffer the input sequence to a smaller or larger frame size.
Description The Buffer block redistributes the input samples to a new frame size, larger or
smaller than the input frame size. Buffering to a larger frame size yields an
output with a slower frame rate than the input, as illustrated below for scalar
input.
“fast-time” input “slow-time” output
(frame size = 1, sample period = T si) (frame size = 3, frame period = 3∗Tsi)
7 4 1
9 8 7 6 5 4 3 2 1 8 5 2
9 6 3
Buffering to a smaller frame size yields an output with a faster frame rate than
the input, as illustrated below for scalar output.
“slow-time” input “fast-time” output
(frame size = 3, frame period = 3∗Tsi) (frame size = 1, sample period = Tsi)
7 4 1
8 5 2 9 8 7 6 5 4 3 2 1
9 6 3
The block coordinates the output frame size and frame rate of nonoverlapping
buffers so that the sample period of the signal is the same at both the input and
output, Tso = Tsi.
Sample-Based Operation
Sample-based inputs are interpreted by the Buffer block as independent
channels of data. Thus, a sample-based length-N vector input is interpreted as
N independent samples.
In sample-based operation, the Buffer block creates frame-based outputs from
sample-based inputs. A sequence of sample-based length-N vector inputs (1-D,
2-D row, or 2-D column) is buffered into an Mo-by-N matrix, where Mo is
specified by the Output buffer size parameter (Mo > 1). That is, each input
vector becomes a row in the N-channel frame-based output matrix. When
5-41
Buffer
Mo=1, the input is simply passed through to the output, and retains the same
dimension.
Sample-based full-dimension matrix inputs are not accepted.
The Buffer overlap parameter, L, specifies the number of samples (rows) from
the current output to repeat in the next output, where L < Mo. For 0 ≤ L < Mo,
the number of new input samples that the block acquires before propagating
the buffered data to the output is the difference between the Output buffer
size and Buffer overlap, Mo-L.
The output frame period is (Mo-L)∗Tsi, which is equal to the input sequence
sample period, Tsi, when the Buffer overlap is Mo-1. For L < 0, the block
simply discards L input samples after the buffer fills, and outputs the buffer
with period (Mo-L)∗Tsi, which is longer than the zero-overlap case.
In the model below, the block buffers a four-channel sample-based input using
a Output buffer size of 3 and a Buffer overlap of 1.
ch2 ch3
ch1 ch4
Sample-based input ,
t=5 6 1 5 –6 sample period = Tsi
Tsi = 1
t=4 5 1 5 –5
Frame-based output ,
t=3 4 0 5 –4 frame period = (M o-L)∗Tsi
first
t=2 3 0 5 –3
first sample-based frame-based
t=1 2 1 5 –2 input output
ch1
ch2
ch3
ch4
ch1
ch2
ch3
ch4
ch1
ch2
ch3
ch4
t=0 1 1 5 –1
4 0 5 –4 2 1 5 –2 0 0 0 0 0000
5 1 5 –5 3 0 5 –3 1 1 5 –1 0000
6 1 5 –6 4 0 5 –4 2 1 5 –2 0000
Note that the input vectors do not begin appearing at the output until the
second row of the second matrix. This is due to the block’s latency (see
“Latency” below). The first output matrix (all zeros in this example) reflects the
block’s Initial conditions setting, while the first row of zeros in the second
output is a result of the one-sample overlap between consecutive output
frames.
5-42
Buffer
You can use the rebuffer_delay function with a frame size of 1 to precisely
compute the delay (in samples) for sample-based signals. For the above
example,
d = rebuffer_delay(1,3,1)
d =
4
This agrees with the four samples of delay (zeros) per channel shown in the
figure above.
Frame-Based Operation
In frame-based operation, the Buffer block redistributes the samples in the
input frame to an output frame with a new size and rate. A sequence of Mi-by-N
matrix inputs is buffered into a sequence of Mo-by-N frame-based matrix
outputs, where Mo is the output frame size specified by the Output buffer size
parameter (i.e., the number of consecutive samples from the input frame to
buffer into the output frame). Mo can be greater or less than the input frame
size, Mi. Each of the N input channels is buffered independently.
The Buffer overlap parameter, L, specifies the number of samples (rows) from
the current output to repeat in the next output, where L < Mo. For 0 ≤ L < Mo,
the number of new input samples the block acquires before propagating the
buffered data to the output is the difference between the Output buffer size
and Buffer overlap, Mo-L.
The input frame period is Mi∗Tsi, where Tsi is the sample period. The output
frame period is (Mo-L)∗Tsi, which is equal to the sequence sample period when
the Buffer overlap is Mo-1. The output sample period is therefore related to
the input sample period by
( M o – L )T si
T so = -------------------------------
Mo
5-43
Buffer
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
5 1 1 1
6 1 2 1 51 30 11 00 00 00
7 0 3 0 61 40 21 00 00 00
8 0 4 0 70 51 30 11 00 00
t=4 t=0 (Mo=3, L=1) t=10 t=8 t=6 t=4 t=2 t=0
Note that the sequence is delayed by eight samples, which is the latency of the
block in Simulink’s multitasking mode for the parameter settings of this
example (see “Latency” below). The first eight output samples therefore adopt
the value specified for the Initial conditions, which is assumed here to be zero.
Use the rebuffer_delay function to determine the block’s latency for any
combination of frame size and overlap.
• Scalar input and output (Mo = Mi = 1) with zero or negative Buffer overlap
(L ≤ 0)
• Scalar output (Mo = 1) with zero Buffer overlap (L = 0) for any input frame
size Mi
• Equal input and output frame sizes (Mo = Mi) with zero Buffer overlap
(L = 0)
• Input frame size an integer multiple of the output frame size (Mi/Mo = k, for
an integer value of k) with zero Buffer overlap (L = 0)
Zero tasking latency means that the first input sample (received at t=0)
appears as first output sample.
5-44
Buffer
Nonzero Latency
Mo + L (L ≥ 0)
D =
Mo (L < 0)
• An Mo-by-N matrix
• A length-Mo vector to be repeated across all columns of the initial output(s)
• A scalar to be repeated across all elements of the initial output(s)
In the special case where the output is 1-by-N (the result of unbuffering an
Mi-by-N frame-based matrix), Initial conditions can be:
5-45
Buffer
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
Dialog Box
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-46
Buffer
5-47
Burg AR Estimator
Description The Burg AR Estimator block uses the Burg method to fit an autoregressive
(AR) model to the input data by minimizing (least squares) the forward and
backward prediction errors while constraining the AR parameters to satisfy
the Levinson-Durbin recursion.
The input is a sample-based vector (row, column, or 1-D) or frame-based vector
(column only) representing a frame of consecutive time samples from a
single-channel signal, which is assumed to be the output of an AR system
driven by white noise. The block computes the normalized estimate of the AR
system parameters, A(z), independently for each successive input frame.
G G
H ( z ) = ------------ = -------------------------------------------------------------------------------
A(z) –1
1 + a ( 2 )z + … + a ( p + 1 )z
–p
• A – The top output, A, is a column vector of length p+1 with the same frame
status as the input, and contains the normalized estimate of the AR model
polynomial coefficients in descending powers of z,
[1 a(2) ... a(p+1)]
• K – The top output, K, is a column vector of length p with the same frame
status as the input, and contains the reflection coefficients (which are a
secondary result of the Levinson recursion).
• A and K – The block outputs both realizations.
5-48
Burg AR Estimator
Dialog Box
Output(s)
The realization to output, model coefficients, reflection coefficients, or both.
Inherit estimation order from input dimensions
When selected, sets the estimation order p to one less than the length of the
input vector.
Estimation order
The order of the AR model, p. This parameter is enabled when Inherit
estimation order from input dimensions is not selected.
5-49
Burg Method
Description The Burg Method block estimates the power spectral density (PSD) of the input
frame using the Burg method. This method fits an autoregressive (AR) model
to the signal by minimizing (least-squares) the forward and backward
prediction errors while constraining the AR parameters to satisfy the
Levinson-Durbin recursion.
The input is a sample-based vector (row, column, or 1-D) or frame-based vector
(column only) representing a frame of consecutive time samples from a
single-channel signal. The block’s output (a column vector) is the estimate of
the signal’s power spectral density at Nfft equally spaced frequency points in
the range [0,Fs), where Fs is the signal’s sample frequency.
When Inherit estimation order from input dimensions is selected, the order
of the all-pole model is one less that the input frame size. Otherwise, the order
is the value specified by the Estimation order parameter. The spectrum is
computed from the FFT of the estimated AR model parameters.
When Inherit FFT length from input dimensions is selected, Nfft is specified
by the frame size of the input, which must be a power of 2. When Inherit FFT
length from input dimensions is not selected, Nfft is specified as a power of 2
by the FFT length parameter, and the block zero pads or truncates the input
to Nfft before computing the FFT. The output is always sample-based.
The Burg Method and Yule-Walker Method blocks return similar results for
large frame sizes. The following table compares the features of the Burg
Method block to the Covariance Method, Modified Covariance Method, and
Yule-Walker Method blocks.
5-50
Burg Method
Characteristics Does not apply Does not apply Does not apply Applies window to
window to data window to data window to data data
Advantages High resolution for Better resolution than High resolution for Performs as well as
short data records Y-W for short data short data records other methods for
records (more large data records
accurate estimates)
Disadvantages Peak locations highly May produce unstable May produce unstable Performs relatively
dependent on initial models models poorly for short data
phase records
May suffer spectral Frequency bias for Peak locations Frequency bias for
line-splitting for estimates of sinusoids slightly dependent on estimates of sinusoids
sinusoids in noise, or in noise initial phase in noise
when order is very
large
Conditions for Order must be less Order must be less Because of the biased
Nonsingularity than or equal to half than or equal to 2/3 estimate, the
the input frame size the input frame size autocorrelation
matrix is guaranteed
to positive-definite,
hence nonsingular
5-51
Burg Method
Examples The dspsacomp demo compares the Burg method with several other spectral
estimation methods.
Dialog Box
5-52
Burg Method
5-53
Check Signal Attributes
Description The Check Signal Attributes block terminates the simulation with an error
when the input characteristics differ from those specified by the block
parameters.
When the Error if input parameter is set to Does not match attributes
exactly, the block generates an error only when the input possesses none of the
attributes specified by the other parameters. Signals that possess at least one
of the specified attributes are propagated to the output unaltered, and do not
generate an error.
When the Error if input parameter is set to Matches attributes exactly, the
block generates an error only when the input possesses all attributes specified
by the other parameters. Signals that do not possess all of the specified
attributes are propagated to the output unaltered, and do not generate an
error.
Signal Attributes
The Check Signal Attributes block can test for up to five different signal
attributes, as specified by the following parameters. When Ignore is selected
in any parameter, the block does not check the signal for the corresponding
attribute. For example, when Complexity is set to Ignore, neither real nor
complex inputs cause the block to generate an error. The attributes are:
• Complexity
Checks whether the signal is real or complex. (Note that this information can
also be displayed in a model by attaching a Probe block with Probe complex
signal selected, or by selecting Port data types from the model window’s
Format menu.)
• Frame status
Checks whether the signal is frame-based or sample-based. (Note that
Simulink displays sample-based signals using a single line, →, and
frame-based signals using a double line, ⇒.)
5-54
Check Signal Attributes
• Dimensionality
Checks the dimension of signal for compliance (Is...) or noncompliance
(Is not...) with the attributes in the subordinate Dimension menu, which are
shown in the table below. See“Signal Dimension Nomenclature” on page 1-10
for a description of Simulink signal dimensions. M and N are positive
integers unless otherwise indicated below.
5-55
Check Signal Attributes
5-56
Check Signal Attributes
Note that when Signal dimensions is selected from the model window
Format menu, Simulink displays the size of a 1-D vector signal as an
unbracketed integer, and displays the dimension of a 2-D signal as a pair of
bracketed integers, [MxN]. Simulink does not display any size information for
a 1-D or 2-D scalar signal. Dimension information for a signal can also be
displayed in a model by attaching a Probe block with Probe signal
dimensions selected.
• Data type
Checks the signal data type for compliance (Is...) or noncompliance (Is not...)
with the attributes in the subordinate General data type menu, which are
shown in the table below. Any of the specific data types listed in the Is...
5-57
Check Signal Attributes
Note that data type information can also be displayed in a model by selecting
Port data types from the model window’s Format menu.
• Sample mode
Checks whether the signal is discrete-time or continuous-time. (Note that
when Sample time colors is selected from the Format menu, Simulink
displays continuous-time signal lines in black or grey and discrete-time
signal lines in colors corresponding to the relative rate. When a Probe block
with Probe sample time enabled is attached to a continuous-time signal, the
block icon displays the string Ts:[0 x], where x is the sample time offset.
When a Probe block is attached to a discrete-time signal, the block icon
displays the string Ts:[t 0] for a sample-based signal or Tf:[t 0] for a
frame-based signal, where t is the nonzero sample period or frame period,
respectively. Frame-based signals are almost always discrete-time.)
5-58
Check Signal Attributes
Dialog Box
Error if input
Specifies whether the block generates an error when the input possesses
none of the required attributes (Does not match attributes exactly), or
when the input possesses all of the required attributes (Matches
attributes exactly).
Complexity
The complexity for which the input should be checked, Real or Complex.
Frame status
The frame status for which the input should be checked, Sample-based or
Frame-based.
Dimensionality
Specifies whether the input should be checked for compliance (Is...) or
noncompliance (Is not...) with the attributes in the subordinate
Dimension menu.
Dimensions
The dimensions for which the input should be checked. This parameter is
available when Is... or Is not... is selected in the Dimensionality menu.
5-59
Check Signal Attributes
Data type
Specifies whether the input should be checked for compliance (Is...) or
noncompliance (Is not...) with the attributes in the subordinate General
data type menu.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-60
Chirp
Purpose 5Chirp
Generate a swept-frequency cosine (chirp) signal.
Description The Chirp block outputs a swept-frequency cosine (chirp) signal with unity
amplitude and continuous phase. To specify the desired output chirp signal,
you must define its instantaneous frequency function, also known as the output
frequency sweep. The frequency sweep can be linear, quadratic, or logarithmic,
and repeats once every Sweep time by default. See the following sections of
this reference page for more details:
5-61
Chirp
1 Sample-based
5-62
Chirp
The following diagram illustrates the possible shapes of the frequency sweep
that you can obtain by setting the Frequency sweep and Sweep mode
parameters.
For information on how to set the frequency values in your sweep, see “Setting
Instantaneous Frequency Sweep Values”.
5-63
Chirp
The following diagram illustrates a linear sweep in both sweep modes. For
information on setting the frequency values in your sweep, see “Setting
Instantaneous Frequency Sweep Values”.
5-64
Chirp
The following table summarizes the sweep values at specific times for all
Frequency sweep settings. For information on the formulas used to compute
sweep values at other times, see “Block Computation Methods”.
Frequency Sweep Value at t = 0 Sweep Value at t = tg Time When Sweep Value is Target
Sweep Frequency, fi(tg)
Linear f0 fi(tg) tg
Quadratic f0 fi(tg) tg
Logarithmic f0 + 1 fi(tg) tg
Equations for Output Computation. The following table shows the equations used by
the block to compute the user-specified output frequency sweep, fi(t), the block
output, ychirp(t), and the actual output frequency sweep, fi(actual)(t). The only
time the user-specified sweep is not the actual output sweep is when the
Frequency sweep parameter is set to Swept cosine.
5-65
Chirp
examine the following table and the diagram in “Shaping the Frequency
Sweep by Setting Frequency Sweep and Sweep Mode” on page 5-62.
Table 5-2: Equations Used by the Chirp Block for Unidirectional Positive Sweeps
Swept cosine y ( t ) = cos ( 2πf ( t )t + φ ) Same as Linear Same as Linear f (t) = f (t) + βt
chirp i 0 i ( actual ) i
Output Computation Method for Linear, Quadratic, and Logarithmic Frequency Sweeps.
The derivative of the phase of a chirp function gives the instantaneous
frequency of the chirp function. The Chirp block uses this principle to calculate
5-66
Chirp
the chirp output when the Frequency Sweep parameter is set to Linear,
Quadratic, or Logarithmic.
For instance, if you want a chirp signal with a linear instantaneous frequency
sweep, you should set the Frequency Sweep parameter to Linear, and tune
the linear sweep values by setting other parameters appropriately. The block
will output a chirp signal, the phase derivative of which is the specified linear
sweep. This ensures that the instantaneous frequency of the output is the
linear sweep you desired. For equations describing the linear, quadratic, and
logarithmic sweeps, see “Equations for Output Computation” on page 5-65.
Output Computation Method for Swept Cosine Frequency Sweep. To generate the swept
cosine chirp signal, the block sets the swept cosine chirp output as follows.
Note that Equation 5-1 does not hold for the swept cosine chirp, so the
user-defined frequency sweep, fi(t), is not the actual output frequency sweep,
fi(actual)(t), of the swept cosine chirp. Thus, the swept cosine output may not
behave as you expect. To learn more about swept cosine chirp behavior, see
“Cautions Regarding the Swept Cosine Sweep” on page 5-67 and “Equations for
Output Computation” on page 5-65.
5-67
Chirp
Swept Cosine Instantaneous Output Frequency at the Target Time is not the Target Frequency.
The swept cosine sweep value at the Target time is not necessarily the Target
frequency. This is because the user-specified sweep is not the actual frequency
sweep of the swept cosine output, as noted in “Output Computation Method for
Swept Cosine Frequency Sweep” on page 5-67. See Table 5-1, Instantaneous
Frequency Sweep Values, for the actual value of the swept cosine sweep at the
Target time.
Swept Cosine Output Frequency Content May Greatly Exceed Frequencies in the Sweep. In
Swept cosine mode, you should not set the parameters so that 1/Tsw is very
large compared to the values of the Initial frequency and Target frequency
parameters. In such cases, the actual frequency content of the swept cosine
sweep may be closer to 1/Tsw, far exceeding the Initial frequency and Target
frequency parameter values.
Examples The first few examples demonstrate how to use the Chirp block’s main
parameters, how to view the output in the time domain, and how to view the
output spectrogram:
Examples 4 and 5 illustrate Chirp block settings that may produce unexpected
outputs:
• “Example 4: Output Sweep with Negative Frequencies”
• “Example 5: Output Sweep with Frequencies Greater Than Half the
Sampling Frequency”
Example 1: Setting a Final Frequency Value for Unidirectional Sweeps. Often times, you
may want a unidirectional sweep for which you know the initial and final
frequency values. You can specify the final frequency of a unidirectional sweep
by setting Target time equal to Sweep time, in which case the Target
frequency becomes the final frequency in the sweep. The following model
demonstrates this method.
This technique may not work for swept cosine sweeps. For details, see
“Cautions Regarding the Swept Cosine Sweep” on page 5-67.
5-68
Chirp
Open the Example 1 model by clicking here in the MATLAB Help Browser. You
can also rebuild the model yourself; see the following list for model parameter
settings (leave unlisted parameters in their default states).
Since Target time is set to equal Sweep time (1 second), the Target
frequency (25 Hertz) is the final frequency of the unidirectional sweep.
10 40
35
5 30
AMPLITUDE
FREQUENCY
25
0
20
15
−5
10
5
−10
0 1 2 3 4 5 6 0
Frame: 6 TIME (s) 0 1 2 3 4 5
TIME (s)
Run your model to see the time domain output, and then type the following
command to view the chirp output spectrogram.
5-69
Chirp
specgram(dsp_examples_yout,[0:.01:40],400,hamming(128),110)
5-70
Chirp
Open the Example 2 model by clicking here in the MATLAB Help Browser.
10 40
35
5 30
AMPLITUDE
FREQUENCY
25
0
20
15
−5
10
5
−10
0 1 2 3 4 5 6 0
Frame: 6 TIME (s) 0 1 2 3 4 5
TIME (s)
Run your model to see the time domain output, and then type the following
command to view the chirp output spectrogram.
specgram(dsp_examples_yout,[0:.01:40],400,hamming(128),110)
Example 3: When Sweep Time is Greater Than Target Time. Setting Sweep time to 1.5
and leaving the rest of the parameters as in the Example 1 model gives the
following output. The sweep still reaches the Target frequency (25 Hertz) at
the Target time (1 second), but since Sweep time is greater than Target time,
the sweep continues on its linear path until one Sweep time (1.5 seconds) is
traversed.
Unexpected behavior may arise when you set Sweep time greater than Target
time; see “Example 4: Output Sweep with Negative Frequencies” for details.
5-71
Chirp
Open the Example 3 model by clicking here in the MATLAB Help Browser.
10 40
35
5 30
AMPLITUDE
FREQUENCY
25
0
20
15
−5
10
5
−10
0 1 2 3 4 5 6 0
Frame: 6 TIME (s) 0 1 2 3 4 5
Time (s)
Run your model to see the time domain output, and then type the following
command to view the chirp output spectrogram.
specgram(dsp_examples_yout,[0:.01:40],400,hamming(128),110)
Example 4: Output Sweep with Negative Frequencies. Modify the Example 1 model by
changing Sweep time to 1.5, Initial frequency to 25, and Target frequency
to 0. The output chirp of this example may not behave as you expect because the
sweep contains negative frequencies between 1 and 1.5 seconds. The sweep
reaches the Target frequency of 0 Hertz at one second, then continues on its
negative slope, taking on negative frequency values until it traverses one
Sweep time (1.5 seconds).
The spectrogram may reflect negative sweep frequencies along the x-axis so
they appear to be positive, as in the one below. If you unexpectedly get a chirp
output with a spectrogram resembling the one following, your chirp’s sweep
may contain negative frequencies. See the next example for another possible
unexpected chirp output.
5-72
Chirp
Open the Example 4 model by clicking here in the MATLAB Help Browser.
10 30
25
5
20
AMPLITUDE
FREQUENCY
0 15
10
−5
−10
0 1 2 3 4 5 6 0
0 1 2 3 4 5
Frame: 6 TIME (s) TIME (s)
Run your model to see the time domain output, and then type the following
command to view the chirp output spectrogram.
specgram(dsp_examples_yout,[0:.1:30],400,hamming(128),110);
Example 5: Output Sweep with Frequencies Greater Than Half the Sampling Frequency.
Modify the Example 1 model by changing the Target frequency parameter
to 275. The output chirp of this model may not behave as you expect because the
sweep contains frequencies greater than half the sampling frequency (200
Hertz), which causes aliasing. If you unexpectedly get a chirp output with a
spectrogram resembling the one following, your chirp’s sweep may contain
frequencies greater than half the sampling frequency. See the previous
example for another possible unexpected chirp output.
5-73
Chirp
Open the Example 5 model by clicking here in the MATLAB Help Browser.
10 200
180
160
5
140
AMPLITUDE
FREQUENCY
120
0
100
80
−5 60
40
20
−10
0 1 2 3 4 5 6 0
Frame: 6 TIME (s) 0 1 2 3 4 5
TIME (s)
Run your model to see the time domain output, and then type the following
command to view the chirp output spectrogram.
specgram(dsp_examples_yout,256,400,hamming(64),60)
5-74
Chirp
Dialog Box
Frequency sweep
The type of output instantaneous frequency sweep, fi(t): Linear,
Logarithmic, Quadratic, or Swept cosine. Tunable.
Sweep mode
The directionality of the chirp signal: Unidirectional or Bidirectional.
Tunable.
Initial frequency (Hz)
For Linear, Quadratic, and Swept cosine sweeps, the initial frequency,
f0, of the output chirp signal. For Logarithmic sweeps, Initial frequency
is one less than the actual initial frequency of the sweep. Also, when the
sweep is Logarithmic, you must set the Initial frequency to be less than
the Target frequency. Tunable.
5-75
Chirp
5-76
Chirp
See “Creating Signals Using Signal Generator Blocks” on page 3-36 for related
information.
5-77
Cholesky Factorization
Description The Cholesky Factorization block uniquely factors the square Hermitian
positive definite input matrix S as
*
S = LL
where L is a lower triangular square matrix with positive diagonal elements
and L* is the Hermitian (complex conjugate) transpose of L. Only the diagonal
and upper triangle of the input matrix are used, and any imaginary component
of the diagonal entries is disregarded.
The block’s output is a composite matrix with lower triangle elements from L
and upper triangle elements from L*, and is always sample-based.
3.00 0 0
L = – 0.33 2.81 0
0.67 – 1.70 1.91
Note that L and L* share the same diagonal in the output matrix. Cholesky
factorization requires half the computation of Gaussian elimination
(LU decomposition), and is always stable.
The algorithm requires that the input be square and Hermitian positive
definite. When the input is not positive definite, the block reacts with the
behavior specified by the Non-positive definite input parameter. The
following options are available:
• Ignore – Proceed with the computation and do not issue an alert. The output
is not a valid factorization. A partial factorization will be present in the
upper left corner of the output.
5-78
Cholesky Factorization
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-79
Cholesky Inverse
Description The Cholesky Inverse block computes the inverse of the Hermitian positive
definite input matrix S by performing Cholesky factorization.
–1 * –1
S = ( LL )
• Ignore – Proceed with the computation and do not issue an alert. The output
is not a valid inverse.
• Warning – Display a warning message in the MATLAB command window,
and continue the simulation. The output is not a valid inverse.
• Error – Display an error dialog box and terminate the simulation.
Dialog Box
5-80
Cholesky Inverse
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-81
Cholesky Solver
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The Cholesky Solver block solves the linear system SX=B by applying Cholesky
factorization to input matrix at the S port, which must be square (M-by-M) and
Hermitian positive definite. Only the diagonal and upper triangle of the matrix
are used, and any imaginary component of the diagonal entries is disregarded.
The input to the B port is the right-hand side M-by-N matrix, B. The output is
the unique solution of the equations, M-by-N matrix X, and is always
sample-based.
When the input is not positive definite, the block reacts with the behavior
specified by the Non-positive definite input parameter. The following options
are available:
• Ignore – Proceed with the computation and do not issue an alert. The output
is not a valid solution.
• Warning – Proceed with the computation and display a warning message in
the MATLAB command window. The output is not a valid solution.
• Error – Display an error dialog box and terminate the simulation.
Algorithm Cholesky factorization uniquely factors the Hermitian positive definite input
matrix S as
*
S = LL
where L is a lower triangular square matrix with positive diagonal elements.
The equation SX=B then becomes
*
LL X = B
which is solved for X by making the substitution Y = L*X, and solving the
following two triangular systems by forward and backward substitution,
respectively.
5-82
Cholesky Solver
LY = B
*
L X = Y
Dialog Box
5-83
Complex Cepstrum
Library Transforms
Description The Complex Cepstrum block computes the complex cepstrum of each channel
in the real-valued M-by-N input matrix, u. For both sample-based and
frame-based inputs, the block assumes that each input column is a frame
containing M consecutive samples from an independent channel. The block
does not accept complex-valued inputs.
The input is altered by the application of a linear phase term so that there is
no phase discontinuity at ±π radians. That is, each input channel is
independently zero padded and circularly shifted to have zero phase at
π radians.
The output is a real Mo-by-N matrix, where Mo is specified by the FFT length
parameter. Each output column contains the length-Mo complex cepstrum of
the corresponding input column.
y = cceps(u,Mo) % Equivalent MATLAB code
When the Inherit FFT length from input port dimensions check box is
selected, the output frame size matches the input frame size (Mo=M). In this
case, a sample-based length-M row vector input is processed as a single channel
(i.e., as an M-by-1 column vector), and the output is a length-M row vector. A
1-D vector input is always processed as a single channel, and the output is a
1-D vector.
The output is always sample-based, and the output port rate is the same as the
input port rate.
Dialog Box
5-84
Complex Cepstrum
5-85
Complex Exponential
Description The Complex Exponential block computes the complex exponential function for
each element of the real input, u.
ju
y = e = cos u + j sin u
where j = – 1 . The output is complex, with the same size and frame status as
the input.
Dialog Box
5-86
Constant Diagonal Matrix
Description The Constant Diagonal Matrix block outputs a square diagonal matrix
constant. The Constant along diagonal parameter determines the values
along the matrix diagonal. This parameter can be a scalar to be repeated for all
elements along the diagonal, or a vector containing the values of the diagonal
elements. To generate the identity matrix, set the Constant along diagonal
to 1, or use the Identity Matrix block.
The output is frame-based when the Frame-based output check box is
selected; otherwise, the output is sample-based.
Dialog Box
5-87
Constant Diagonal Matrix
Supported (MATLAB
( commands for casting values to certain data types are provided in
Data Types parentheses.)
Boolean (boolean)
8-, 16-, and 32-bit signed integer (int8, int16, int32)
8-, 16-, and 32-bit unsigned integer (uint8, uint16, uint32)
Single-precision floating point (single)
Double-precision floating point (double)
See “Creating Signals Using Constant Blocks” on page 3-33 for related
information.
5-88
Constant Ramp
Description The Constant Ramp block generates the constant ramp signal
y = (0:L-1)*m + b
where m is the slope specified by the scalar Slope parameter, b is the y-intercept
specified by the scalar Offset parameter.
For a matrix input, the length L of the output ramp is equal to either the
number of rows or the number of columns in the input, as determined by the
Ramp length equals number of parameter. For a 1-D vector input, L is equal
to the length of the input vector. The output, y, is always a 1-D vector.
Dialog Box
5-89
Constant Ramp
See “Creating Signals Using Constant Blocks” on page 3-33 for related
information.
5-90
Contiguous Copy
Description The Contiguous Copy block copies the input to a contiguous block of memory,
and passes this new copy to the output. The output is identical to the input, but
is guaranteed to reside in a contiguous section of memory.
Because Simulink employs an efficient copy-by-reference method for
propagating data in a model, some operations produce outputs with
discontiguous memory locations. An example of such an operation is shown
below with the Simulink Selector block.
Memory addresses m1 m2 m3 m4 m5 m6 m7 m8
Memory contents u1 u2 u3 u4 u5 u6 u7 u8
m1
m2
m3
m6
m4
m3
m5
m7
m6
m7
m8
Although this does not present a problem during simulation, blocks linked to
versions of the DSP Blockset prior to 4.0 may require contiguous inputs for
code-generation with the Real-Time Workshop (RTW). When such blocks are
used in a model intended for code generation, they should be preceded by the
Contiguous Copy block to ensure that their inputs are contiguous. The DSP
Blockset version 3.1 Autocorrelation block shown below is an example of one
that requires contiguous inputs for code generation.
5-91
Contiguous Copy
m6 m9 v3.1
m3 m 10
m7 m 11
Dialog Box
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-92
Convert 1-D to 2-D
Description The Convert 1-D to 2-D block reshapes a length-Mi 1-D vector or an Mi-by-Ni
matrix to an Mo-by-No matrix, where Mo is specified by the Number of output
rows parameter, and No is specified by the Number of output columns
parameter.
y = reshape(u,Mo,No) % Equivalent MATLAB code
The input is reshaped columnwise, as shown in the two cases below. The
length-6 vector and the 2-by-3 matrix are both reshaped to the same 3-by-2
output matrix.
(u1 u2 u3 u4 u5 u6)
u1 u4
u2 u5
u3 u6
u1 u3 u5
u2 u4 u6
An error is generated if (Mo∗No) ≠ (Mi∗Ni). That is, the total number of input
elements must be conserved in the output.
The output is frame-based if the Frame-based output check box is selected;
otherwise, the output is sample-based.
Dialog Box
5-93
Convert 1-D to 2-D
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-94
Convert 2-D to 1-D
Description The Convert 2-D to 1-D block reshapes an M-by-N matrix input to a 1-D vector
with length M∗N.
y = u(:) % Equivalent MATLAB code
u1 u4
u2 u5 (u1 u2 u3 u4 u5 u6)
u3 u6
Dialog Box
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-95
Convert Complex DSP To Simulink
Description The Convert Complex DSP To Simulink block accepts complex data (scalar,
vector, matrix) in the DSP Blockset Version 2.2 format, and outputs the same
data in the Simulink Version 3 complex format. Only complex data should be
supplied to this block.
Blocks provided in Release 11 and later blocksets (e.g., Simulink Version 3.0,
DSP Blockset Version 3.0, Fixed Point Blockset Version 2.0) use the
Simulink Version 3 complex format, which is not compatible with the DSP
Blockset Version 2.2 complex format. To add a new block or subsystem
(Release 11 and later) to an existing model that uses the DSP Blockset Version
2.2 complex data format, precede it with the Convert Complex DSP To
Simulink block. If the new block or subsystem’s output is complex, you should
follow it with the complementary Convert Complex Simulink To DSP block
(unless the downstream blocks have already been updated to their Release 11
counterparts).
These convertor blocks are only needed for interfacing Version 3.0 blocks to the
complex-data section of a Version 2.2 or earlier model. Version 3.0 blocks can
be added to real-data sections of older models without any data format
conversion.
Note Within a section of model that uses the Version 2.2 complex format, you
should continue to use the complex port identifier (∗) as a guide to wiring
blocks. Outputs ports labeled with the ∗ symbol should only be connected to
input ports labeled with the ∗ symbol.
The following figure shows how you can use these two convertor blocks to
migrate part of a complex-data model to the Version 3.0 complex format while
letting other components continue to use the Version 2.2 complex-data format.
5-96
Convert Complex DSP To Simulink
(Subsystem A remains a
Version 2.2 implementation)
(Subsystem B remains a
Version 2.2 implementation)
Dialog Box
5-97
Convert Complex Simulink To DSP
Description The Convert Complex Simulink To DSP block accepts complex data (scalar,
vector, matrix) in the Simulink Version 3 format, and outputs the same data in
the DSP Blockset Version 2.2 complex format. Only complex data should be
supplied to this block.
Blocks provided in Release 11 and later blocksets (e.g., Simulink Version 3.0,
DSP Blockset Version 3.0, Fixed Point Blockset Version 2.0) use the
Simulink Version 3 complex format, which is not compatible with the DSP
Blockset Version 2.2 complex format. To add a new block or subsystem
(Release 11 and later) to an existing model that uses the DSP Blockset Version
2.2 complex data format, precede it with the Convert Complex DSP To
Simulink block. If the new block’s output is complex, you should then follow it
with the Convert Complex Simulink To DSP block (unless the downstream
blocks have already been updated to their Release 11 counterparts).
These convertor blocks are only needed for interfacing Version 3.0 blocks to the
complex-data section of a Version 2.2 or earlier model. Version Version 3.0
blocks can be added to real-data sections of older models without any data
format conversion.
Note Within a section of model that uses the Version 2.2 complex format, you
should continue to use the complex port identifier (∗) as a guide to wiring
blocks. Outputs ports labeled with the ∗ symbol should only be connected to
input ports labeled with the ∗ symbol.
The following figure shows how you can use these two convertor blocks to
migrate part of a complex-data model to the Version 3.0 complex format while
letting other components continue to use the Version 2.2 complex-data format.
5-98
Convert Complex Simulink To DSP
(Subsystem A remains a
Version 2.2 implementation)
(Subsystem B remains a
Version 2.2 implementation)
Dialog Box
5-99
Convolution
Purpose 5Convolution
Compute the convolution of two inputs.
Frame-Based Inputs
Matrix inputs must be frame-based. The output, y, is a frame-based
(Mu+Mv-1)-by-N matrix whose jth column has elements
max ( M u, M v )
y i, j = ∑ u k, j v *( i – k + 1 ), j 1 ≤ i ≤ ( Mu + Mv – 1 )
k=1
where ∗ denotes the complex conjugate. Inputs u and v are zero when indexed
outside of their valid ranges. When both inputs are real, the output is real;
when one or both inputs are complex, the output is complex.
When one input is a column vector (single channel) and the other is a matrix
(multiple channels), the single-channel input is independently convolved with
each channel of the multichannel input. For example, if u is a Mu-by-1 column
vector and v is an Mv-by-N matrix, the output is an (Mu+Mv-1)-by-N matrix
whose jth column has elements
max ( M u, M v )
y i, j = ∑ u k v (*i – k + 1 ), j 1 ≤ i ≤ ( Mu + Mv – 1 )
k=1
Sample-Based Inputs
If u and v are sample-based vectors with lengths Mu and Mv, the Convolution
block performs the vector convolution
max ( M u, M v )
yi = ∑ u k v *( i – k + 1 ) 1 ≤ i ≤ ( Mu + Mv – 1 )
k=1
5-100
Convolution
• When both inputs are row vectors, or when one input is a row vector and the
other is a 1-D vector, the output is a 1-by-(Mu+Mv-1) row vector.
• When both inputs are column vectors, or when one input is a column vector
and the other is a 1-D vector, the output is a (Mu+Mv-1)-by-1 column vector.
• When both inputs are 1-D vectors, the output is a 1-D vector of length
Mu+Mv-1.
Dialog Box
5-101
Correlation
Purpose 5Correlation
Compute the correlation along the columns of two inputs.
Library Statistics
Frame-Based Inputs
Matrix inputs must be frame-based. The output, y, is a frame-based
(Mu+Mv-1)-by-N matrix whose jth column has elements
max ( M u, M v )
y i, j = ∑ u k, j v *( k + i – M ), j
v
1 ≤ i ≤ ( Mu + Mv – 1 )
k=1
where ∗ denotes the complex conjugate. Inputs u and v are zero when indexed
outside of their valid ranges. When both inputs are real, the output is real;
when one or both inputs are complex, the output is complex.
When one input is a column vector (single channel) and the other is a matrix
(multiple channels), the single-channel input is independently cross-correlated
with each channel of the multichannel input. For example, if u is a Mu-by-1
column vector and v is an Mv-by-N matrix, the output is an (Mu+Mv-1)-by-N
matrix whose jth column has elements
max ( M u, M v )
y i, j = ∑ u k v *( k – i + M v ), j 1 ≤ i ≤ ( Mu + Mv – 1 )
k=1
Sample-Based Inputs
Matrix inputs cannot be sample based, so all sample-based inputs are column
vectors or 1-D vectors. (the block does not support 2-D row vector inputs.) If u
and v are sample-based vectors with lengths Mu and Mv, the Correlation block
performs the vector cross-correlation
5-102
Correlation
max ( M u, M v )
yi = ∑ u k v *( k – i + M v ) 1 ≤ i ≤ ( Mu + Mv – 1 )
k=1
• When both inputs are column vectors, or when one input is a column vector
and the other is a 1-D vector, the output is a (Mu+Mv-1)-by-1 column vector.
• When both inputs are 1-D vectors, the output is a 1-D vector of length
Mu+Mv-1.
Dialog Box
5-103
Counter
Purpose 5Counter
Count up or down through a specified range of numbers.
Description The Counter block increments or decrements an internal counter each time it
receives a trigger event at the Clk port. A trigger event at the Rst port resets
the counter to its initial state.
The input to the Rst port must be a real sample-based scalar. The input to the
Clk port can be a real sample-based scalar, or a real frame-based vector
(i.e., single channel). If both inputs are sample-based, they must have the same
sample period. If the Clk input is frame-based, the frame period must equal the
sample period of the Rst input.
The trigger event for both inputs is specified by the Count event pop-up menu,
and can be one of the following:
• Rising edge triggers a count or reset operation when the Clk or Rst input
rises from a negative value to zero or a positive value, or from zero to a
positive value.
• Falling edge triggers a count or reset operation when the Clk or Rst input
falls from a positive value to zero or a negative value, or from zero to a
negative value.
• Either edge triggers a count or reset operation when either a rising or falling
edge (as described above) occurs.
• Nonzero sample triggers a count or reset operation at each sample time that
the Clk or Rst input is not zero.
• Free running disables the Clk port, and enables the Samples per output
frame and Sample time parameters. The block increments or decrements
the counter at a constant interval, Ts, specified by the Sample time
parameter. See “Free-Running Operation” below.
At the start of the simulation, the block sets the counter to the value specified
by the Initial count parameter, which can be any integer in the range defined
by the Counter size parameter. The Counter size parameter allows you to
choose from three standard counter ranges, or to specify an arbitrary counter
limit:
5-104
Counter
Sample-Based Operation
The block operates in sample-based mode when the Clk input is a sample-based
scalar. Sample-based vectors and matrices are not accepted.
When the Count direction parameter is set to Up, a sample-based trigger
event at the Clk input causes the block to increment the counter by one. The
block continues incrementing the counter when triggered until the counter
value reaches the upper count limit (e.g., 255 for an 8-bit counter). At the next
Clk trigger event, the block resets the counter to 0, and resumes incrementing
the counter with the subsequent Clk trigger event.
When the Count direction parameter is set to Down, a sample-based trigger
event at the Clk input causes the block to decrement the counter by one. The
block continues decrementing the counter when triggered until the counter
value reaches 0. At the next Clk trigger event, the block resets the counter to
the upper count limit (e.g., 255 for an 8-bit counter), and resumes
decrementing the counter with the subsequent Clk trigger event.
Between triggering events the block holds the output at its most recent value.
The block resets the counter to its initial state when the trigger event specified
in the Count event menu is received at the optional Rst input. When trigger
events are received simultaneously at the Clk and Rst ports, the block first
resets the counter, and then increments or decrements appropriately. (If you
do not need to reset the counter during the simulation, you can disable the Rst
port by deselecting the Reset input check box.)
The Output pop-up menu provides three options for the output port
configuration of the block icon:
• Count configures the block icon to show a Cnt port, which produces the
current value of the counter as a sample-based scalar with the same sample
period as the inputs.
• Hit configures the block icon to show a Hit port. The Hit port produces zeros
while the value of the counter does not equal the integer Hit value
5-105
Counter
parameter setting. When the counter value does equal the Hit value setting,
the block generates a value of 1 at the Hit port. The output is sample-based
with the same sample period as the inputs.
• Count and Hit configures the block icon with both ports.
Frame-Based Operation
The block operates in frame-based mode when the Clk input is a frame-based
vector (i.e., single channel). Multichannel frame-based inputs are not accepted.
Frame-based operation is the same as sample-based operation, except that the
block increments or decrements the counter by the total number of trigger
events contained in the Clk input frame. A trigger event that is split across two
consecutive frames is counted in the frame that contains the conclusion of the
event. When a trigger event is received at the Rst port, the block first resets the
counter, and then increments or decrements the counter by the number of
trigger events contained in the Clk frame.
The Cnt and Hit outputs are sample-based scalars with sample period equal to
the Clk input frame period.
Free-Running Operation
The block operates in free-running mode when Free running is selected from
the Count event menu.
The Clk input port is disabled in this mode, and the block simply increments or
decrements the counter using the constant sample period specified by the
Sample time parameter, Ts. The Cnt output is a frame-based M-by-1 matrix
containing the count value at each of M consecutive sample times, where M is
specified by the Samples per output frame parameter. The Hit output is a
frame-based M-by-1 matrix containing the hit status (0 or 1) at each of those M
consecutive sample times. Both outputs have a frame period of M∗Ts.
Example In the model below, the Clk port of the Counter block is driven by Simulink’s
Pulse Generator block, and the Rst port is triggered by an N-Sample Enable
block. All of the Counter block’s inputs and outputs are multiplexed into a
single To Workspace block using a 4-port Mux block.
5-106
Counter
To run the model, first select Simulation Parameters from the Simulation
menu, and set the Stop time to 30. Then adjust the block parameters as
described below. (Use the default settings for the Pulse Generator and To
Workspace blocks.)
The figure below shows the first 22 samples of the model’s four-column output,
yout. The first column is the Counter block’s Clk input, the second column is
the block’s Rst input, the third column is the block’s Cnt output, and the fourth
column is the block’s Hit output.
5-107
Counter
...
...
...
You can see that the seventh input samples to both the Clk and Rst ports of the
Counter block represent trigger events (rising edges), so at this time step the
block first resets the counter to its initial value of 5, and then immediately
decrements the count to 4. When the counter reaches its minimum value of 0,
it rolls over to its maximum value of 20 with the following trigger event at the
Cnt port.
5-108
Counter
Dialog Box
Count direction
The counter direction, Up or Down. Tunable, except in Simulink’s external
mode.
Count event
The type of event that triggers the block to increment, decrement, or reset
the counter when received at the Clk or Rst ports. Free running disables
the Clk port, and counts continuously with the period specified by the
Sample time parameter.
Counter size
The range of integer values the block should count through before recycling
to zero.
Maximum count
The counter’s maximum value when Counter size is set to User defined.
Tunable.
5-109
Counter
Initial count
The counter’s initial value at the start of the simulation and after reset.
Tunable, except in Simulink’s external mode.
Output
Selects the output port(s) to enable: Cnt, Hit, or both.
Hit value
The scalar value whose occurrence in the count should be flagged by a 1 at
the (optional) Hit output. This parameter is available when Hit or Count
and Hit are selected in the Output menu. Tunable, except in Simulink’s
external mode.
Reset input
Enables the Rst input port when selected.
Samples per output frame
The number of samples, M, in each output frame. This parameter is
available when Free running is selected in the Count event menu.
Sample time
The output sample period, Ts, in free-running mode. This parameter is
available when Free running is selected in the Count event menu.
5-110
Covariance AR Estimator
Description The Covariance AR Estimator block uses the covariance method to fit an
autoregressive (AR) model to the input data. This method minimizes the
forward prediction error in the least-squares sense.
The input is a sample-based vector (row, column, or 1-D) or frame-based vector
(column only) representing a frame of consecutive time samples from a
single-channel signal, which is assumed to be the output of an AR system
driven by white noise. The block computes the normalized estimate of the AR
system parameters, A(z), independently for each successive input frame.
G G
H ( z ) = ------------ = -------------------------------------------------------------------------------
A(z) –1
1 + a ( 2 )z + … + a ( p + 1 )z
–p
Dialog Box
Estimation order
The order of the AR model, p.
5-111
Covariance AR Estimator
5-112
Covariance Method
Description The Covariance Method block estimates the power spectral density (PSD) of
the input using the covariance method. This method fits an autoregressive
(AR) model to the signal by minimizing the forward prediction error in the
least-squares sense. The order of the all-pole model is the value specified by the
Estimation order parameter, and the spectrum is computed from the FFT of
the estimated AR model parameters.
The input is a sample-based vector (row, column, or 1-D) or frame-based vector
(column only) representing a frame of consecutive time samples from a
single-channel signal. The block’s output (a column vector) is the estimate of
the signal’s power spectral density at Nfft equally spaced frequency points in
the range [0,Fs), where Fs is the signal’s sample frequency.
When Inherit FFT length from input dimensions is selected, Nfft is specified
by the frame size of the input, which must be a power of 2. When Inherit FFT
length from input dimensions is not selected, Nfft is specified as a power of 2
by the FFT length parameter, and the block zero pads or truncates the input
to Nfft before computing the FFT. The output is always sample-based.
See the Burg Method block reference for a comparison of the Burg Method,
Covariance Method, Modified Covariance Method, and Yule-Walker Method
blocks.
Dialog Box
Estimation order
The order of the AR model.
5-113
Covariance Method
5-114
Create Diagonal Matrix
Description The Create Diagonal Matrix block populates the diagonal of the M-by-M matrix
output with the elements contained in the length-M vector input, D. The
elements off the diagonal are zero.
A = diag(D) Equivalent MATLAB code
Dialog Box
5-115
Cumulative Sum
Description The Cumulative Sum block computes the cumulative sum of the row or column
elements in the M-by-N input matrix u.
Columnwise Summing
When the Cumulative Sum along parameter is set to Columns, the block
computes the cumulative sum of the column elements.
y = cumsum(u) % Equivalent MATLAB code
The frame status of the output is the same as the input. For sample-based
inputs, the first row of each successive output is the same as that of the
corresponding input. For convenience, length-M 1-D vector inputs are treated
as M-by-1 column vectors for column-wise summation, and the output is a
length-M 1-D vector.
For frame-based inputs, the first row of the first output is the same as that of
the first input, and the first row of each subsequent output contains the sum of
the first row of the current input (time t) and the last row of the previous output
(time t-Tf).
y 1, j ( t ) = u 1, j ( t ) + y M, j ( t – T f )
Rowwise Summing
When the Cumulative Sum along parameter is set to Rows, the block
computes the cumulative sum of the row elements.
y = cumsum(u,2) % Equivalent MATLAB code
5-116
Cumulative Sum
j
y i, j = ∑ u i, k 1≤j≤N
k=1
The frame status of the output is the same as the input. For both sample-based
and frame-based inputs, the first column of each successive output is the same
as that of the corresponding input. For convenience, length-N 1-D vector inputs
are treated as 1-by-N row vectors for row-wise summation, and the output is a
length-N 1-D vector.
Dialog Box
5-117
dB Conversion
Description The dB Conversion block converts a linearly scaled power or amplitude input
to dB or dBm. The Input signal parameter specifies whether the input is a
power signal or a voltage signal, and the Convert to parameter controls the
scaling of the output. When selected, the Add eps to input to protect
against “log(0) = -inf” parameter adds a value of eps to all power and voltage
inputs. When this option is not enabled, zero-valued inputs produce -inf at the
output. The size and frame status of the output are the same as the input.
Power Inputs
Select Power as the Input signal parameter when the input, u, is a real,
nonnegative, power signal (units of watts). When the Convert to parameter is
set to dB, the block performs the dB conversion
y = 10*log10(u) % Equivalent MATLAB code
When the Convert to parameter is set to dBm, the block performs the dBm
conversion
y = 10*log10(u) + 30
Voltage Inputs
Select Amplitude as the Input signal parameter when the input, u, is a real
voltage signal (units of volts). The block uses the scale factor specified in ohms
by the Load resistance parameter, R, to convert the voltage input to units of
power (watts) before converting to dB or dBm. When the Convert to parameter
is set to dB, the block performs the dB conversion
y = 10*log10(abs(u)^2/R)
When the Convert to parameter is set to dBm, the block performs the dBm
conversion
y = 10*log10(abs(u)^2/R) + 30
5-118
dB Conversion
Dialog Box
Convert to
The logarithmic scaling to which the input is converted, dB or dBm.
Tunable.
Input signal
The type of input signal, Power or Amplitude. Tunable.
Load resistance
The scale factor used to convert voltage inputs to units of power. Tunable.
Add eps to input to protect against “log(0) = -inf”
When selected, adds eps to all input values (power or voltage). Tunable.
5-119
dB Gain
Description The dB Gain block multiplies the input by the decibel values specified in the
Gain parameter. For an M-by-N input matrix u with elements uij, the Gain
parameter can be a real M-by-N matrix with elements gij to be multiplied
element-wise with the input, or a real scalar.
( g ij ⁄ k )
y ij = 10u ij
The value of k is 10 for power signals (select Power as the Input signal
parameter) and 20 for voltage signals (select Amplitude as the Input signal
parameter).
The value of the equivalent linear gain
lin ( g ij ⁄ k )
g ij = 10
is displayed in the block icon below the dB gain value. The size and frame
status of the output are the same as the input.
Dialog Box
Gain
The dB gain to apply to the input, a scalar or a real M-by-N matrix.
Tunable.
Input signal
The type of input signal: Power or Amplitude. Tunable.
5-120
dB Gain
5-121
DCT
Purpose 5DCT
Compute the DCT of the input.
Library Transforms
Description The DCT block computes the unitary discrete cosine transform (DCT) of each
channel in the M-by-N input matrix, u.
y = dct(u) % Equivalent MATLAB code
For both sample-based and frame-based inputs, the block assumes that each
input column is a frame containing M consecutive samples from an
independent channel. The frame size, M, must be a power of two. To work with
other frame sizes, use the Zero Pad block to pad or truncate the frame size to a
power-of-two length.
The output is an M-by-N matrix whose lth column contains the length-M DCT
of the corresponding input column.
M
π ( 2m – 1 ) ( k – 1 )
y ( k, l ) = w ( k ) ∑ u ( m, l ) cos --------------------------------------------,
2M
k = 1, … , M
m=1
where
1
--------- , k=1
w(k) = M
2
----- , 2≤k≤M
M
The output is always sample-based, and the output port rate and data type
(real/complex) are the same as those of the input port.
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are processed as single channels (i.e., as M-by-1 column vectors),
and the output has the same dimension as the input.
5-122
DCT
Dialog Box
5-123
Delay Line
Description The Delay Line block buffers the input samples into a sequence of overlapping
or underlapping matrix outputs. In the most typical use (sample-based inputs),
each output differs from the preceding output by only one sample, as
illustrated below for scalar input.
(input sample period = Tsi) (output sample period = Tsi)
4 3 2 1 0 0 0
9 8 7 6 5 4 3 2 1 5 4 3 2 1 0 0
6 5 4 3 2 1 0
Note that the first output of the block in the example above is all zeros; this is
because the Initial Conditions parameter is set to zero. Due to the latency of
the Delay Line block, all outputs are delayed by one frame, the entries of which
are defined by the Initial Conditions parameter.
Sample-Based Operation
In sample-based operation, the Delay Line block buffers a sequence of
sample-based length-N vector inputs (1-D, row, or column) into a sequence of
overlapping frame-based Mo-by-N matrix outputs, where Mo is specified by the
Delay line size parameter (Mo>1). That is, each input vector becomes a row in
the frame-based output matrix.
At each sample time the new input vector is added in the last row of the output,
so each output overlaps the previous output by Mo-1 samples. Therefore, the
output sample period and frame period is the same as the input sample period
(Tso=Tsi, and Tfo=Tsi). When Mo=1, the input is simply passed through to the
output and retains the same dimension, but becomes frame-based. The latency
of the block always causes an initial delay in the output; the value of the first
output is specified by the Initial conditions parameter (see “Initial
Conditions” below). Sample-based full-dimension matrix inputs are not
accepted.
The Delay Line block’s sample-based operation is similar to that of a Buffer
block with Buffer size equal to Mo and Buffer overlap equal to Mo-1, except
that the Buffer block has a different latency.
5-124
Delay Line
In the model below, the block operates on a sample-based input with a Delay
line size of 3.
ch2 ch3
ch1 ch4
Sample-based input,
t=5 6 1 5 –6 sample period = Tsi
Tsi = 1
t=4 5 1 5 –5
Frame-based output ,
t=3 4 0 5 –4 sample period = T si
first
t=2 3 0 5 –3
first sample-based frame-based
t=1 2 1 5 –2 input output
ch1
ch2
ch3
ch4
ch1
ch2
ch3
ch4
ch1
ch2
ch3
ch4
t=0 1 1 5 –1
1 1 5 –1 0 0 0 0 0 0 0 0 0000
2 1 5 –2 1 1 5 –1 0 0 0 0 0000
3 0 5 –3 2 1 5 –2 1 1 5 –1 0000
The input vectors in the example above do not begin appearing at the output
until the second row of the second matrix due to the block’s latency (see “Initial
Conditions” below). The first output matrix (all zeros in this example) reflects
the block’s Initial conditions setting. As for any sample-based input, the
output frame rate and output sample rate are both equal to the input sample
rate.
Frame-Based Operation
In frame-based operation, the Delay Line block rebuffers a sequence of
frame-based Mi-by-N matrix inputs into a sequence of frame-based Mo-by-N
matrix outputs, where Mo is the output frame size specified by the Delay line
size parameter. Depending on whether Mo is greater than, less than, or equal
to the input frame size, Mi, the output frames can be underlapped or
overlapped. Each of the N input channels is rebuffered independently.
When Mo > Mi, the output frame overlap is the difference between the output
and input frame size, Mo-Mi. When Mo < Mi, the output is underlapped; the
Delay Line block discards the first Mi-Mo samples of each input frame so that
only the last Mo samples are buffered into the corresponding output frame.
5-125
Delay Line
When Mo = Mi, the output data is identical to the input data, but is delayed by
the latency of the block. Due to the block’s latency, the outputs are always
delayed by one frame, the entries of which are specified by the Initial
conditions (see “Initial Conditions” below).
The output frame period is equal to the input frame period (Tfo=Tfi). The output
sample period, Tso, is therefore equal to Tfi/Mo, or equivalently, Tsi(Mi/Mo)
In the model below, the block rebuffers a two-channel frame-based input with
a Delay line size of 3.
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
9 1 5 1 1 1
61 21 00
10 1 6 1 2 1
70 30 00
11 0 7 0 3 0
80 40 00
12 0 8 0 4 0
t=8 t=4 t=0 t=8 t=4 t=0
(Mo=3)
The first output frame in the example is a product of the latency of the Delay
Line block; it is all zeros because the Initial conditions is set to be zero. Since
the input frame size, 4, is larger than the output frame size, 3, only the last
three samples in each input frame are propagated to the corresponding output
frame. The frame periods of the input and output are the same, and the output
sample period is Tsi(Mi/Mo), or 4/3 the input sample period.
Initial Conditions
The Delay Line block’s buffer is initialized to the value specified by the
Initial condition parameter. The block outputs this buffer at the first
simulation step (t=0). If the block’s output is a vector, the Initial condition can
be a vector of the same size, or a scalar value to be repeated across all elements
of the initial output. If the block’s output is a matrix, the Initial condition can
be a matrix of the same size, a vector (of length equal to the number of matrix
rows) to be repeated across all columns of the initial output, or a scalar to be
repeated across all elements of the initial output.
5-126
Delay Line
Dialog Box
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-127
Detrend
Purpose 5Detrend
Remove a linear trend from a vector.
Library Statistics
Description The Detrend block removes a linear trend from the length-M input vector, u,
by subtracting the straight line that best fits the data in the least-squares
sense.
The least-squares line, û = ax + b, is the line with parameters a and b that
minimizes the quantity
M
2
∑ ( ui – ûi )
i=1
for M evenly-spaced values of x, where ui is the ith element in the input vector.
The output, y = u–û, is an M-by-1 column vector (regardless of the input vector
dimension) with the same frame status as the input.
Dialog Box
5-128
Difference
Purpose 5Difference
Compute the element-to-element difference along rows or columns.
Description The Difference block computes the difference between adjacent elements in
rows or columns of the M-by-N input matrix u.
Columnwise Differencing
When the Difference along parameter is set to Columns, the block computes
differences between adjacent column elements.
y = diff(u) % Equivalent MATLAB code
y i, j = u i + 1 , j – u i, j 1 ≤ i ≤ (M – 1)
For convenience, length-M 1-D vector inputs are treated as M-by-1 column
vectors for columnwise differencing, and the output is 1-D.
For frame-based inputs, the output is a frame-based M-by-N matrix whose jth
column has elements
y i, j = u i + 1 , j – u i, j 2≤i≤M
The first row of the first output contains the difference between the first row of
the first input and zero. The first row of each subsequent output contains the
difference between the first row of the current input (time t) and the last row
of the previous input (time t-Tf).
y 1, j ( t ) = u M , j ( t – T f ) – u 1, j ( t )
Rowwise Differencing
When the Difference along parameter is set to Rows, the block computes
differences between adjacent row elements.
y = diff(u,[],2) % Equivalent MATLAB code
5-129
Difference
y i, j = u i, j + 1 – u i, j 1 ≤ j ≤ (N – 1)
The frame status of the output is the same as the input. For convenience,
length-N 1-D vector inputs are treated as 1-by-N row vectors for rowwise
differencing, and the output is 1-D.
Dialog Box
Difference along
The dimension along which to compute element-to-element differences.
Columns specifies columnwise differencing, while Rows specifies rowwise
differencing. Tunable.
5-130
Digital Filter Design
Description The Digital Filter Design block implements a digital FIR or IIR filter that you
design using the Filter Design and Analysis Tool graphical user interface,
referred to as FDATool. The block applies the filter to a discrete-time input
signal and outputs the resulting signal.
To learn how to use FDATool, see the FDATool section of the Signal Processing
Toolbox documentation.
5-131
Digital Filter Design
5-132
Digital Filter Design
5-133
Direct-Form II Transpose Filter
u ( k) ...
b( m ) b(3) b(2) b(1)
Σ z-1
... Σ z-1 Σ z-1 Σ y( k)
zn-1(k) z 2 ( k) z1(k)
-a(n) -a(3) -a(2)
...
This is a canonical form that has the minimum number of delay elements. The
filter order is max(m,n)-1.
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and an M-by-N frame-based matrix input is treated as N
independent channels. In both cases, the block filters each channel
independently over time, and the output has the same size and frame status as
the input.
The filter is specified in the parameter dialog box by its transfer function,
–1 –( m – 1 )
B(z) b1 + b2 z + … + bm + 1 z
H ( z ) = ------------ = -----------------------------------------------------------------------------------
A(z) –1
a1 + a2 z + … + an + 1 z
–( n – 1 )
5-134
Direct-Form II Transpose Filter
Initial Conditions
In its default form, the filter initializes the internal filter states to zero, which
is equivalent to assuming past inputs and outputs are zero. The block also
accepts optional nonzero initial conditions for the filter delays. Note that the
number of filter states (delay elements) per input channel is
max(m,n)-1
• Empty matrix
The empty matrix, [], causes a zero (0) initial condition to be applied to all
delay elements in each filter channel.
• Scalar
The scalar value is copied to all delay elements in each filter channel. Note
that a value of zero is equivalent to setting the Initial conditions parameter
to the empty matrix, [].
• Vector
The vector has a length equal to the number of delay elements in each filter
channel, max(m,n)-1, and specifies a unique initial condition for each delay
element in the filter channel. This vector of initial conditions is applied to
each filter channel.
• Matrix
The matrix specifies a unique initial condition for each delay element, and
can specify different initial conditions for each filter channel. The matrix
must have the same number of rows as the number of delay elements in the
filter, max(m,n)-1, and must have one column per filter channel.
5-135
Direct-Form II Transpose Filter
Dialog Box
Numerator
The filter numerator vector. Tunable; the numerator coefficients can be
adjusted while the simulation runs, but the vector length (i.e., the filter
order) must remain the same.
Denominator
The filter denominator vector. Tunable; the denominator coefficients can
be adjusted while the simulation runs, but the vector length (i.e., the filter
order) must remain the same.
Initial conditions
The filter’s initial conditions, a scalar, vector, or matrix.
5-136
Direct-Form II Transpose Filter
See “Designing Filters with Various Filter Structures” on page 4-6 for related
information.
5-137
Discrete Impulse
Description The Discrete Impulse block generates an impulse (the value 1) at output
sample D+1, where D is specified by the Delay parameter (D ≥ 0). All output
samples preceding and following sample D+1 are zero.
When D is a length-N vector, the block generates an M-by-N matrix output
representing N distinct channels, where frame size M is specified by the
Samples per frame parameter. The impulse for the ith channel appears at
sample D(i)+1. For M=1, the output is sample-based; otherwise, the output is
frame-based.
The Sample time parameter value, Ts, specifies the output signal sample
period. The resulting frame period is M∗Ts.
The Data type parameter allows you to specify an output precision of double,
single, or Boolean. Note, however, that most of the blocks in the DSP Blockset
accept only double precision inputs. Use the Simulink Data Type Conversion
block to convert integer data types to double precision. See “Working with Data
Types” in the Simulink documentation for a complete discussion of data types,
as well as a list of Simulink blocks capable of reduced-precision operations.
• Delay = [0 3 5]
• Sample time = 0.25
• Samples per frame = 4
• Data type = Double
5-138
Discrete Impulse
Run the model and look at the output, yout. The first few samples of each
channel are shown below.
yout(1:10,:)
ans =
1 0 0
0 0 0
0 0 0
0 1 0
0 0 0
0 0 1
0 0 0
0 0 0
0 0 0
0 0 0
Dialog Box
Delay
The number of zero-valued output samples, D, preceding the impulse. A
length-N vector specifies an N-channel output. Tunable.
5-139
Discrete Impulse
Sample time
The sample period, Ts, of the output signal. The output frame period is
M∗Ts. Tunable.
Samples per frame
The number of samples, M, in each output frame. Tunable.
Data type
The precision of the output. Tunable.
See “Creating Signals Using Signal Generator Blocks” on page 3-36 for related
information.
5-140
Downsample
Purpose 5Downsample
Resample an input at a lower rate by deleting samples.
Description The Downsample block resamples each channel of the Mi-by-N input at a rate
K times lower than the input sample rate by discarding K-1 consecutive
samples following each sample passed through to the output. The integer K is
specified by the Downsample factor parameter.
The Sample offset parameter delays the output samples by an integer number
of sample periods, D, where 0 ≤ D < (K-1), so that any of the K possible output
phases can be selected. For example, when you downsample the sequence
1, 2, 3, ... by a factor of 4, you can select from the following four phases.
1,2,3,... 0 0,1,5,9,13,17,21,25,...
1,2,3,... 1 0,2,6,10,14,18,22,26,...
1,2,3,... 2 0,3,7,11,15,19,23,27,...
1,2,3,... 3 0,4,8,12,16,20,24,28,...
The initial zero in each output sequence above is a result of the default zero
Initial condition parameter setting for this example. See “Latency” on
page 5-143 for more on the Initial condition parameter.
Sample-Based Operation
When the input is sample-based, the block treats each of the M∗N matrix
elements as an independent channel, and downsamples each channel over
time. The input and output sizes are identical.
The Sample-based mode parameter determines how the block represents the
new rate at the output. There are two available options:
• Allow multirate
When Allow multirate is selected, the sample period of the sample-based
output is K times longer than the input sample period (Tso = KTsi). The block
is therefore multirate.
5-141
Downsample
The setting of the Frame-based mode popup menu does not affect
sample-based inputs.
Frame-Based Inputs
When the input is frame-based, the block treats each of the N input columns as
a frame containing Mi sequential time samples from an independent channel.
The block downsamples each channel independently by discarding K-1 rows of
the input matrix following each row that it passes through to the output.
The Frame-based mode parameter determines how the block adjusts the rate
at the output to accommodate the reduced number of samples. There are two
available options:
5-142
Downsample
The setting of the Sample-based mode popup menu does not affect
frame-based inputs.
Latency
Zero Latency. The Downsample block has zero tasking latency for the special
combinations of input signal sampling and parameter settings shown in the
table below. In all of these cases the block has single-rate operation.
Zero tasking latency means that the block propagates input sample D+1
(received at t=0) as the first output sample, followed by input sample D+1+K,
input sample D+1+2K, and so on. The Initial condition parameter value is not
used.
5-143
Downsample
Nonzero Latency. The Downsample block is multirate for most settings other
than those in the above table. The amount of latency for multirate operation
depends on input signal sampling and Simulink’s tasking mode, as shown in
the table below.
5-144
Downsample
11 – 11
12 – 12
13 – 13
14 – 14
- Downsample factor = 2
- Sample offset = 1
- Initial condition = [11 -11;12 -12;13 -13;14 -14]
- Frame-based mode = Maintain input frame size
• Configure the Probe blocks by deselecting the Probe width and Probe
complex signal check boxes (if desired).
This model is multirate because there are at least two distinct frame rates, as
shown by the two Probe blocks. To run this model in Simulink’s multitasking
mode, select Fixed-step and discrete from the Type controls in the Solver
5-145
Downsample
panel of the Simulation Parameters dialog box, and select MultiTasking from
the Mode parameter. Additionally, set the Stop time to 30.
Run the model and look at the output, yout. The first few samples of each
channel are shown below.
yout =
11 -11
12 -12
13 -13
14 -14
2 -2
4 -4
6 -6
8 -8
10 -10
12 -12
14 -14
Since we ran this frame-based multirate model in multitasking mode, the first
row of the initial condition matrix appears as the first output sample, followed
by the other three initial condition rows. The second row of the first input
matrix (i.e., row D+1, where D is the Sample offset) appears in the output as
sample 5 (i.e., sample Mi+1, where Mi is the input frame size).
Dialog Box
5-146
Downsample
Downsample factor
The integer factor, K, by which to decrease the input sample rate.
Sample offset
The sample offset, D, which must be an integer in the range [0, K-1].
Initial condition
The value with which the block is initialized for cases of nonzero latency; a
scalar or matrix.
Sample-based mode
The method by which to implement downsampling for sample-based
inputs: Allow multirate (i.e, decrease the output sample rate), or Force
single-rate (i.e., force the output sample rate to match the input sample
rate by repeating every Kth input sample K times at the output).
Frame-based mode
The method by which to implement downsampling for frame-based inputs:
Maintain input frame size (i.e., decrease the frame rate), or Maintain
input frame rate (i.e., decrease the frame size).
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-147
DSP Constant
Description The DSP Constant block generates a signal whose value remains constant
throughout the simulation. The Constant value parameter specifies the
constant to output, and can be any valid MATLAB expression that evaluates to
a scalar, vector, or matrix.
When a row vector or column vector is specified for the Constant value
parameter, and the Interpret vector parameters as 1-D check box is selected,
the dimension of the Constant value vector is disregarded, and the output is a
1-D vector. When the Interpret vector parameters as 1-D check box is not
selected, the output dimension is constrained to match the Constant value
dimension (row or column). When the Constant value is an M-by-N matrix
with M > 1 and N > 1, the output is always M-by-N.
When Sample mode is set to Continuous, the output is a continuous-time
signal. When Sample mode is set to Discrete, the Sample time and
Frame-based output parameters are enabled, and signal has the discrete
output period specified by the Sample time parameter.
When the Frame-based output check box is selected, the output is
frame-based; otherwise, the output is sample-based. Because a 1-D vector
signal cannot be frame-based, an active Frame-based output setting overrides
an active Interpret vector parameters as 1-D setting, and the output is a
frame-based column vector (regardless of the actual Constant value vector
dimension).
5-148
DSP Constant
Dialog Box
Constant value
The constant to generate. Tunable; values entered here can be tuned, but
their dimensions must remain fixed.
Interpret vector parameters as 1-D
When selected, generates 1-D vector outputs for Constant value settings
with vector dimension; when unselected, generates 2-D vector outputs for
Constant value settings with vector dimension. An active Interpret
vector parameters as 1-D setting is overridden by an active Frame-based
output setting.
Sample mode
The sample mode of the output, Discrete for a discrete-time signal or
Continuous for a continuous-time signal.
Sample time
The discrete sample period for sample-based outputs. When the
Frame-based output parameter is checked, this parameter is named
Frame period, and is the discrete frame period for the frame-based output.
This parameter is enabled when Discrete is selected in the Sample mode
menu.
Frame-based output
Specifies frame-based output when selected. This parameter is enabled
when Discrete is selected in the Sample mode menu
5-149
DSP Constant
Supported (MATLAB commands for casting values to certain data types are provided in
Data Types parentheses.)
Boolean (boolean)
8-, 16-, and 32-bit signed integer (int8, int16, int32)
8-, 16-, and 32-bit unsigned integer (uint8, uint16, uint32)
Single-precision floating point (single)
Double-precision floating point (double)
See “Creating Signals Using Constant Blocks” on page 3-33 for related
information.
5-150
Dyadic Analysis Filter Bank
Description The Dyadic Analysis Filter Bank block decomposes a broadband signal into a
collection of successively more bandlimited components by repeatedly dividing
the frequency range. The typical (asymmetric) n-level filter bank structure is
shown below.
Asymmetric Filter Bank, n Levels
u HP ↓2 2Ts y1
LP ↓2 HP ↓2 4Ts y2
LP ↓2 HP ↓2 8Ts y3
LP ↓2 ... HP ↓2 yn
Tsi = Ts LP ↓2 yn+1
At each level, the low-frequency output of the previous level is decomposed into
adjacent high- and low-frequency subbands by a highpass (HP) and lowpass
(LP) filter pair. Each of the two output subbands is half the bandwidth of the
input to that level (hence “dyadic”). The bandlimited output of each filter is
maximally decimated by a factor of 2 to preserve the bit rate of the original
signal. In wavelet applications (see below) the aliasing introduced by the
decimation stage can be exactly canceled in reconstruction.
The Lowpass FIR filter coefficients and Highpass FIR filter coefficients
parameters specify (respectively) the filter coefficients to be used for every
lowpass and highpass direct-form II transpose filter in the filter bank. The
values of these coefficients are typically computed using the wavelet family
5-151
Dyadic Analysis Filter Bank
functions in the Wavelet Toolbox (see the Wavelet Toolbox documentation for
more information).
Tree Structure
The Tree structure parameter specifies an asymmetric (or wavelet) tree, as
shown above, or a symmetric structure, as shown below. Note that the
symmetric structure decomposes both the high- and low-frequency subbands at
each level, whereas the asymmetric structure only decomposes the
low-frequency bands.
Asymmetric Tree. The asymmetric structure in the first figure (Tree structure
set to Asymmetric) has n+1 outputs, where n is the Number of levels
parameter value. The sample rate and bandwidth of the top output are half the
input sample rate and bandwidth. The sample rate and bandwidth of each
additional output (except the last) are half that of the output from the previous
level. In general, for an input with sample period Tsi = Ts, and bandwidth BW,
output yk has sample period Tso,k and bandwidth BWk.
k
( 2 )T s (1 ≤ k ≤ n)
T so, k =
( 2 n )T (k = n + 1)
s
BW
---------- (1 ≤ k ≤ n)
2
k
BW k =
BW
---------- (k = n + 1)
n
2
Note that in frame-based mode, the change in the sample period of output yk is
reflected by its frame size, Mo,k, rather than by its frame rate.
Mi
------- (1 ≤ k ≤ n)
2
k
M o, k =
Mi
------- (k = n + 1)
n
2
5-152
Dyadic Analysis Filter Bank
The bottom two outputs (yn and yn+1) share the same sample period,
bandwidth, and frame size because they originate at the same tree level.
Symmetric Tree. The symmetric structure shown below (Tree structure set to
Symmetric) has 2n outputs, where n is the Number of levels parameter value.
HP ↓2 ...
LP ↓2 y2
HP ↓2
HP ↓2 y3
LP ↓2 ...
LP ↓2 y4
u
HP ↓2 y5
HP ↓2 ...
LP ↓2 y6
LP ↓2
HP ↓2 y7
LP ↓2 ...
Tsi = Ts
LP ↓2 y2n
The sample rate and bandwidth of every output are reduced by a factor of 2n
from the input sample rate and bandwidth. For an input with sample period
Tsi = Ts, and bandwidth BW, output yk has sample period Tso,k and
bandwidth BWk.
n n
T so, k = ( 2 )T s (1 ≤ k ≤ 2 )
BW n
BW k = ---------- (1 ≤ k ≤ 2 )
n
2
5-153
Dyadic Analysis Filter Bank
Mi n
M o, k = ------- (1 ≤ k ≤ 2 )
n
2
Sample-Based Operation
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and the block filters each channel independently over time. The
output at each port is the same size as the input, one output channel for each
input channel. As described earlier, for the asymmetric tree structure, each
output port has a different sample period.
The figure below shows the input and output sample periods for a 64-channel
sample-based input to a three-level filter bank. The input has a period of 1, so
the fastest output has a period of 2.
Tso = 2
Tso = 4
Tsi = 1
Tso = 8
Tso = 8
Frame-Based Operation
An Mi-by-N frame-based matrix input is treated as N independent channels,
and the block filters each channel independently over time. The input frame
size Mi must be a multiple of 2n, and n is the number of filter bank levels. For
example, a frame size of 8 would be appropriate for a three-level tree (23=8).
The number of columns in each output is the same as the number of columns
in the input.
Each output port has the same frame period as the input. The reduction in the
output sample rates results from the smaller output frame sizes, as shown in
the example below for a four-channel input to a three-level asymmetric tree.
5-154
Dyadic Analysis Filter Bank
Tso = 1/32)
Tso = 1/8)
Applications
Wavelets. The primary application for dyadic analysis filter banks is coding for
data compression using wavelets.
At the transmitting end, the output of the dyadic analysis filter bank is fed to
a lossy compression scheme, which typically assigns the number of bits for each
filter bank output in proportion to the relative energy in that frequency band.
This represents the more powerful signal components by a greater number of
bits than the less powerful signal components.
lossy
decoding
coding
At the receiving end, the transmission is decoded and fed to a dyadic synthesis
filter bank to reconstruct the original signal. The filter coefficients of the
complementary analysis and synthesis stages are designed to cancel aliasing
introduced by the filtering and resampling.
fy
k
Q = -------------
-
BW y k
and f y is the midpoint frequency of the band occupied by output yk. The
k
frequency axis of a scalogram therefore has logarithmic divisions like those
shown below, where Fs is the sample rate (1/Ts).
5-155
Dyadic Analysis Filter Bank
Fs/32
Fs/64
Fs/128
Fs/256
0
Latency
Zero Latency. The Dyadic Analysis Filter Bank block has no tasking latency for
frame-based operation, which is always single-rate. The block therefore
analyzes the first input sample (received at t=0) to produce the first output
sample at each port.
Nonzero Latency. The Dyadic Analysis Filter Bank block has tasking latency
only for sample-based operation, which is always multirate. As shown in the
table below, the amount of latency, D, depends on the structure (symmetric or
asymmetric) of the n-level tree used by the block.
In the above cases, the block repeats a zero initial condition in each channel for
the first D output samples. For example, in single-tasking mode, the
asymmetric tree structure generates 2n-1 zero-valued output samples at each
port in each channel before propagating the first analyzed input sample
(computed from the input received at t=0).
See “Excess Algorithmic Delay (Tasking Latency)” in Chapter 3 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
5-156
Dyadic Analysis Filter Bank
Dialog Box
5-157
Dyadic Analysis Filter Bank
5-158
Dyadic Synthesis Filter Bank
Description The Dyadic Synthesis Filter Bank block typically reconstructs a signal that
was decomposed by the Dyadic Analysis Filter Bank block. The reconstruction
or synthesis process is the inverse of the analysis process, and restores the
original signal by upsampling, filtering, and summing the bandlimited inputs
in stages corresponding to the analysis process. The typical (asymmetric)
n-level filter bank structure is shown below.
Asymmetric Filter Bank, n Levels
u1 2Ts ↑2 HP Σ y
u2 4Ts ↑2 HP Σ ↑2 LP
u3 8Ts ↑2 HP Σ ↑2 LP
un ↑2 HP Σ ... ↑2 LP
un+1 ↑2 LP Tso = Ts
5-159
Dyadic Synthesis Filter Bank
highpass and lowpass direct-form II transpose filter in the filter bank. The
values of these coefficients are typically computed together with the dyadic
analysis coefficients using the wavelet family functions in the Wavelet Toolbox
(see the Wavelet Toolbox documentation for more information).
Tree Structure
The Tree structure parameter specifies an asymmetric (or wavelet) tree, as
shown above, or a symmetric structure, as shown below. Note that the
symmetric structure reconstructs a signal that was symmetrically decomposed
by the Dyadic Analysis Filter Bank block (i.e., both the high- and low-frequency
subbands were divided at each level). The asymmetric structure reconstructs a
signal that was asymmetrically decomposed by the Dyadic Analysis Filter
Bank block (i.e., only the low-frequency subbands were divided at each level).
Asymmetric Tree. The asymmetric structure in the first figure (Tree structure
set to Asymmetric) has n+1 inputs, where n is the Number of levels
parameter value. The sample rate and bandwidth of the output are twice the
sample rate and bandwidth of the top input. The sample rate and bandwidth
of each additional input (except the last) should be half that of the input to the
previous level.
BW k
BW k + 1 = ------------- 1≤k<n
2
The bottom two inputs (un and un+1) should have the same sample rate and
bandwidth since they are processed by the same level.
T si, n + 1 = T si, n
BW n + 1 = BW n
Note that in frame-based mode, the change in the sample period of input uk is
reflected by its frame size, Mi,k, rather than by its frame rate.
M i, k
M i, k + 1 = ------------ 1≤k<n
2
5-160
Dyadic Synthesis Filter Bank
M i, n + 1 = M i, n
Symmetric Tree. The symmetric structure shown below (Tree structure set to
Symmetric) has 2n inputs, where n is the Number of levels parameter value.
Symmetric Filter Bank, n Levels
u1 ↑2 HP
Σ ... ↑2 HP
u2 ↑2 LP
Σ ↑2 HP
u3 ↑2 HP
Σ ... ↑2 LP
u4 ↑2 LP
Σ y
u5 ↑2 HP
Σ ... ↑2 HP
u6 ↑2 LP
Σ ↑2 LP
u7 ↑2 HP
Σ ... ↑2 LP
Tso = Ts
u2n ↑2 LP
HP: highpass filter with fc ≈ 1/2 Nyquist
LP: lowpass filter with fc ≈ 1/2 Nyquist
Tsi = (2n)Ts for all 2n inputs ↑2: upsample by 2
The sample rate and bandwidth of the output are a factor of 2n higher than the
sample rate and bandwidth of the inputs, which are all equal.
Sample-Based Operation
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and the block filters each channel independently over time. The
output is the same size as the input at each port, one output channel for each
input channel. As described earlier, for the asymmetric tree structure, each
input port has a different sample period.
5-161
Dyadic Synthesis Filter Bank
The figure below shows the input and output sample periods for the four
64-channel sample-based inputs to a three-level filter bank. The fastest input
has a period of 2, so the output period is 1.
Tsi = 2
Tsi = 4
Tso = 1
Tsi = 8
Tsi = 8
Frame-Based Operation
An Mi-by-N frame-based matrix input is treated as N independent channels,
and the block filters each channel independently over time. The number of
columns in the output is the same as the number of columns in the input.
All inputs must have the same frame period, which is also the output frame
period. The different input sample rates should be represented by the input
frame sizes: If the input to the top port has frame size Mi, the input to the
second-from-top port should have frame size Mi/2, the input to the
third-from-top port should have frame size Mi/4, and so on. The input to the
bottom port should have the same frame size as the second-from-bottom port.
The increase in the sample rate of the output is also represented by its frame
size, which is twice the largest input frame size.
The relationship between sample periods, frame periods, and frame sizes is
shown below for a four-channel frame-based input to a three-level filter bank.
(Tsi=1/32)
(Tsi=1/16) Tfo = 1
Tfi = 1
Tso = 1/64
(Tsi=1/8)
(Tsi=1/8)
5-162
Dyadic Synthesis Filter Bank
Applications
The primary application for asymmetric dyadic synthesis filter banks is coding
for compression using wavelets.
At the transmitting end, the output of a dyadic analysis filter bank is fed to a
lossy compression scheme, which typically assigns the number of bits for each
filter bank output in proportion to the relative energy in that frequency band.
This represents the more powerful signal components by a greater number of
bits than the less powerful signal components.
lossy
decoding
coding
At the receiving end, the transmission is decoded and fed to the dyadic
synthesis filter bank to reconstruct the original signal. The filter coefficients of
the complementary analysis and synthesis stages are designed to cancel
aliasing introduced by the filtering and resampling.
Latency
Zero Latency. The Dyadic Synthesis Filter Bank block has no tasking latency for
frame-based operation, which is always single-rate. The block therefore uses
the first input samples (received at t=0) to synthesize the first output sample.
Nonzero Latency. The Dyadic Synthesis Filter Bank block has tasking latency
only for sample-based operation, which is always multirate. As shown in the
table below, the amount of latency, D, depends on the structure (symmetric or
asymmetric) of the n-level tree used by the block.
In the above cases, the block repeats a zero initial condition in each channel for
the first D output samples. For example, in single-tasking mode the
5-163
Dyadic Synthesis Filter Bank
Dialog Box
5-164
Dyadic Synthesis Filter Bank
5-165
Edge Detector
Description The Edge Detector block generates an impulse (the value 1) in a given output
channel when the corresponding channel of the input transitions from zero to
a nonzero value. Otherwise, the block generates zeros in each channel.
The output has the same dimension and sample rate as the input. If the input
is frame-based, the output is frame-based; otherwise, the output is
sample-based. For frame-based input, an edge that is split across two
consecutive frames (i.e., a zero at the bottom of the first frame, and a nonzero
value at the top of the following frame) is counted in the frame that contains
the nonzero value.
Example In the model below, the Edge Detector block locates the edges (zero to nonzero
transitions) in a two-channel frame-based input with frame size 3. The two
input channels are horizontally concatenated with the two output channels to
create the four-channel workspace variable yout.
Adjust the block parameters as described below. (Use the default settings for
the To Workspace block.)
5-166
Edge Detector
Input Output
First –5 0 00
input First output
–4 1 01 ch2 edge
–3 0 00
–2 0 00
–1 2 01 ch2 edge
0 0 00
1 0 10 ch1 edge
Simulation time
2 0 00
3 3 01 ch2 edge
4 0 00
5 0 00
0 0 00
Dialog Box
5-167
Event-Count Comparator
Description The Event-Count Comparator block records the number of nonzero inputs to
the Data port during the period that the block is enabled by a high signal (the
value 1) at the interval (Int) port. Both inputs must be scalars, and the Int
input must be sample-based.
When the number of accumulated nonzero inputs first equals the Event
threshold setting, the block waits one additional sample interval, and then
sets the output high (1). The block holds the output high until recording is
restarted by a low-to-high (0-to-1) transition at the Int port.
If the input to the Data port is frame-based, the output is frame-based;
otherwise, the output is sample-based.
Example In the model below, the Event-Count Comparator block (Event threshold = 3)
detects two threshold crossings in the input to the Data port, one at sample 4
and one at sample 12.
All inputs and outputs are multiplexed into the workspace variable yout,
whose contents are shown in the figure below. The two left columns in the
illustration show the inputs to the Data and Int ports, the center column shows
the state of the block’s internal counter, and the right column shows the block’s
output.
5-168
Event-Count Comparator
...
...
...
Dialog Box
Event threshold
The value against which to compare the number of nonzero inputs.
Tunable.
5-169
Extract Diagonal
5Extract Diagonal
Description The Extract Diagonal block populates the 1-D output vector with the elements
on the main diagonal of the M-by-N input matrix A.
D = diag(A) Equivalent MATLAB code
Dialog Box
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-170
Extract Triangular Matrix
Description The Extract Triangular Matrix block creates a triangular matrix output from
the upper or lower triangular elements of an M-by-N input matrix. A length-M
1-D vector input is treated as an M-by-1 matrix.
The Extract parameter selects between the two components of the input:
• Upper – Copies the elements on and above the main diagonal of the input
matrix to an output matrix of the same size. The first row of the output
matrix is therefore identical to the first row of the input matrix. The
elements below the main diagonal of the output matrix are zero.
• Lower – Copies the elements on and below the main diagonal of the input
matrix to an output matrix of the same size. The first column of the output
matrix is therefore identical to the first column of the input matrix. The
elements above the main diagonal of the output matrix are zero.
Example The example below shows the extraction of upper and lower triangles from a
5-by-3 input matrix.
1 2 3 1 2 3
4 5 6 0 5 6
7 8 9 0 0 9
10 11 12 0 0 0
13 14 15 0 0 0
1 2 3 1 0 0
4 5 6 4 5 0
7 8 9 7 8 9
10 11 12 10 11 12
13 14 15 13 14 15
5-171
Extract Triangular Matrix
Dialog Box
Extract
The component of the matrix to copy to the output, upper triangle or lower
triangle. Tunable, except in Simulink’s external mode.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-172
FFT
Purpose 5FFT
Compute the FFT of the input.
Library Transforms
Description The FFT block computes the fast Fourier transform (FFT) of each channel in
the M-by-N or length-M input, u, where M must be a power of two. To work
with other input sizes, use the Zero Pad block to pad or truncate the length-M
dimension to a power-of-two length. The output is always complex-valued and
sample-based (it is unoriented 1-D vectors for unoriented inputs).
y = fft(u,M) % Equivalent MATLAB code
The kth entry of the lth output channel, y(k, l), is the kth point of the M-point
discrete Fourier transform (DFT) of the lth input channel.
M
y ( k, l ) = ∑ u ( m, l )e – j 2π ( m – 1 ) ( k – 1 ) ⁄ M k = 1 , …, M (5-2)
m=1
For information on block output characteristics and how to configure the block
computation methods, see the following sections:
Note For M-by-N and length-M inputs, M must be a power of two. To work
with other input sizes, use the Zero Pad block to pad or truncate the length-M
5-173
FFT
5-174
FFT
Click here in the MATLAB Help Browser to open a Simulink model based on
the following diagram.
Effects of Block Input’s Size, Dimension, and Frame Status on Block Output
1 2 3 10 20 30
2 4 6 – 2 + 2i – 4 + 4i – 6 + 6i
Frame-based 4-by-3 input Sample-based 4-by-3 output –2 –4 –6
3 6 9
4 8 12 – 2 – 2i – 4 – 4i – 6 – 6i
Compute FFT of each column
1 2 3 10 20 30
2 4 6 – 2 + 2i – 4 + 4i – 6 + 6i
Sample-based 4-by-3 nonrow input Sample-based 4-by-3 output –2 –4 –6
3 6 9
4 8 12 – 2 – 2i – 4 – 4i – 6 – 6i
Compute FFT of each column
( 1, 2, 3, 4 ) Unoriented length-4 1-D vector input Unoriented length-4 1-D vector output ( 10, – 2 + 2i, – 2, – 2 – 2i )
5-175
FFT
Note Linearly ordering the output requires extra data sorting manipulation,
so in some situations it may be better to output in bit-reversed order as
illustrated in the example, “Use of Outputs in Bit-Reversed Order” on
page 5-179.
The next diagram illustrates the difference between linear and bit-reversed
outputs. Note that output values in linear and bit-reversed order are the same;
only the order in which they appear in the columns differs.
Input must be Output in Output in
in linear order linear order bit-reversed order
1 36 w0 w0 36 wk is the kth frequency at which
2 – 4 + 9.7i w1 w4 –4
the block computes the FFT. For an
3 – 4 + 4i w2 w2 – 4 + 4i
Output can – 4 + 1.7i w3 w6 – 4 – 4i N-point FFT,
4
be ordered
wk = 2πk/N
5 –4 w4 w1 – 4 + 9.7i
k = 0, 1, ..., N-1
6 in two ways – 4 – 1.7i w5 w5 – 4 – 1.7i
7 – 4 – 4i w6 w3 – 4 + 1.7i
8 – 4 – 9.7i w7 w7 – 4 – 9.7i
and indicate the
Bit reverse the frequencies at which the block
frequency indices computes the FFT to get the output
5-176
FFT
5-177
FFT
Twiddle factor computation Sine and Cosine Computation Effect on Block Performance
Parameter Setting Method
Table lookup The block computes and stores The block usually runs much
the trigonometric values before more quickly, but requires
the simulation starts, and extra memory for storing the
retrieves them during the precomputed trigonometric
simulation. When you generate values. You can optimize the
code from the block, the table for memory
processor running the generated consumption or speed, as
code stores the trigonometric described in “Optimizing the
values computed by the block, Table of Trigonometric
and retrieves the values during Values” below.
code execution.
Trigonometric fcn The block computes sine and The block usually runs more
cosine values during the slowly, but does not need
simulation. When you generate extra data memory. For code
code from the block, the generation, the block
processor running the generated requires a support library to
code computes the sine and emulate the trigonometric
cosine values while the code functions, increasing the size
runs. of the generated code.
5-178
FFT
the table of trigonometric values for speed or memory by varying the number
of table entries as summarized in the following table.
Example Use of Outputs in Bit-Reversed Order. The FFT block runs more quickly when it
outputs in bit-reversed order. You can often use an output in bit-reversed order
when your model also uses the IFFT block (the IFFT block allows you to
indicate whether its input is in bit-reversed or linear order). For instance, set
the FFT block to output in bit-reversed order when you want to filter or
5-179
FFT
5-180
FFT
Dialog Box
5-181
FFT
5-182
Filter Realization Wizard
Description The Filter Realization Wizard is a tool for automatically creating filter
realizations with specific architectures. The Wizard’s interface allows you to
specify the filter’s structure and coefficients, the type of data to be filtered, and
optimization criteria for the design. The Wizard then builds the specified filter
as a subsystem composed of Sum, Gain, and Unit Delay blocks. You can specify
the name of the subsystem (“Filter” is the default) and whether it is placed in
the current model or in a new model.
The Architecture panel in the Wizard’s interface allows you to select from the
following realizations.
Architecture Parameters
The Optimization panel in the Wizard’s interface lets you choose to optimize
for zero and unity gains. Zero-gain optimization removes zero-gain paths from
the filter structure, and unity-gain optimization substitutes a wire (short
circuit) for unity gains.
Type a name for the new filter block in the Block Name text field, and select
where the block should be placed from the Destination pop-up menu. Within
a model, the Filter subsystem operates on a sample-based signal (similar to
Simulink’s Discrete Filter block), filtering each channel over time. Double-click
on the subsystem to open it; you can then modify the gains or the filter
structure to suit your needs.
5-183
Filter Realization Wizard
Fixed-Point Options
By default, the filter constructed by the Filter Realization Wizard operates
using the Simulink standard double-precision arithmetic. If you have the
Fixed-Point Blockset installed on your system, you have the additional option
of building the filter to operate using single-precision or fixed-point arithmetic.
Select the option you want from the Data Type panel:
Examples The examples below illustrate some of the common architectures available
through the Filter Realization Wizard:
5-184
Filter Realization Wizard
5 Press the Build button to create the specified filter subsystem in a new
model window.
5-185
Filter Realization Wizard
6 Double-click the new Butter LPF block to see the Direct-Form II filter
realization that the Wizard created.
5-186
Filter Realization Wizard
3 Type a name for the new filter subsystem in the Block Name field. The
example uses Butter SOS.
4 Press the Build button to create the specified filter subsystem in a new
model window.
5 Double-click the new Butter SOS block to see the Direct-Form II filter
realization that the Wizard created.
1 At the MATLAB command line, compute the coefficients for the Nth order
sections by entering
[b1,a1] = butter(4,.25);
[b2,a2] = butter(3,.25);
2 Configure the Wizard to use these coefficient vectors as the numerator and
denominator of a Direct-Form II structure:
- Select Direct-Form II from the Type menu.
- Type {b1,b2} in the Numerator text field. Note that the numerator
coefficient vector for each section is entered as an element in a cell array.
Since this is a two-section filter, a two-cell array is specified in the
5-187
Filter Realization Wizard
Numerator field. The two filter sections do not need to have the same
order.
- Type {a1,a2} in the Denominator text field. Note that the denominator
coefficient vector for each section is also entered as an element in a cell
array. Since this is a two-section filter, a two-cell array is specified in the
Denominator field.
3 Type a name for the new filter subsystem in the Block Name field. The
example uses Butter Sections.
4 Press the Build button to create the specified filter subsystem in a new
model window.
5 Double-click the new Butter Sections block to see the Direct-Form II filter
realization that the Wizard created.
1 At the MATLAB command line, compute the lattice and ladder coefficients
(k and v, respectively) for the ARMA filter.
[b,a] = butter(4,.25);
5-188
Filter Realization Wizard
[k,v] = tf2latc(b,a);
5-189
Filter Realization Wizard
Dialog Box
Numerator
The numerator coefficients for the direct-form I and II structures, specified
as a vector or variable name.
Denominator
The denominator coefficients for the direct-form I and II structures,
specified as a vector or variable name.
Coefficients
The coefficients for the symmetric FIR structure, specified as a vector or
variable name.
5-190
Filter Realization Wizard
Lattice Coeffs
The lattice coefficients for the lattice MA/AR/ARMA structures, specified
as a vector or variable name.
Ladder Coeffs
The ladder coefficients for the lattice ARMA structure, specified as a vector
or variable name.
Optimize for zero gains
Enables zero-gain optimization (when checked) by removing zero-gain
paths from the filter structure.
Optimize for unity gains
Enables unity-gain optimization (when checked) by substituting a wire
(short circuit) for unity gains.
Destination
The location where the new filter block should be created.
Block name
The name of the new filter block.
Build
Generate the filter.
Data type
The precision of the data that the filter will process. Built-in data types,
when selected, configures the block to build the filter using
double-precision Simulink blocks. Single precision and Fixed-point
configure the block to build the filter using Fixed-Point Blockset blocks.
Fixed-point
Options for fixed-point filter construction. See the Fixed-Point Blockset
documentation.
5-191
Filter Realization Wizard
See “Designing Filters with Various Filter Structures” on page 4-6 for related
information.
5-192
FIR Decimation
Description The FIR Decimation block resamples the discrete-time input at a rate K times
slower than the input sample rate, where the integer K is specified by the
Decimation factor parameter. This process consists of two steps:
• The block filters the input data using a direct-form II transpose FIR filter.
• The block downsamples the filtered data to a lower rate by discarding K-1
consecutive samples following every sample retained.
The FIR Decimation block implements the above FIR filtering and
downsampling steps together using a polyphase filter structure, which is more
efficient than straightforward filter-then-decimate algorithms. The output of
the decimator is the first phase of the polyphase filter.
The FIR filter coefficients parameter specifies the numerator coefficients of
the FIR filter transfer function H(z).
–1 –( m – 1 )
H ( z ) = B ( z ) = b1 + b2 z + … + bm z
The length-m coefficient vector, [b(1) b(2) ... b(m)], can be generated by
one of the filter design functions in the Signal Processing Toolbox, such as the
fir1 function used in the example below. The filter should be lowpass with
normalized cutoff frequency no greater than 1/K. All filter states are internally
initialized to zero.
Sample-Based Operation
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and the block decimates each channel over time. The output sample
period is K times longer than the input sample period (Tso = KTsi), and the
input and output sizes are identical.
Frame-Based Operation
An Mi-by-N frame-based matrix input is treated as N independent channels,
and the block decimates each channel over time. The Framing parameter
determines how the block adjusts the rate at the output to accommodate the
reduced number of samples. There are two available options:
5-193
FIR Decimation
5-194
FIR Decimation
Latency
Zero Latency. The FIR Decimation block has zero tasking latency for all
single-rate operations. The block is single-rate for the particular combinations
of sampling mode and parameter settings shown in the table below.
Note that in sample-based mode, single-rate operation occurs only in the trivial
case of factor-of-1 decimation.
The block also has zero latency for sample-based multirate operations in
Simulink’s single-tasking mode. Zero tasking latency means that the block
propagates the first filtered input sample (received at t=0) as the first output
sample, followed by filtered input samples K+1, 2K+1, and so on.
Nonzero Latency. The FIR Decimation block is multirate for all settings other
than those in the above table. The amount of latency for multirate operation
depends on Simulink’s tasking mode and the block’s sampling mode, as shown
in the table below.
5-195
FIR Decimation
samples K+1, 2K+1, and so on. See the example below for an illustration of this
case.
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
Examples Example 1
Construct the frame-based model shown below.
5-196
FIR Decimation
or, equivalently,
–1 –2 –3
H ( z ) = B ( z ) = 0.0386 + 0.04614z + 0.04614z + 0.0386z
• Configure the Probe blocks by deselecting the Probe width, Probe complex
signal, and Probe signal dimensions check boxes (if desired).
This model is multirate because there are at least two distinct sample rates, as
shown by the two Probe blocks. To run this model in Simulink’s multitasking
mode, select Fixed-step and discrete from the Type controls in the Solver
panel of the Simulation Parameters dialog box, and select MultiTasking from
the Mode parameter. Also set the Stop time to 30.
Run the model and look at the output, yout. The first few samples of each
channel are shown below.
yout =
0 0
0 0
0 0
0 0
0.0386 -0.0386
1.5000 -1.5000
3.5000 -3.5000
5.5000 -5.5000
7.5000 -7.5000
9.5000 -9.5000
11.5000 -11.5000
Since we ran this frame-based multirate model in multitasking mode, the first
four (Mi) output rows are zero. The first filtered input matrix row appears in
the output as sample 5 (i.e., sample Mi+1).
Example 2
The dspmrf_menu demo illustrates the use of the FIR Decimation block in a
number of multistage multirate filters.
5-197
FIR Decimation
Dialog Box
5-198
FIR Decimation
5-199
FIR Interpolation
Description The FIR Interpolation block resamples the discrete-time input at a rate
L times faster than the input sample rate, where the integer L is specified by
the Interpolation factor parameter. This process consists of two steps:
• The block upsamples the input to a higher rate by inserting L-1 zeros
between samples.
• The block filters the upsampled data with a direct-form II transpose FIR
filter.
The FIR Interpolation block implements the above upsampling and FIR
filtering steps together using a polyphase filter structure, which is more
efficient than straightforward upsample-then-filter algorithms.
The FIR filter coefficients parameter specifies the numerator coefficients of
the FIR filter transfer function H(z).
–1 –( m – 1 )
H ( z ) = B ( z ) = b1 + b2 z + … + bm z
The coefficient vector, [b(1) b(2) ... b(m)], can be generated by one of the
filter design functions in the Signal Processing Toolbox (such as fir1), and
should have a length greater than the interpolation factor (m>L). The filter
should be lowpass with normalized cutoff frequency no greater than 1/L. All
filter states are internally initialized to zero.
Sample-Based Operation
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and the block interpolates each channel over time. The output
sample period is L times shorter than the input sample period (Tso = Tsi/L), and
the input and output sizes are identical.
Frame-Based Operation
An Mi-by-N frame-based matrix input is treated as N independent channels,
and the block decimates each channel over time. The Framing parameter
determines how the block adjusts the rate at the output to accommodate the
added samples. There are two available options:
5-200
FIR Interpolation
5-201
FIR Interpolation
Latency
Zero Latency. The FIR Interpolation block has zero tasking latency for all
single-rate operations. The block is single-rate for the particular combinations
of sampling mode and parameter settings shown in the table below.
Note that in sample-based mode, single-rate operation occurs only in the trivial
case of factor-of-1 interpolation.
The block also has zero latency for sample-based multirate operations in
Simulink’s single-tasking mode. Zero tasking latency means that the block
propagates the first filtered input (received at t=0) as the first input sample,
followed by L-1 interpolated values, the second filtered input sample, and so
on.
Nonzero Latency. The FIR Interpolation block is multirate for all settings other
than those in the above table. The amount of latency for multirate operation
depends on Simulink’s tasking mode and the block’s sampling mode, as shown
in the table below.
5-202
FIR Interpolation
Example Example 1
Construct the frame-based model shown below.
5-203
FIR Interpolation
or, equivalently,
–1 –2 –3
H ( z ) = B ( z ) = 0.0386 + 0.04614z + 0.04614z + 0.0386z
• Configure the Probe blocks by deselecting the Probe width, Probe complex
signal, and Probe signal dimensions check boxes (if desired).
This model is multirate because there are at least two distinct sample rates, as
shown by the two Probe blocks. To run this model in Simulink’s multitasking
mode, select Fixed-step and discrete from the Type controls in the Solver
panel of the Simulation Parameters dialog box, and select MultiTasking from
the Mode parameter. Also set the Stop time to 30.
Run the model and look at the output, yout. The first few samples of each
channel are shown below.
yout =
0 0
0 0
0 0
0 0
0.0386 -0.0386
0.4614 -0.4614
0.5386 -0.5386
0.9614 -0.9614
1.0386 -1.0386
Since we ran this frame-based multirate model in multitasking mode, the first
four (Mi) output rows are zero. The first filtered input matrix row appears in
the output as sample 5 (i.e., sample Mi+1). Every second row is an interpolated
value.
Example 2
The dspintrp demo provides another simple example, and the dspmrf_menu
demo illustrates the use of the FIR Interpolation block in a number of
multistage multirate filters.
5-204
FIR Interpolation
Dialog Box
5-205
FIR Interpolation
5-206
FIR Rate Conversion
Description The FIR Rate Conversion block resamples the discrete-time input to a period
K/L times the input sample period, where the integer K is specified by the
Decimation factor parameter and the integer L is specified by the
Interpolation factor parameter. The resampling process consists of the
following steps:
• The block upsamples the input to a higher rate by inserting L-1 zeros
between input samples.
• The upsampled data is passed through a direct-form II transpose FIR filter.
• The block downsamples the filtered data to a lower rate by discarding K-1
consecutive samples following each sample retained.
K and L must be relatively prime integers; that is, the ratio K/L cannot be
reducible to a ratio of smaller integers. The FIR Rate Conversion block
implements the above three steps together using a polyphase filter structure,
which is more efficient than straightforward upsample-filter-decimate
algorithms. The output of the interpolator is the first filter phase, while the
output of the decimator is the last filter phase. When both K and L are greater
than 1, the resulting output is the last decimation phase from the first
interpolation phase.
The FIR filter coefficients parameter specifies the numerator coefficients of
the FIR filter transfer function H(z).
–1 –( m – 1 )
H ( z ) = B ( z ) = b1 + b2 z + … + bm z
The coefficient vector, [b(1) b(2) ... b(m)], can be generated by one of the
filter design functions in the Signal Processing Toolbox (such as fir1), and
should have a length greater than the interpolation factor (m>L). The filter
should be lowpass with normalized cutoff frequency no greater than
min(1/L,1/K). All filter states are internally initialized to zero.
5-207
FIR Rate Conversion
Frame-Based Operation
This block accepts only frame-based inputs. An Mi-by-N frame-based matrix
input is treated as N independent channels, and the block resamples each
channel independently over time.
The Interpolation factor, L, and Decimation factor, K, must satisfy the
relation
K Mi
---- = --------
L Mo
for an integer output frame size Mo. The simplest way to satisfy this
requirement is to let the Decimation factor equal the input frame size, Mi.
The output frame size, Mo, is then equal to the Interpolation factor. This
change in the frame size, from Mi to Mo, produces the desired rate conversion
while leaving the output frame period the same as the input (Tfo = Tfi).
17 13 9 5 1
5.17 3.84 2.50 1.17 0.04
18 14 10 6 2
5.61 4.30 2.94 1.61 0.29
19 15 11 7 3
6.05 4.72 3.39 2.05 0.72
20 16 12 8 4
t=12 t=9 t=6 t=3 t=0
t=12 t=9 t=6 t=3 t=0
Tfo = 3
Tfi = 3
Latency
The FIR Rate Conversion block has no tasking latency. The block propagates
the first filtered input (received at t=0) as the first output sample.
Examples The dspsrcnv demo compares sample rate conversion performed by the FIR
Rate Conversion block with the same conversion performed by a cascade of
Upsample, Direct-Form II Transpose Filter, and Downsample blocks.
5-208
FIR Rate Conversion
Diagnostics An error is generated if the relation between K and L shown above is not
satisfied.
(Input port width)/(Output port width) must equal the
(Decimation factor)/(Interpolation factor).
A warning is generated if L and K are not relatively prime; that is, if the ratio
L/K can be reduced to a ratio of smaller integers.
Warning: Integer conversion factors are not relatively prime in
block 'modelname/FIR Rate Conversion (Frame)'. Converting ratio
L/M to l/m.
The block scales the ratio to be relatively prime, and continues the simulation.
Dialog Box
Interpolation factor
The integer factor, L, by which to upsample the signal before filtering.
FIR filter coefficients
The FIR filter coefficients, in descending powers of z.
Decimation factor
The integer factor, K, by which to downsample the signal after filtering.
5-209
FIR Rate Conversion
5-210
Flip
Purpose 5Flip
Flip the input vertically or horizontally.
Description The Flip block vertically or horizontally reverses the M-by-N input matrix, u.
The output always has the same dimension and frame status as the input.
When Columns is selected from the Flip along menu, the block vertically flips
the input so that the first row of the input is the last row of the output.
y = flipud(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs are treated as M-by-1 column
vectors for vertical flipping.
When Rows is selected from the Flip along menu, the block horizontally flips
the input so that the first column of the input is the last column of the output.
y = fliplr(u) % Equivalent MATLAB code
For convenience, length-N 1-D vector inputs are treated as 1-by-N row vectors
for horizontal flipping. The output always has the same dimension and frame
status as the input.
Dialog Box
Flip along
The dimension along which to flip the input. Columns specifies vertical
flipping, while Rows specifies horizontal flipping. Tunable
5-211
Flip
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-212
Forward Substitution
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The Forward Substitution block solves the linear system LX=B by simple
forward substitution of variables, where L is the lower triangular M-by-M
matrix input to the L port, and B is the M-by-N matrix input to the B port. The
output is the solution of the equations, the M-by-N matrix X, and is always
sample-based.
The block only uses the elements in the lower triangle of input L; the upper
elements are ignored. When Force input to be unit-lower triangular is
selected, the block replaces the elements on the diagonal of L with ones. This
is useful when matrix L is the result of another operation, such as an LDL
decomposition, that uses the diagonal elements to represent the D matrix.
A length-M vector input at port B is treated as an M-by-1 matrix.
Dialog Box
5-213
Forward Substitution
5-214
Frame Status Conversion
Description The Frame Status Conversion block passes the input through to the output,
and sets the output frame status to the Output signal parameter, which can
be either Frame-based or Sample-based. The output frame status can also be
inherited from the signal at the Ref (reference) input port, which is made
visible by selecting the Inherit output frame status from Ref input port
check box.
If the Output signal parameter setting or the inherited signal’s frame status
differs from the input frame status, the block changes the input frame status
accordingly, but does not otherwise alter the signal. In particular, the block
does not rebuffer or resize 2-D inputs. Because 1-D vectors cannot be
frame-based, if the input is a length-M 1-D vector, and the Output signal
parameter is set to Frame-based, the output is a frame-based M-by-1 matrix
(i.e., a single channel).
If the Output signal parameter or the inherited signal’s frame status matches
the input frame status, the block passes the input through to the output
unaltered.
Dialog Box
5-215
Frame Status Conversion
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-216
From Wave Device
Description The From Wave Device block reads audio data from a standard Windows audio
device in real-time. It is compatible with most popular Windows hardware,
including Sound Blaster cards. (Models that contain both this block and the To
Wave Device block require a duplex-capable sound card.)
The Use default audio device parameter allows the block to detect and use the
system’s default audio hardware. This option should be selected on systems
that have a single sound device installed, or when the default sound device on
a multiple-device system is the desired source. In cases when the default sound
device is not the desired input source, deselect Use default audio device, and
enter the desired device identification number in the Audio device ID
parameter. The device ID is an integer value that the block associates with the
sound device. A three-device system, for example, has device ID numbers of
1, 2, and 3.
If the audio source contains two channels (stereo), the Stereo check box should
be selected. If the audio source contains a single channel (mono), the Stereo
check box should be deselected. For stereo input, the block’s output is an
M-by-2 matrix containing one frame (M consecutive samples) of audio data
from each of the two channels. For mono input, the block’s output is an M-by-1
matrix containing one frame (M consecutive samples) of audio data from the
mono input. The frame size, M, is specified by the Samples per frame
parameter. For M=1, the output is sample-based; otherwise, the output is
frame-based.
The amplitude of the input from the sound device should be in the range ±1.
Values outside this range are clipped to the nearest allowable value. If the
audio signal is saturating at ±1, you can reduce the microphone gain from the
Multimedia Properties window (available through the Windows 95/98/NT
Control Panel). The audio data is processed in uncompressed PCM (pulse code
modulation) format, and should typically be sampled at one of the standard
Windows audio device rates: 8000, 11025, 22050, or 44100 Hz. You can select
one of these rates from the Sample rate parameter. To specify a different rate,
select the User-defined option and enter a value in the User-defined sample
rate parameter.
5-217
From Wave Device
The Sample Width (bits) parameter specifies the number of bits used to
represent the signal samples read by the audio device. Two settings are
available:
The 16-bit sample width setting requires more memory but yields better
fidelity. The output from the block is independent of the Sample Width (bits)
setting, and is always double precision.
Buffering
Since the audio device accepts real-time audio input, Simulink must read a
continuous stream of data from the device throughout the simulation. Delays
in reading data from the audio hardware can result in hardware errors or
distortion of the signal. This means that the From Wave Device block must in
principle read data from the audio hardware as quickly as the hardware itself
acquires the signal. However, the block often cannot match the throughput rate
of the audio hardware, especially when the simulation is running from within
Simulink rather than as generated code. (Simulink operations are generally
slower than comparable hardware operations, and execution speed routinely
varies during the simulation as the host operating system services other
processes.) The block must therefore rely on a buffering strategy to ensure that
signal data can be read on schedule without losing samples.
At the start of the simulation, the audio device begins writing the input data to
a (hardware) buffer with a capacity of Tb seconds. The From Wave Device block
immediately begins pulling the earliest samples off the buffer (first in, first out)
and collecting them in length-M frames for output. As the audio device
continues to append inputs to the bottom of the buffer, the From Wave Device
block continues to pull inputs off the top of the buffer at the best possible rate.
The following figure shows an audio signal being acquired and output with a
frame size of 8 samples. The buffer of the sound board is approaching its
five-frame capacity at the instant shown, which means that the hardware is
adding samples to the buffer more rapidly than the block is pulling them off. (If
5-218
From Wave Device
the signal sample rate was 8 kHz, this small buffer could hold approximately
0.005 second of data.)
board
Troubleshooting
If the buffer size is too small in relation to the simulation throughput rate, the
buffer may fill before the entire length of signal is processed. This usually
results in a device error or undesired device output. When this problem occurs,
you can choose to either increase the buffer size or the simulation throughput
rate:
where Fs is the sample rate of the signal and M is the number of samples per
frame. The required buffer size for a given signal depends on the signal
5-219
From Wave Device
length, the frame size, and the speed of the simulation. Note that increasing
the buffer size may increase model latency.
• Increase the simulation throughput rate
Two useful methods for improving simulation throughput rates are
increasing the signal frame size and compiling the simulation into native
code:
- Increase frame sizes (and convert sample-based signals to frame-based
signals) throughout the model to reduce the amount of block-to-block
communication overhead. This can drastically increase throughput rates
in many cases. However, larger frame sizes generally result in greater
model latency due to initial buffering operations.
- Generate executable code with Real Time Workshop. Native code runs
much faster than Simulink, and should provide rates adequate for
real-time audio processing.
More general ways to improve throughput rates include simplifying the model,
and running the simulation on a faster PC processor. See “Delay and Latency”
on page 3-85 of this book, and “Improving Simulation Performance and
Accuracy” in the Simulink documentation, for other ideas on improving
simulation performance.
Dialog Box
5-220
From Wave Device
5-221
From Wave File
Description The From Wave File block reads audio data from a Microsoft Wave (.wav) file
and generates a double-precision signal with amplitudes in the range ±1. The
audio data must be in uncompressed PCM (pulse code modulation) format.
y = wavread('filename') % Equivalent MATLAB code
The File name parameter can specify an absolute or relative path to the file. If
the file is on the MATLAB path or in the current directory (the directory
returned by typing pwd at the MATLAB command line), you need only specify
the file’s name. You do not need to specify the.wav extension in either case.
If the audio file contains two channels (stereo), the block’s output is an M-by-2
matrix containing one frame (M consecutive samples) of audio data from each
of the two channels. If the audio file contains a single channel (mono), the
block’s output is an M-by-1 matrix containing one frame (M consecutive
samples) of mono audio data. The frame size, M, is specified by the Samples
per frame parameter. For M=1, the output is sample-based; otherwise, the
output is frame-based.
The output frame period, Tfo, is
M
T fo = ------ ,
Fs
5-222
From Wave File
Dialog Box
File name
The path and name of the file to read. Paths can be relative or absolute.
Samples per output frame
The number of samples in each output frame, M.
Minimum number of samples for each read from file
The number of consecutive samples to acquire from the file with each file
access, L. Tunable.
5-223
Histogram
Purpose 5Histogram
Generate the histogram of an input or sequence of inputs.
Library Statistics
Description The Histogram block computes the frequency distribution of the elements in
each column of the input, or tracks the frequency distribution in a sequence of
inputs over a period of time. The Running histogram parameter selects
between basic operation and running operation, described below.
The block sorts the elements of each column into the number of discrete bins
specified by the Number of bins parameter, n.
y = hist(u,n) % Equivalent MATLAB code
BM – Bm
∆ = -----------------------
n
and centers located at
B m + k + --- ∆
1
k = 0, 1, 2, …, n – 1
2
Input values that fall on the border between two bins are sorted into the
lower-valued bin; that is, each bin includes its upper boundary. For example, a
bin of width 4 centered on the value 5 contains the input value 7, but not the
input value 3. Input values greater than the Maximum value of input
parameter or less than Minimum value of input parameter are sorted into the
highest-valued or lowest-valued bin, respectively.
Basic Operation
When the Running histogram check box is not selected, the block computes
the frequency distribution of each column in the M-by-N input u independently
at each sample time.
5-224
Histogram
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
The output, y, is a sample-based n-by-N matrix whose jth column is the
histogram for the data in the jth column of u. When the Normalized check box
is selected, the block scales each column of the output so that sum(y(:,j)) is 1.
Running Operation
When the Running histogram check box is selected, the block computes the
frequency distributions in a time-sequence of M-by-N inputs by creating N
persistent histograms to which successive inputs are continuously added. For
frame-based inputs, this is equivalent to a persistent histogram for each
independent channel.
As in basic operation, length-M 1-D vector inputs and sample-based length-M
row vector inputs are both treated as M-by-1 column vectors.
The output is a sample-based n-by-N matrix whose jth column reflects the
current state of the jth histogram. The block resets the running histogram (by
emptying all bins of all histograms) when the scalar input at the optional Rst
port is nonzero. (The Rst port can be disabled by deselecting the Reset port
check box.)
Example The model below illustrates the Histogram block’s basic operation for a
single-channel input, u, where
u = [0 -2 6 -12 2 5 4 3 0 4 3 -2 -3 -2 -9]'
5-225
Histogram
• Normalized =
• Running histogram =
5
–2
-2 4
–9
-2 2 4
-9 -2 0 3
-12 -3 0 3
-8 -4 0 4 8
Dialog Box
5-226
Histogram
5-227
IDCT
Purpose 5IDCT
Compute the IDCT of the input.
Library Transforms
Description The IDCT block computes the inverse discrete cosine transform (IDCT) of each
channel in the M-by-N input matrix, u.
y = idct(u) % Equivalent MATLAB code
For both sample-based and frame-based inputs, the block assumes that each
input column is a frame containing M consecutive samples from an
independent channel. The frame size, M, must be a power-of-two. To work with
other frame sizes, use the Zero Pad block to pad or truncate the frame size to a
power-of-two length.
The output is an M-by-N matrix whose lth column contains the length-M IDCT
of the corresponding input column.
M
π ( 2m – 1 ) ( k – 1 )
y ( m, l ) = ∑ w ( k )u ( k, l ) cos -------------------------------------------
2M
-, m = 1, …, M
k=1
where
1
--------- , k=1
w(k) = M
2
----- , 2≤k≤M
M
The output is always frame-based, and the output sample rate and data type
(real/complex) are the same as those of the input.
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are processed as single channels (i.e., as M-by-1 column vectors),
and the output has the same dimension as the input.
5-228
IDCT
Dialog Box
5-229
Identity Matrix
Description The Identity Matrix block generates a rectangular matrix with ones on the
main diagonal and zeros elsewhere.
When the Inherit input port attributes from input port check box is selected,
the input port is enabled, and an M-by-N matrix input generates a
sample-based M-by-N matrix output with the same sample period. The values
in the input matrix are ignored.
y = eye([M N]) % Equivalent MATLAB code
When the Inherit input port attributes from input port check box is not
selected, the input port is disabled, and the dimensions of the output matrix are
determined by the Matrix size parameter. A scalar value, M, specifies an
M-by-M identity matrix, while a two-element vector, [M N], specifies an
M-by-N unit-diagonal matrix. The output is sample-based, and has the sample
period specified by the Sample time parameter.
Example Set Matrix size to [3 6] to generate the 3-by-6 unit-diagonal matrix below.
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
5-230
Identity Matrix
Dialog Box
See “Creating Signals Using Constant Blocks” on page 3-33 for related
information.
5-231
IFFT
Purpose 5IFFT
Compute the IFFT of the input.
Library Transforms
Description The IFFT block computes the inverse fast Fourier transform (IFFT) of each
channel in the M-by-N or length-M input, u, where M must be a power of two.
To work with other input sizes, use the Zero Pad block to pad or truncate the
length-M dimension to a power-of-two length. The output is always
frame-based, and each output column contains the M-point inverse discrete
Fourier transform (IDFT) of the corresponding input channel.
y = ifft(u,M) % Equivalent MATLAB code
The kth entry of the lth output channel, y(k, l), is the kth point of the M-point
IDFT of the lth input channel.
M
1
y(k, l) = -----
M ∑ u ( m, l )e j2π ( m – 1 ) ( k – 1 ) ⁄ M k = 1, … , M (5-3)
m=1
You can choose to output a scaled version of the input’s IDFT, M ⋅ y(k, l) , by
setting the parameter Skip normalization by transform length, N.
M
For information on block output characteristics and how to configure the block
computation methods, see the following sections:
5-232
IFFT
Note For M-by-N and length-M inputs, M must be a power of two. To work
with other input sizes, use the Zero Pad block to pad or truncate the length-M
dimension to a power-of-two length. To get valid outputs, you must correctly
set the Input is in bit-reversed order parameter to indicate the ordering of
the block input. When the input is conjugate symmetric and you want to get a
real-valued output, set the Input is conjugate symmetric parameter.
5-233
IFFT
5-234
IFFT
Click here in the MATLAB Help Browser to open a Simulink model based on
the following diagram.
Effects of Block Input Size, Dimension, and Frame Status on Block Output
1 2 3 2.5 5 7.5
2 4 6 – 0.5 – 0.5i – 1 – i – 1.5 – 1.5i
Frame-based 4-by-3 input Frame-based 4-by-3 output – 0.5 –1 – 1.5
3 6 9
4 8 12 – 0.5 + 0.5i – 1 + i – 1.5 + 1.5i
Compute IFFT of each column
1 2 3 2.5 5 7.5
2 4 6 – 0.5 – 0.5i – 1 – i – 1.5 – 1.5i
Sample-based 4-by-3 nonrow input Frame-based 4-by-3 output – 0.5 –1 – 1.5
3 6 9
4 8 12 – 0.5 + 0.5i – 1 + i – 1.5 + 1.5i
Compute IFFT of each column
1234 Sample-based 1-by-4 row vector input Frame-based 1-by-4 output 2.5 – 0.5 – 0.5i – 0.5 – 0.5 + 0.5i
2.5
( 1, 2, 3, 4 ) – 0.5 – 0.5i
Unoriented length-4 1-D vector input Frame-based 4-by-1 output – 0.5
– 0.5 + 0.5i
Compute IFFT of the vector
Note If the IFFT block input is conjugate symmetric but you do not set the
Input is conjugate symmetric parameter, you do not get a real-valued
output. Instead, you get a complex-valued output with small imaginary parts.
5-235
IFFT
The block output is invalid if you set this parameter when the input is not
conjugate symmetric.
5-236
IFFT
Example For an example of how to optimize computations when using both the IFFT
block and FFT block in the same model, see the FFT block reference page
example, “Use of Outputs in Bit-Reversed Order” on page 5-179.
Dialog Box
5-237
IFFT
values before the simulation starts. In Trigonometric fcn mode, the block
computes the sine and cosine values during the simulation.
Optimize table for
Optimization of the table of sine and cosine values for Speed or Memory.
Active only when Twiddle factor computation is set to Table lookup.
Input is in bit-reversed order
Set when the input is in bit-reversed order, and clear when the input is in
linear order. The block yields invalid outputs if you do not set this
parameter correctly.
Input is conjugate symmetric
Set when the block input is conjugate symmetric and you want real-valued
outputs. The block output is invalid if you set this parameter when the
input is not conjugate symmetric.
Skip normalization by transform length, N
When set, rather than computing the IDFT, the block computes a scaled
version of the IDFT given by Equation 5-4.
5-238
Inherit Complexity
Description The Inherit Complexity block alters the input data at the Data port to match
the complexity of the reference input at the Ref port. If the Data input is real,
and the Ref input is complex, the block appends a zero-valued imaginary
component, 0i, to each element of the Data input.
Data Ref Output
0 5+ i 0+0i
1 3-2i 1+0i
Simulation time
2 0+ i 2+0i
3 2-5i 3+0i
4 2-5i 4+0i
...
...
...
If the Data input is complex, and the Ref input is real, the block outputs the
real component of the Data input.
Data Ref Output
i 5 0
1-2i 5 1
Simulation time
2+ i 3 2
3-5i -2 3
4-5i -2 4
...
...
...
If both the Data input and Ref input are real, or if both the Data input and Ref
input are complex, the block propagates the Data input with no change.
5-239
Inherit Complexity
Dialog Box
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-240
Integer Delay
Description The Integer Delay block delays a discrete-time input by the number of sample
intervals specified in the Delay parameter. Noninteger delay values are
rounded to the nearest integer, and negative delays are clipped at 0.
Sample-Based Operation
When the input is a sample-based M-by-N matrix, the block treats each of the
M∗N matrix elements as an independent channel. The Delay parameter, v, can
be an M-by-N matrix of positive integers that specifies the number of sample
intervals to delay each channel of the input, or a scalar integer by which to
equally delay all channels.
For example, if the input is M-by-1 and v is the matrix
[v(1) v(2) ... v(M)]', the first channel is delayed by v(1) sample intervals,
the second channel is delayed by v(2) sample intervals, and so on. Note that
when a channel is delayed for ∆ sample-time units, the output sample at time
t is the input sample at time t – ∆ . If t – ∆ is negative, then the output is the
corresponding value specified by the Initial conditions parameter.
A 1-D vector of length M is treated as an M-by-1 matrix, and the output is 1-D.
The Initial conditions parameter specifies the output of the block during the
initial delay in each channel. The initial delay for a particular channel is the
time elapsed from the start of the simulation until the first input in that
channel is propagated to the output. Both fixed and time-varying initial
conditions can be specified in a variety of ways to suit the dimensions of the
input.
• Scalar value to be repeated at each sample time of the initial delay (for every
channel). For a 2-by-2 input with the parameter settings below,
5-241
Integer Delay
the block generates the following sequence of matrices at the start of the
simulation,
1 2 1 3 2 4 3
–1 –1 u 11 – 1 u 11 u 12 u 11 u 12 u 11 u 12
, , , , ,…
1 2 1
–1 –1 –1 –1 –1 –1 u 21 – 1 u 21 u 22
k
where u ij is the i,jth element of the kth matrix in the input sequence.
• Array of size M-by-N-by-d. In this case, you can set different fixed initial
conditions for each element of a sample-based input. This setting is
explained further in the Array bullet in “Time-Varying Initial Conditions”
below.
the block outputs the sequence -1, -1, -1, 0, 1,... at the start of the
simulation.
• Array of dimension M-by-N-by-d, where d is the value specified for the Delay
parameter (the maximum value if the Delay is a vector) and M and N are the
number of rows and columns, respectively, in the input matrix. The d pages
5-242
Integer Delay
of the array are output in sequence, one at each sample time of the initial
delay. For a 2-by-3 input, and the parameters below,
1 2 3, 2 4 6, 3 6 9
4 5 6 1 3 5 0 4 8
Frame-Based Operation
When the input is a frame-based M-by-N matrix, the block treats each of the N
columns as an independent channel, and delays each channel as specified by
the Delay parameter.
For frame-based inputs, the Delay parameter can be a scalar integer by which
to equally delay all channels. It can also be a 1-by-N row vector, each element
of which serves as the delay for the corresponding channel of the N-channel
input. Likewise, it can also be an M-by-1 column vector, each element of which
serves as the delay for one of the corresponding M samples for each channel.
The Delay parameter can be an M-by-N matrix of positive integers as well; in
this case, each element of each channel is delayed by the corresponding
element in the delay matrix. For instance, if the fifth element of the third
column of the delay matrix was 3, then the fifth element of the third channel of
the input matrix is always delayed by three sample-time units.
When a channel is delayed for ∆ sample-time units, the output sample at time
t is the input sample at time t – ∆ . If t – ∆ is negative, then the output is the
corresponding value specified in the Initial conditions parameter.
5-243
Integer Delay
The Initial conditions parameter specifies the output during the initial delay.
Both fixed and time-varying initial conditions can be specified. The initial
delay for a particular channel is the time elapsed from the start of the
simulation until the first input in that channel is propagated to the output.
Fixed Initial Conditions. The settings shown below specify fixed initial conditions.
The value entered in the Initial conditions parameter is repeated at the
output for each sample time of the initial delay. A fixed initial condition in
frame-based mode can be one of the following:
• Scalar value to be repeated for all channels of the output at each sample time
of the initial delay. For a general M-by-N input with the parameter settings
below,
the first five samples in each of the N channels are zero. Note that if the
frame size is larger than the delay, all of these zeros are all included in the
first output from the block.
• Array of size 1-by-N-by-D. In this case, you can also specify different fixed
initial conditions for each channel. See the Array bullet in “Time-Varying
Initial Conditions” below for details.
Initial conditions cannot be specified by full matrices.
- When an element of the delay entry is less than the frame size,
D = d + 1
where d is the maximum delay.
5-244
Integer Delay
- When the all elements of the delay entry are greater than the input frame
size,
D = d + input frame size - 1
Only the first d entries of the initial condition vector will be used; the rest of
the values are ignored, but you must include them nonetheless. For a
two-channel ramp input [1:100; 1:100]' with a frame size of 4 and the
parameter settings below,
the block outputs the following sequence of frames at the start of the
simulation.
–4 –1 3 –5 7 4
–5 –2
, 4 1 , 8 5 ,…
1 –3 5 2 9 6
2 –4 6 3 10 7
Note that since one of the delays, 2, is less than the frame size of the input,
4, the length of the Initial conditions vector is the sum of the maximum
delay and 1 (5+1), which is 6. The first five entries of the initial conditions
vector are used by the channel with the maximum delay, and the rest of the
entries are ignored. Since the first channel is delayed for less than the
maximum delay (2 sample time units), it only makes use of two of the initial
condition entries.
5-245
Integer Delay
the block outputs the following sequence of frames at the start of the
simulation.
–1 –2 – 9 – 10 4 4
–3 –4
, 1 1 , 5 5 ,…
–5 –6 2 2 6 6
–7 –8 3 3 7 7
Note that the channels have distinct time varying initial conditions; the
initial conditions for channel 1 correspond to the first entry of each length-2
row vector in the initial conditions array, and the initial conditions for
channel 2 correspond to the second entry of each row vector in the initial
conditions array. Only the first five entries in the initial conditions array are
used; the rest are ignored.
The 1-by-N-by-D array entry can also specify different fixed initial conditions
for every channel; in this case, every 1-by-N entry in the array would be
identical, so that the initial conditions for each column are fixed over time.
Initial conditions cannot be specified by full matrices.
Examples The dspafxr demo illustrates an audio reverberation system built around the
Integer Delay block.
5-246
Integer Delay
Input Output
ch1
ch2
ch3
ch1
ch2
ch3
[1 1 1] First input [0 1 0] First output
(sample-based)
[2 2 2] [0 2 0]
[3 3 3] [1 3 0]
[4 4 4] [2 4 0]
Simulation time
[5 5 5] [3 5 0]
[6 6 6] [4 6 1]
[7 7 7] [5 7 2]
[8 8 8] [6 8 3]
[9 9 9] [7 9 4]
Delay: [2 0 5]
...
...
Initial conditions: 0
Dialog Box
Delay
The number of sample periods to delay the input signal.
Initial conditions
The value of the block’s output during the initial delay.
5-247
Integer Delay
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-248
Kalman Adaptive Filter
Description The Kalman Adaptive Filter block computes the optimal linear minimum
mean-square estimate (MMSE) of the FIR filter coefficients using a one-step
predictor algorithm. This Kalman filter algorithm is based on the following
physical realization of a dynamical system.
The Kalman filter assumes that there are no deterministic changes to the filter
taps over time (i.e., the transition matrix is identity), and that the only
observable output from the system is the filter output with additive noise. The
corresponding Kalman filter is expressed in matrix form as
K ( n – 1 )u ( n )
g ( n ) = --------------------------------------------------------------------
H
u ( n )K ( n – 1 )u ( n ) + Q M
H
y ( n ) = u ( n )ŵ ( n )
e(n) = d(n) – y(n)
ŵ ( n + 1 ) = ŵ ( n ) + e ( n )g ( n )
H
K ( n ) = K ( n – 1 ) – g ( n )u ( n )K ( n – 1 ) + Q P
5-249
Kalman Adaptive Filter
Variable Description
The correlation matrices, QM and QP, are specified in the parameter dialog box
by scalar variance terms to be placed along the matrix diagonals, thus ensuring
that these matrices are symmetric. The filter algorithm based on this
constraint is also known as the random-walk Kalman filter.
The implementation of the algorithm in the block is optimized by exploiting the
symmetry of the input covariance matrix K(n). This decreases the total number
of computations by a factor of two.
The block icon has port labels corresponding to the inputs and outputs of the
Kalman algorithm. Note that inputs to the In and Err ports must be
sample-based scalars. The signal at the Out port is a scalar, while the signal at
the Taps port is a sample-based vector.
5-250
Kalman Adaptive Filter
An optional Adapt input port is added when the Adapt input check box is
selected in the dialog box. When this port is enabled, the block continuously
adapts the filter coefficients while the Adapt input is nonzero. A zero-valued
input to the Adapt port causes the block to stop adapting, and to hold the filter
coefficients at their current values until the next nonzero Adapt input.
The FIR filter length parameter specifies the length of the filter that the
Kalman algorithm estimates. The Measurement noise variance and the
Process noise variance parameters specify the correlation matrices of the
measurement and process noise, respectively. The Measurement noise
variance must be a scalar, while the Process noise variance can be a vector
of values to be placed along the diagonal, or a scalar to be repeated for the
diagonal elements.
The Initial value of filter taps specifies the initial value ŵ ( 0 ) as a vector, or
as a scalar to be repeated for all vector elements. The Initial error correlation
matrix specifies the initial value K(0), and can be a diagonal matrix, a vector
of values to be placed along the diagonal, or a scalar to be repeated for the
diagonal elements.
5-251
Kalman Adaptive Filter
Dialog Box
References Haykin, S. Adaptive Filter Theory. 3rd ed. Englewood Cliffs, NJ: Prentice Hall,
1996.
5-252
Kalman Adaptive Filter
5-253
LDL Factorization
Description The LDL Factorization block uniquely factors the square Hermitian positive
definite input matrix S as
*
S = LDL
where L is a lower triangular square matrix with unity diagonal elements, D is
a diagonal matrix, and L* is the Hermitian (complex conjugate) transpose of L.
Only the diagonal and lower triangle of the input matrix are used, and any
imaginary component of the diagonal entries is disregarded.
The block’s output is a composite matrix with lower triangle elements lij
from L, diagonal elements dij from D, and upper triangle elements uij from L*.
It is always sample-based. The output format is shown below for a 5-by-5
matrix.
d 11 u 12 u 13 u 14 u 15
l 21 d 22 u 23 u 24 u 25
*
l 31 l 32 d 33 u 34 u 35 u ij = l ji
l 41 l 42 l 43 d 44 u 45
l 51 l 52 l 53 l 54 d 55
5-254
LDL Factorization
• Ignore – Proceed with the computation and do not issue an alert. The output
is not a valid factorization. A partial factorization will be present in the
upper left corner of the ouput.
• Warning – Display a warning message in the MATLAB command window,
and continue the simulation. The output is not a valid factorization. A partial
factorization will be present in the upper left corner of the ouput.
• Error – Display an error dialog box and terminate the simulation.
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-255
LDL Factorization
5-256
LDL Inverse
Description The LDL Inverse block computes the inverse of the Hermitian positive definite
input matrix S by performing an LDL factorization.
–1 * –1
S = ( LDL )
L is a lower triangular square matrix with unity diagonal elements, D is a
diagonal matrix, and L* is the Hermitian (complex conjugate) transpose of L.
Only the diagonal and lower triangle of the input matrix are used, and any
imaginary component of the diagonal entries is disregarded. The output is
always sample-based.
LDL factorization requires half the computation of Gaussian elimination
(LU decomposition), and is always stable. It is more efficient than Cholesky
factorization because it avoids computing the square roots of the diagonal
elements.
The algorithm requires that the input be Hermitian positive definite. When the
input is not positive definite, the block reacts with the behavior specified by the
Non-positive definite input parameter. The following options are available:
• Ignore – Proceed with the computation and do not issue an alert. The output
is not a valid inverse.
• Warning – Display a warning message in the MATLAB command window,
and continue the simulation. The output is not a valid inverse.
• Error – Display an error dialog box and terminate the simulation.
Dialog Box
5-257
LDL Inverse
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-258
LDL Solver
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The LDL Solver block solves the linear system SX=B by applying LDL
factorization to the matrix at the S port, which must be square (M-by-M) and
Hermitian positive definite. Only the diagonal and lower triangle of the matrix
are used, and any imaginary component of the diagonal entries is disregarded.
The input to the B port is the right-hand side M-by-N matrix, B. The output is
the unique solution of the equations, M-by-N matrix X, and is always
sample-based.
A length-M 1-D vector input for right-hand side B is treated as an M-by-1
matrix.
When the input is not positive definite, the block reacts with the behavior
specified by the Non-positive definite input parameter. The following options
are available:
• Ignore – Proceed with the computation and do not issue an alert. The output
is not a valid solution.
• Warning – Proceed with the computation and display a warning message in
the MATLAB command window. The output is not a valid solution.
• Error – Display an error dialog box and terminate the simulation.
Algorithm The LDL algorithm uniquely factors the Hermitian positive definite input
matrix S as
*
S = LDL
where L is a lower triangular square matrix with unity diagonal elements, D is
a diagonal matrix, and L* is the Hermitian (complex conjugate) transpose of L.
The equation
*
LDL X = B
is solved for X by the following steps:
5-259
LDL Solver
1 Substitute
*
Y = DL X
2 Substitute
*
Z = L X
3 Solve one diagonal and two triangular systems.
LY = B
DZ = Y
*
L X = Z
Dialog Box
5-260
Least Squares Polynomial Fit
Description The Least Squares Polynomial Fit block computes the coefficients of the nth
order polynomial that best fits the input data in the least-squares sense, where
n is specified by the Polynomial order parameter. A distinct set of n+1
coefficients is computed for each column of the M-by-N input, u.
For a given input column, the block computes the set of coefficients,
c1, c2, …, cn+1, that minimizes the quantity
M
2
∑ ( ui – ûi )
i=1
The values of the independent variable, x1, x2, …, xM, are specified as a
length-M vector by the Control points parameter. The same M control points
are used for all N polynomial fits, and can be equally or unequally spaced. The
equivalent MATLAB code is shown below.
c = polyfit(x,u,n) % Equivalent MATLAB code
Example In the model below, the Polynomial Evaluation block uses the second-order
polynomial
2
y = –2 u + 3
5-261
Least Squares Polynomial Fit
The Control points parameter of the Least Squares Polynomial Fit block is
configured with the same four values of independent variable u that are used
as input to the Polynomial Evaluation block, [1 2 3 4]. The Least Squares
Polynomial Fit block uses these values together with the input values of
dependent variable y to reconstruct the original polynomial coefficients.
Dialog Box
Control points
The values of the independent variable to which the data in each input
column correspond. For an M-by-N input, this parameter must be a
length-M vector. Tunable.
Polynomial order
The order, n, of the polynomial to be used in constructing the best fit. The
number of coefficients is n+1. Tunable.
5-262
Least Squares Polynomial Fit
5-263
Levinson-Durbin
Purpose 5Levinson-Durbin
Solve a linear system of equations using Levinson-Durbin recursion.
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The Levinson-Durbin block solves the nth-order system of linear equations
Ra = b
for the particular case where R is a Hermitian, positive-definite, Toeplitz
matrix and b is identical to the first column of R shifted by one element and
with the opposite sign.
r(1) r* ( 2 ) L r* ( n ) a(2) –r ( 2 )
r ( 2 ) r ( 1 ) L r* ( n – 1 ) a(3) –r ( 3 )
=
M M O M M M
r(n) r(n – 1) L r(1) a ( n + 1 ) – r ( n + 1)
The input to the block, r = [r(1) r(2) ... r(n+1)], can be a 1-D or 2-D
vector (row or column). It contains lags 0 through n of an autocorrelation
sequence, which appear in the matrix R.
The block can output the polynomial coefficients, A, the reflection
coefficients, K, and the prediction error power, P, in various combinations. The
Output(s) parameter allows you to enable the A and K outputs by selecting one
of the following settings:
• A – Port A outputs A=[1 a(2) a(3) ... a(n+1)], the solution to the
Levinson-Durbin equation. A has the same dimension as the input. The
elements of the output can also be viewed as the coefficients of an nth-order
autoregressive (AR) process (see below).
• K – Port K outputs K=[k(1) k(2) ... k(n)], which contains n reflection
coefficients, and has the same dimension as the input, less one element.
(A scalar input causes an error when K is selected.) Reflection coefficients
are useful for realizing a lattice representation of the AR process described
below.
• A and K – The block outputs both representations at their respective ports.
(A scalar input causes an error when A and K is selected.)
5-264
Levinson-Durbin
Applications
One application of the Levinson-Durbin formulation above is in the
Yule-Walker AR problem, which concerns modeling an unknown system as an
autoregressive process. Such a process would be modeled as the output of an
all-pole IIR filter with white Gaussian noise input. In the Yule-Walker
problem, the use of the signal’s autocorrelation sequence to obtain an optimal
estimate leads to an Ra = b equation of the type shown above, which is most
efficiently solved by Levinson-Durbin recursion. In this case, the input to the
block represents the autocorrelation sequence, with r(1) being the zero-lag
value. The output at the block’s A port then contains the coefficients of the
autoregressive process that optimally models the system. The coefficients are
ordered in descending powers of z, and the AR process is minimum phase. The
prediction error, G, defines the gain for the unknown system, where G = P .
G G
H ( z ) = ------------ = --------------------------------------------------------------------------------
A(z) –1
1 + a ( 2 )z + … + a ( n + 1 )z
–n
5-265
Levinson-Durbin
average (MA) process (or FIR filter) that predicts the next value of a signal
from the current signal sample and a finite number of past samples. In this
case, the input to the block represents the signal’s autocorrelation sequence,
with r(1) being the zero-lag value, and the output at the block’s A port contains
the coefficients of the predictive MA process (in descending powers of z).
–1 –n
H ( z ) = A ( z ) = 1 + a ( 2 )z + … + a ( n + 1 )z
These coefficients solve the optimization problem below.
N 2
min
{ ai } E xn – ∑ ai xn – i
i=1
Again, the output at the block’s K port contains the corresponding reflection
coefficients, [k(1) k(2) ... k(n)], for the lattice realization of this FIR
filter. The Autocorrelation LPC block in the Linear Prediction library
implements this autocorrelation-based prediction method.
Algorithm The algorithm requires O(n2) operations, and is thus much more efficient for
large n than standard Gaussian elimination, which requires O(n3) operations.
Dialog Box
Output(s)
The solution representation of Ra = b to output: model coefficients (A),
reflection coefficients (K), or both (A and K). For scalar inputs, this
parameter must be set to A.
5-266
Levinson-Durbin
References Golub, G. H., and C. F. Van Loan. Sect. 4.7 in Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
Ljung, L. System Identification: Theory for the User. Englewood Cliffs, NJ:
Prentice Hall, 1987. Pgs. 278-280.
Kay, Steven M., Modern Spectral Estimation: Theory and Application.
Englewood Cliffs, NJ: Prentice Hall, 1988.
5-267
LMS Adaptive Filter
Description The LMS Adaptive Filter block implements an adaptive FIR filter using the
stochastic gradient algorithm known as the normalized Least Mean-Square
(LMS) algorithm.
H
y ( n ) = ŵ ( n – 1 )u ( n )
e(n) = d(n) – y(n)
u(n)
ŵ ( n ) = ŵ ( n – 1 ) + --------------------------------------- µe∗ ( n )
H
a + u ( n )u ( n )
The variables are as follows.
Variable Description
ŵ ( n ) = ŵ ( n – 1 ) + u ( n )µe∗ ( n )
The block icon has port labels corresponding to the inputs and outputs of the
LMS algorithm. Note that inputs to the In and Err ports must be sample-based
5-268
LMS Adaptive Filter
scalars. The signal at the Out port is a scalar, while the signal at the Taps port
is a sample-based vector.
An optional Adapt input port is added when the Adapt input check box is
selected in the dialog box. When this port is enabled, the block continuously
adapts the filter coefficients while the Adapt input is nonzero. A zero-valued
input to the Adapt port causes the block to stop adapting, and to hold the filter
coefficients at their current values until the next nonzero Adapt input.
The FIR filter length parameter specifies the length of the filter that the LMS
algorithm estimates. The Step size parameter corresponds to µ in the
equations. Typically, for convergence in the mean square, 0<µ<2. The Initial
value of filter taps specifies the initial value ŵ ( 0 ) as a vector, or as a scalar
to be repeated for all vector elements. The Leakage factor specifies the value
of the leakage factor, 1 – µα , in the leaky LMS algorithm below. This
parameter must be between 0 and 1.
u(n)
ŵ ( n + 1 ) = ( 1 – µα )ω̂ ( n ) + -----------------------------µe∗ ( n )
H
u ( n )u ( n )
Examples The lmsdemo demo illustrates a noise cancellation system built around the
LMS Adaptive Filter block.
5-269
LMS Adaptive Filter
Dialog Box
References Haykin, S. Adaptive Filter Theory. 3rd ed. Englewood Cliffs, NJ: Prentice Hall,
1996.
5-270
LMS Adaptive Filter
5-271
LU Factorization
Description The LU Factorization block factors a row permutation of the square input
matrix A as
A p = LU
Example The row-pivoted matrix Ap and permutation index vector P computed by the
block are shown below for 3-by-3 input matrix A.
–1 8 –5 9 –1 2
A = 9 –1 2 P = (2 1 3) A = –1 8 –5
p
2 –5 7 2 –5 7
5-272
LU Factorization
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-273
LU Inverse
Description The LU Inverse block computes the inverse of the square input matrix A by
factoring and inverting row-pivoted variant Ap.
–1 –1
A p = ( LU )
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-274
LU Solver
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The LU Solver block solves the linear system AX=B by applying
LU factorization to the M-by-M matrix at the A port. The input to the B port is
the right-hand side M-by-N matrix, B. The output is the unique solution of the
equations, M-by-N matrix X, and is always sample-based.
A length-M 1-D vector input for right-hand side B is treated as an M-by-1
matrix.
Algorithm The LU algorithm factors a row-permuted variant (Ap) of the square input
matrix A as
A p = LU
Ap X = Bp
LUX = B p
is solved for X by making the substitution Y = UX, and solving two triangular
systems.
LY = B p
UX = Y
Dialog Box
5-275
LU Solver
5-276
Magnitude FFT
Description The Magnitude FFT block computes a nonparametric estimate of the spectrum
using the periodogram method. When the Output parameter is set to
Magnitude squared, the block output for an input u is equivalent to
y = abs(fft(u,nfft)).^2 % Equivalent MATLAB code
When the Output parameter is set to Magnitude, the block output for an
input u is equivalent to
y = abs(fft(u,nfft)) % Equivalent MATLAB code
Example The dspsacomp demo compares the periodogram method with several other
spectral estimation methods.
5-277
Magnitude FFT
Dialog Box
Output
Determines whether the block computes the magnitude FFT (Magnitude)
or magnitude-squared FFT (Magnitude squared) of the input. Tunable.
Inherit FFT length from input dimensions
When selected, uses the input frame size as the number of data points, Nfft,
on which to perform the FFT.
FFT size
The number of data points on which to perform the FFT, Nfft. If Nfft exceeds
the input frame size, the frame is zero-padded as needed. This parameter
is enabled when Inherit FFT length from input dimensions is not
selected.
5-278
Magnitude FFT
5-279
Matrix 1-Norm
Description The Matrix 1-Norm block computes the 1-norm, or maximum column-sum, of
an M-by-N input matrix, A.
M
y = A 1 = max
1≤j≤N
∑ a ij
i=1
This is equivalent to
y = max(sum(abs(A))) % Equivalent MATLAB code
a 11 a 12 a 13
a 21 a 22 a 23 A 1 = max ( A 1, A 2, A 3 )
a 31 a 32 a 33
a 13 + a 23 + a 33 = A 3
a 12 + a 22 + a 32 = A 2
a 11 + a 21 + a 31 = A 1
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-280
Matrix 1-Norm
5-281
Matrix Multiply
Description The Matrix Multiply block multiplies n input matrices, A, B, C, ..., Un, in the
forward direction, where n is specified by the Number of input ports
parameter and Un is the input at the nth port.
Y = ((((A*B)*C)*D) ... Un) % Equivalent MATLAB code
All inputs must have sizes compatible for matrix multiplication; that is,
size(A,2) = size(B,1), size(B,2) = size(C,1), and so on. Inputs can be real,
complex, sample-based, or frame-based in any combination, but all inputs
must have the same precision, single or double. A length-M 1-D vector input at
any port is treated as an M-by-1 matrix.
The size of sample-based output Y is [size(A,1) size(Un,2)]. That is, Y is
MA-by-NUn.
Algorithm The Matrix Multiply block is optimized to use at most two temporary variables
for storage of intermediate results.
Dialog Box
5-282
Matrix Multiply
5-283
Matrix Product
Description The Matrix Product block multiplies the elements of an M-by-N input matrix u
along either the rows or columns.
When the Multiply along parameter is set to Rows, the block multiplies across
the elements of each row and outputs the resulting M-by-1 matrix. A length-N
1-D vector input is treated as a 1-by-N matrix.
u 11 u 12 u 13 y1 ( u 11 u 12 u 13 )
u 21 u 22 u 23 y 2 = ( u 21 u 22 u 23 )
u 31 u 32 u 33 y3 ( u 31 u 32 u 33 )
This is equivalent to
y = prod(u,2) % Equivalent MATLAB code
When the Multiply along parameter is set to Columns, the block multiplies
down the elements of each column and outputs the resulting 1-by-N matrix. A
length-M 1-D vector input is treated as a M-by-1 matrix.
u 11 u 12 u 13
u 21 u 22 u 23
u 31 u 32 u 33
y1 y2 y3 = ( u 11 u 21 u 31 ) ( u 12 u 22 u 32 ) ( u 13 u 23 u 33 )
This is equivalent to
y = prod(u) % Equivalent MATLAB code
5-284
Matrix Product
Dialog Box
Multiply along
The dimension of the matrix along which to multiply, row or column.
5-285
Matrix Scaling
Description The Matrix Scaling block scales the rows or columns of the M-by-N input
matrix A by the values in input vector D.
When the Mode parameter is set to Scale Rows (D*A), input D can be a 1-D or
2-D vector of length M, and the block multiplies each element of D across the
corresponding row of matrix A.
d1 × a 11 a 12 a 13 d 1 a 11 d 1 a 12 d 1 a 13
d2 × a 21 a 22 a 23 d 2 a 21 d 2 a 22 d 2 a 23
d3 × a 31 a 32 a 33 d 3 a 31 d 3 a 32 d 3 a 33
When the Mode parameter is set to Scale Columns (A*D), input D can be a 1-D
or 2-D vector of length N, and the block multiplies each element of D across the
corresponding column of matrix A.
d1 d2 d3
× × × d 1 a 11 d 2 a 12 d 3 a 13
a 11 a 12 a 13 d 1 a 21 d 2 a 22 d 3 a 23
a 21 a 22 a 23 d 1 a 31 d 2 a 32 d 3 a 33
a 31 a 32 a 33
The output is the same size as the input matrix, A. If both inputs are
sample-based, the output is sample-based; otherwise, the output is
frame-based.
5-286
Matrix Scaling
Dialog Box
Mode
The mode of operation, row scaling or column scaling. Tunable.
5-287
Matrix Square
Description The Matrix Square block computes the square of an M-by-N input matrix, u, by
premultiplying with the Hermitian transpose.
y = u' * u % Equivalent MATLAB code
Applications
The Matrix Square block is useful in a variety of applications:
• General matrix squares – The Matrix Square block computes the output
matrix, y, without explicitly forming u'. It is therefore more efficient than
other methods for computing the matrix square.
• Sum of squares – When the input is a column vector (N=1), the block’s
operation is equivalent to a multiply-accumulate (MAC) process, or inner
product. The output is the sum of the squares of the input, and is always a
real scalar.
• Correlation matrix – When the input is a row vector (M=1), the output, y, is
the symmetric autocorrelation matrix, or outer product.
Dialog Box
5-288
Matrix Square
5-289
Matrix Sum
Description The Matrix Sum block sums the elements of an M-by-N input matrix u along
either the rows or columns.
When the Sum along parameter is set to Rows, the block sums across the
elements of each row and outputs the resulting M-by-1 matrix. A length-N
1-D vector input is treated as a 1-by-N matrix.
u 11 u 12 u 13 y1 u 11 + u 12 + u 13
u 21 u 22 u 23 y 2 = u 21 + u 22 + u 23
u 31 u 32 u 33 y3 u 31 + u 32 + u 33
This is equivalent to
y = sum(u,2) % Equivalent MATLAB code
When the Sum along parameter is set to Columns, the block sums down the
elements of each column and outputs the resulting 1-by-N matrix. A length-M
1-D vector input is treated as a M-by-1 matrix.
u 11 u 12 u 13
u 21 u 22 u 23
u 31 u 32 u 33
3 3 3
y1 y2 y3 = ∑ ui1 ∑ ui2 ∑ ui3
i=1 i=1 i=1
This is equivalent to
y = sum(u) % Equivalent MATLAB code
5-290
Matrix Sum
Dialog Box
Sum along
The dimension of the matrix to sum along, row or column.
5-291
Matrix Viewer
Description The Matrix Viewer block displays an M-by-N matrix input by mapping the
matrix element values to a specified range of colors. The display is updated as
each new input is received. (A length-M 1-D vector input is treated as an
M-by-1 matrix.)
Image Properties
Click on the Image properties check box to expose the image property
parameters, which control the colormap and display.
The mapping of matrix element values to colors is specified by the Colormap
matrix, Minimum input, and Maximum input parameters. For a colormap
with L colors, the colormap matrix has dimension L-by-3, with one row for each
color and one column for each element of the RGB triple that defines the color.
Examples of RGB triples are
[ 1 0 0 ] (red)
[ 0 0 1 ] (blue)
[0.8 0.8 0.8] (light gray)
5-292
Matrix Viewer
Axis Properties
Click on the Axis properties check box to expose the axis property parameters,
which control labeling and positioning.
The Axis origin parameter determines where the first element of the input
matrix, U(1,1), is displayed. When Upper left corner is specified, the matrix
is displayed in matrix orientation, with U(1,1) in the upper-left corner.
U 11 U 12 U 13 U 14
U 21 U 22 U 23 U 24
U 31 U 32 U 33 U 34
U 41 U 42 U 43 U 44
When Lower left corner is specified, the matrix is flipped vertically to image
orientation, with U(1,1) in the lower-left corner.
U 41 U 42 U 43 U 44
U 31 U 32 U 33 U 34
U 21 U 22 U 23 U 24
U 11 U 12 U 13 U 14
Axis zoom, when selected, causes the image display to completely fill the figure
window. Menus and axis titles are not displayed. This option can also be
selected from the right-click pop-up menu in the figure window.
When Axis zoom is deselected, the axis labels and titles are displayed in a gray
border surrounding the image axes, and the window’s menus (including Axes)
and toolbar are visible. The Plot Editor tools allow you to annotate and
customize the image display. Select Help Plot Editor from the figure’s Help
menu for more information about using these tools. For information on printing
or saving the image, or on the other options found in the generic figure menus
(File, Edit, Window, Help), see the MATLAB documentation.
Figure Window
The image title (in the figure title bar) is the same as the block title. The axis
tick marks reflect the size of the input matrix; the x-axis is numbered from
5-293
Matrix Viewer
• Refresh erases all data on the scope display, except for the most recent
image.
• Autoscale recomputes the Minimum input and Maximum input parameter
values to best fit the range of values observed in a series of 10 consecutive
inputs. The numerical limits selected by the autoscale feature are shown in
the Minimum input and Maximum input parameters, where you can make
further adjustments to them manually.
• Axis zoom, when selected, causes the image to completely fill the containing
figure window. Menus and axis titles are not displayed. When Axis zoom is
deselected, the axis labels and titles are displayed in a gray border
surrounding the scope axes, and the window’s menus (including Axes) and
toolbar are visible. This option can also be set in the Axis properties panel
of the parameter dialog box.
• Colorbar, when selected, displays a bar with the specified colormap to the
right of the image axes.
• Save Position automatically updates the Figure position parameter in the
Axis properties field to reflect the figure window’s current position and size
on the screen. To make the scope window open at a particular location on the
screen when the simulation runs, simply drag the window to the desired
location, resize it as needed, and select Save Position. Note that the
parameter dialog box must be closed when you select Save Position in order
for the Figure position parameter to be updated.
Many of these options can also be accessed by right-clicking with the mouse
anywhere on the displayed image. The right-click menu is very helpful when
the scope is in zoomed mode and the Axes menu is not visible.
Examples See the demo dspstfft.mdl for an example of using the Matrix Viewer block
to create a moving spectrogram (time-frequency plot) of a speech signal by
updating just one column of the input matrix at each sample time.
5-294
Matrix Viewer
Dialog Box
Image properties
Select to expose the image property parameters. Tunable.
Colormap matrix
A 3-column matrix defining the colormap as a set of RGB triples, or a call
to a colormap-generating function such as hot or spring. See the
ColorSpec property for complete information about defining RGB triples,
and the colormap function for a list of colormap-generating functions.
Tunable.
Minimum input value
The input value to be mapped to the color defined in the first row of the
colormap matrix. Select Autoscale from the right-click pop-up menu to set
this parameter to the minimum value observed in a series of 10 consecutive
matrix inputs. Tunable.
5-295
Matrix Viewer
X-axis title
The text to be displayed below the x-axis. Tunable.
Y-axis title
The text to be displayed to the left of the y-axis. Tunable.
Colorbar title
The text to be displayed to the right of the color bar, if Display colorbar is
currently selected. Tunable.
Figure position
A 4-element vector of the form [left bottom width height] specifying
the position of the figure window, where (0,0) is the lower-left corner of
the display. Tunable.
Axis zoom
Resizes the image to fill the figure window. Tunable.
5-296
Matrix Viewer
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-297
Maximum
Purpose 5Maximum
Find the maximum values in an input or sequence of inputs.
Library Statistics
Description The Maximum block identifies the value and position of the largest element in
each column of the input, or tracks the maximum values in a sequence of inputs
over a period of time. The Mode parameter specifies the block’s mode of
operation and can be set to Value, Index, Value and Index, or Running.
Value Mode
When Mode is set to Value, the block computes the maximum value in each
column of the M-by-N input matrix u independently at each sample time.
val = max(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
The output at each sample time, val, is a 1-by-N vector containing the
maximum value of each column in u. For complex inputs, the block selects the
value in each column that has the maximum magnitude, max(abs(u)), as
shown below.
Complex
abs(u) Output (val)
4 + 2i 4.47
–3–i 3.16
4 + 4i 5.66 4 + 4i
–1 + 4 i 4.12
–4–i 4.12
The frame status of the output is the same as that of the input.
Index Mode
When Mode is set to Index, the block computes the maximum value in each
column of the M-by-N input matrix u,
[val,idx] = max(u) % Equivalent MATLAB code
5-298
Maximum
and outputs the sample-based 1-by-N index vector, idx. Each value in idx is an
integer in the range [1 M] indexing the maximum value in the corresponding
column of u.
As in Value mode, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
If a maximum value occurs more than once in a particular column of u, the
computed index corresponds to the first occurrence. For example, if the input
is the column vector [3 2 1 2 3]', the computed index of the maximum value
is 1 rather than 5.
Running Mode
When Mode is set to Running, the block tracks the maximum value of each
channel in a time-sequence of M-by-N inputs. For sample-based inputs, the
output is a sample-based M-by-N matrix with each element yij containing the
maximum value observed in element uij for all inputs since the last reset. For
frame-based inputs, the output is a frame-based M-by-N matrix with each
element yij containing the maximum value observed in the jth column of all
inputs since the last reset, up to and including element uij of the current input.
The block resets the running maximum whenever a reset event is detected at
the optional Rst port. The reset event is specified by the Reset port menu, and
can be one of the following:
• Rising edge triggers a reset operation when the Rst input rises from a
negative value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers a reset operation when the Rst input falls from a
positive value to zero or a negative value, or from zero to a negative value.
• Either edge triggers a reset operation when either a rising or falling edge
(as described above) occurs.
• Non-zero sample triggers a reset operation at each sample time that the Rst
input is not zero.
5-299
Maximum
For sample-based inputs, a reset event causes the running maximum for each
channel to be initialized to the value in the corresponding channel of the
current input. For frame-based inputs, a reset event causes the running
maximum for each channel to be initialized to the earliest value in each
channel of the current input. The Rst port can be disabled by selecting None
from the Reset port menu.
As in the other modes, length-M 1-D vector inputs and sample-based length-M
row vector inputs are both treated as M-by-1 column vectors.
Example The Maximum block in the model below calculates the running maximum of a
frame-based 3-by-2 (two-channel) matrix input, u. The running maximum is
reset at t=2 by an impulse to the block’s Rst port.
• Mode = Running
• Reset port = Non-zero signal
• Signal = u
• Sample time = 1/3
• Samples per frame = 3
where
u = [6 1 3 -7 2 5 8 0 -1 -3 2 1;1 3 9 2 4 1 6 2 5 0 4 17]'
• Delay (samples) = 2
• Sample time = 1
• Samples per frame = 1
5-300
Maximum
61 61
First
13 t=0 0 First output 63
input 39 69
–7 2 69
2 4 t=1 0 69
5 1 69
8 6 86
Simulation time
0 2 t=2 1 86 Reset
–1 5 86
–3 0 8 6
2 4 t=3 0 8 6
1 17 8 17
The statsdem demo illustrates the operation of several blocks from the
Statistics library.
Dialog Box
Mode
The block’s mode of operation: Output the maximum value of each input
(Value), the index of the maximum value (Index), both the value and the
5-301
Maximum
index (Value and index), or track the maximum value of the input
sequence over time (Running).
Reset port
Specifies the reset event detected at the Rst input port when Running is
selected as the Mode parameter. The reset operation can be set to occur
when a rising and/or falling edge is detected at the Rst port, (Rising edge,
Falling edge, Either Edge), or when a non-zero sample is detected at the
Rst port (Non-zero sample). The Rst port can be disabled by selecting
None.
5-302
Mean
Purpose 5Mean
Find the mean value of an input or sequence of inputs.
Library Statistics
Description The Mean block computes the mean of each column in the input, or tracks the
mean values in a sequence of inputs over a period of time. The Running mean
parameter selects between basic operation and running operation.
Basic Operation
When the Running mean check box is not selected, the block computes the
mean of each column of M-by-N input matrix u independently at each sample
time.
y = mean(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
The output at each sample time, y, is a 1-by-N vector containing the mean
value for each column in u. The mean of a complex input is computed
independently for the real and imaginary components, as shown below.
Complex
input (u)
4 + 2i Output (y)
–3 – i
4 + 4i 0 + 1.6i
–1 + 4 i
–4–i
The frame status of the output is the same as that of the input.
Running Operation
When the Running mean check box is selected, the block tracks the mean
value of each channel in a time-sequence of M-by-N inputs. For sample-based
inputs, the output is a sample-based M-by-N matrix with each element yij
containing the mean value of element uij over all inputs since the last reset. For
frame-based inputs, the output is a frame-based M-by-N matrix with each
5-303
Mean
element yij containing the mean value of the jth column over all inputs since
the last reset, up to and including element uij of the current input.
If the Reset port parameter is set to Non-zero sample, the optional Rst port
is enabled and the block resets the running mean when the scalar input at the
Rst port is nonzero. (The Rst port can be disabled by setting the Reset port
parameter to None.) For sample-based inputs, the running mean for each
channel is initialized to the value in the corresponding channel of the current
input. For frame-based inputs, the running mean for each channel is initialized
to the earliest value in each channel of the current input.
As in basic operation, length-M 1-D vector inputs and sample-based length-M
row vector inputs are both treated as M-by-1 column vectors.
Example The Mean block in the model below calculates the running mean of a
frame-based 3-by-2 (two-channel) matrix input, u. The running mean is reset
at t=2 by an impulse to the block’s Rst port.
• Running mean =
• Reset port = Non-zero sample
• Signal = u
• Sample time = 1/3
• Samples per frame = 3
where
u = [6 1 3 -7 2 5 8 0 -1 -3 2 1;1 3 9 2 4 1 6 2 5 0 4 17]'
5-304
Mean
• Delay (samples) = 2
• Sample time = 1
• Samples per frame = 1
61 6.00 1.00
First First output
13 t=0 0 3.50 2.00
input 39 3.33 4.33
–7 2 0.75 3.75
2 4 t=1 0 1.00 3.80
5 1 1.67 3.33
8 6 8.00 6.00
Simulation time
–3 0 1.00 3.25
2 4 t=3 0 1.20 3.40
1 17 1.17 5.67
The statsdem demo illustrates the operation of several blocks from the
Statistics library.
Dialog Box
5-305
Mean
Running mean
Enables running operation when selected.
Reset port
Enables the Rst input port when set to Non-zero sample, and disables the
Rst input port when set to None.
5-306
Median
Purpose 5Median
Find the median value of an input.
Library Statistics
Description The Median block computes the median value of each column in an M-by-N
input matrix.
y = median(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
The output at each sample time, y, is a sample-based 1-by-N vector containing
the median value for each column in u.
When M is odd, the block sorts the column elements by value, and outputs the
central row of the sorted matrix.
s = sort(u);
y = s((M+1)/2,:)
When M is even, the block sorts the column elements by value, and outputs the
average of the two central rows in the sorted matrix.
s = sort(u);
y = mean([s(M/2,:);s(M/2+1,:)])
Complex inputs are sorted by magnitude, and the real and imaginary
components are averaged independently (for even M).
Dialog Box
5-307
Median
5-308
Minimum
Purpose 5Minimum
Find the minimum values in an input or sequence of inputs.
Library Statistics
Description The Minimum block identifies the value and position of the smallest element
in each column of the input, or tracks the minimum values in a sequence of
inputs over a period of time. The Mode parameter specifies the block’s mode of
operation, and can be set to Value, Index, Value and Index, or Running.
Value Mode
When Mode is set to Value, the block computes the minimum value in each
column of the M-by-N input matrix u independently at each sample time.
val = min(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
The output at each sample time, val, is a 1-by-N vector containing the
minimum value of each column in u. For complex inputs, the block selects the
value in each column that has the minimum magnitude, min(abs(u)), as
shown below.
Complex
Input (u) abs(u) Output (val)
4 + 2i 4.47
–3–i 3.16
4 + 4i 5.65 –3–i
– 1 + 4i 4.12
–4–i 4.12
The frame status of the output is the same as that of the input.
Index Mode
When Mode is set to Index, the block computes the minimum value in each
column of the M-by-N input matrix u,
[val,idx] = min(u) % Equivalent MATLAB code
5-309
Minimum
and outputs the sample-based 1-by-N index vector, idx. Each value in idx is an
integer in the range [1 M] indexing the minimum value in the corresponding
column of u.
As in Value mode, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
If a minimum value occurs more than once in a particular column of u, the
computed index corresponds to the first occurrence. For example, if the input
is the column vector [-1 2 3 2 -1]', the computed index of the minimum
value is 1 rather than 5.
Running Mode
When Mode is set to Running, the block tracks the minimum value of each
channel in a time-sequence of M-by-N inputs. For sample-based inputs, the
output is a sample-based M-by-N matrix with each element yij containing the
minimum value observed in element uij for all inputs since the last reset. For
frame-based inputs, the output is a frame-based M-by-N matrix with each
element yij containing the minimum value observed in the jth column of all
inputs since the last reset, up to and including element uij of the current input.
If the Reset port parameter is set to Non-zero sample, the optional Rst port
is enabled and the block resets the running minimum when the scalar input at
the Rst port is nonzero. (The Rst port can be disabled by setting the Reset port
parameter to None.) For sample-based inputs, the running minimum for each
channel is initialized to the value in the corresponding channel of the current
input. For frame-based inputs, the running minimum for each channel is
initialized to the earliest value in each channel of the current input.
As in the other modes, length-M 1-D vector inputs and sample-based length-M
row vector inputs are both treated as M-by-1 column vectors.
Example The Minimum block in the model below calculates the running minimum of a
frame-based 3-by-2 (two-channel) matrix input. The running minimum is reset
at t=2 by an impulse to the block’s Rst port.
5-310
Minimum
• Mode = Running
• Reset port = Non-zero sample
• Signal = u
• Sample time = 1/3
• Samples per frame = 3
where
u = [6 1 3 -7 2 5 8 0 -1 -3 2 1;1 3 9 2 4 2 6 2 5 0 4 17]'
• Delay (samples) = 2
• Sample time = 1
• Samples per frame = 1
5-311
Minimum
In Rst Output
61 61
First
13 t=0 0 First output 11
input 39 11
–7 2 –7 1
2 4 t=1 0 –7 1
5 2 –7 1
8 6 8 6
Simulation time
0 2 t=2 1 0 2 Reset
–1 5 –1 2
–3 0 –3 0
2 4 t=3 0 –3 0
1 17 –3 0
Dialog Box
Mode
The block’s mode of operation: Output the minimum value of each input
(Value), the index of the minimum value (Index), both the value and the
index (Value and Index), or track the minimum values in the input
sequence over time (Running).
Reset port
Enables the Rst input port when set to Non-zero sample, and disables the
Rst input port when set to None.
5-312
Minimum
5-313
Modified Covariance AR Estimator
Description The Modified Covariance AR Estimator block uses the modified covariance
method to fit an autoregressive (AR) model to the input data. This method
minimizes the forward and backward prediction errors in the least-squares
sense. The input is a frame of consecutive time samples, which is assumed to
be the output of an AR system driven by white noise. The block computes the
normalized estimate of the AR system parameters, A(z), independently for each
successive input.
G G
H ( z ) = ------------ = -------------------------------------------------------------------------------
A(z) –1
1 + a ( 2 )z + … + a ( p + 1 )z
–p
Dialog Box
Estimation order
The order of the AR model, p.
5-314
Modified Covariance AR Estimator
5-315
Modified Covariance Method
Description The Modified Covariance Method block estimates the power spectral density
(PSD) of the input using the modified covariance method. This method fits an
autoregressive (AR) model to the signal by minimizing the forward and
backward prediction errors in the least-squares sense. The order of the all-pole
model is the value specified by the Estimation order parameter, and the
spectrum is computed from the FFT of the estimated AR model parameters.
The input is a sample-based vector (row, column, or 1-D) or frame-based vector
(column only) representing a frame of consecutive time samples from a
single-channel signal. The block’s output (a column vector) is the estimate of
the signal’s power spectral density at Nfft equally spaced frequency points in
the range [0,Fs), where Fs is the signal’s sample frequency.
When Inherit FFT length from input dimensions is selected, Nfft is specified
by the frame size of the input, which must be a power of 2. When Inherit FFT
length from input dimensions is not selected, Nfft is specified as a power of 2
by the FFT length parameter, and the block zero pads or truncates the input
to Nfft before computing the FFT. The output is always sample-based.
See the Burg Method block reference for a comparison of the Burg Method,
Covariance Method, Modified Covariance Method, and Yule-Walker Method
blocks.
Examples The dspsacomp demo compares the modified covariance method with several
other spectral estimation methods.
5-316
Modified Covariance Method
Dialog Box
Estimation order
The order of the AR model.
Inherit FFT length from input dimensions
When selected, uses the input frame size as the number of data points, Nfft,
on which to perform the FFT. Tunable.
FFT length
The number of data points, Nfft, on which to perform the FFT. If Nfft
exceeds the input frame size, the frame is zero-padded as needed. This
parameter is enabled when Inherit FFT length from input dimensions is
not selected.
5-317
Modified Covariance Method
5-318
Multiphase Clock
Description The Multiphase Clock block generates a sample-based 1-by-N vector of clock
signals, where the integer N is specified by the Number of phases parameter.
Each of the N phases has the same frequency, f, specified in hertz by the Clock
frequency parameter.
The clock signal indexed by the Starting phase parameter is the first to
become active, at t=0. The other signals in the output vector become active in
turn, each one lagging the preceding signal’s activation by 1/(N∗f) seconds, the
phase interval. The period of the sample-based output is therefore 1/(N∗f)
seconds.
The active level can be either high (1) or low (0), as specified by the Active level
(polarity) parameter. The duration of the active level, D, is set by the Number
of phase intervals over which the clock is active. This value, which can be
an integer value between 1 and N-1, specifies the number of phase intervals
that each signal should remain in the active state after becoming active. The
active duty cycle of the signal is D/N.
Example Configure the Multiphase Clock block in the model below to generate a 100 Hz
five-phase output in which the third signal is first to become active. Use a high
active level with a duration of one interval.
5-319
Multiphase Clock
The Scope window below shows the Multiphase Clock block’s output for these
settings. Note that the first active level appears at t=0 on y(3), the second
active level appears at t=0.002 on y(4), the third active level appears at
t=0.004 on y(5), the fourth active level appears at t=0.006 on y(1), and the
fifth active level appears at t=0.008 on y(2). Each signal becomes active
1/(5∗100) seconds after the previous signal.
Signal 1
Signal 2
Signal 3
Signal 4
Signal 5
5-320
Multiphase Clock
Dialog Box
Clock frequency
The frequency of all output clock signals.
Number of phases
The number of different phases, N, in the output vector.
Starting phase
The vector index of the output signal to first become active. Tunable.
Number of phase intervals over which clock is active
The duration of the active level for every output signal. Tunable.
Active level
The active level, high (1) or low (0). Tunable.
See “Creating Signals Using Signal Generator Blocks” on page 3-36 for related
information.
5-321
Multiport Selector
Description The Multi-port Selector block extracts multiple subsets of rows or columns
from M-by-N input matrix u, and propagates each new submatrix to a distinct
output port. A length-M 1-D vector input is treated as an M-by-1 matrix.
The Indices to output parameter is a cell array whose kth cell contains a
one-dimensional indexing expression specifying the subset of input rows or
columns to be propagated to the kth output port. The total number of cells in
the array determines the number of output ports on the block.
When the Select parameter is set to Rows, the specified one-dimensional
indices are used to select matrix rows, and all elements on the chosen rows are
included. When the Select parameter is set to Columns, the specified
one-dimensional indices are used to select matrix columns, and all elements on
the chosen columns are included. A given input row or column can appear any
number of times in any of the outputs, or not at all.
The Indices to output parameter is tunable, so you can change the values of
the indices at any time during the simulation; however, the number of cells in
the array (i.e., the number of output ports) and the size of each submatrix in
the output must remain the same while the simulation is running.
When an index references a nonexistent row or column of the input, the block
reacts with the behavior specified by the Invalid index parameter. The
following options are available:
• Clip index – Clip the index to the nearest valid value, and do not issue an
alert.
Example: For a 64-by-4 input with Select = Rows, an index of 72 is clipped
to 64; with Select = Columns, an index of 72 is clipped to 4. In both cases, an
index of -2 is clipped to 1.
• Clip and warn – Display a warning message in the MATLAB command
window, and clip as above.
• Generate error – Display an error dialog box and terminate the simulation.
5-322
Multiport Selector
This is a four-cell array, which requires the block to generate four independent
outputs (each at a distinct port). The table below shows the dimensions of these
outputs when Select = Rows and the input dimension is M-by-N.
Dialog Box
Select
The dimension of the input to select, Rows or Columns.
Indices to output
A cell array specifying the row- or column-subsets to propagate to each of
the output ports. The number of cells in the array determines the number
of output ports on the block. This parameter is tunable, but the size of the
cell array (i.e., the number of output ports) and the size of each submatrix
in the output must remain the same while the simulation is running.
5-323
Multiport Selector
Invalid index
Response to an invalid index value. Tunable.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-324
N-Sample Enable
Description The N-Sample Enable block outputs the inactive value (0 or 1, whichever is not
selected in the Active level parameter) during the first N sample times, where
N is the Trigger count value. Beginning with output sample N+1, the block
outputs the active value (1 or 0, whichever is selected in the Active level
parameter) until a reset event occurs or the simulation terminates.
The Reset input check box enables the Rst input port. At any time during the
count, a trigger event at the input port resets the counter to its initial state.
The triggering event is specified by the Trigger type pop-up menu, and can be
one of the following:
• Rising edge triggers the reset when the trigger input rises from a negative
value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers the reset when the trigger input falls from a positive
value to zero or a negative value, or from zero to a negative value.
• Either edge triggers the reset when either a rising or falling edge (as
described above) occurs.
Dialog Box
5-325
N-Sample Enable
Trigger count
The number of samples for which the block outputs the active value.
Tunable.
Active level
The value to output after the first N sample times, 0 or 1. Tunable.
Reset input
Enables the Rst input port.
Trigger type
The type of event that triggers a reset when the Rst port is enabled.
Tunable.
Sample time
The sample period, Ts, for the block’s counter. The block switches from the
active value to the inactive value at t=Ts∗(N+1).
See “Creating Signals Using Signal Generator Blocks” on page 3-36 for related
information.
5-326
N-Sample Switch
Description The N-Sample Switch block outputs the signal connected to the top input port
during the first N sample times after the simulation begins or the block is reset,
where N is specified by the Switch count value. Beginning with output sample
N+1, the block outputs the signal connected to the bottom input until the next
reset event or the end of the simulation.
The sample period of the output is specified by the Sample time parameter
(i.e., the output sample period is not inherited from the sample period of either
input). The block applies a zero-order hold at the input ports, so the value the
block reads from a given port between input sample times is the value of the
most recent input to that port.
Both inputs must have the same dimension, except in the following two cases:
• When one input is a scalar, the block expands the scalar input to match the
size of the other input.
• When one input is a 1-D vector and the other input is a row or column vector
with the same number of elements, the block reshapes the 1-D vector to
match the dimension of the other input.
• Rising edge triggers the reset when the trigger input rises from a negative
value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers the reset when the trigger input falls from a positive
value to zero or a negative value, or from zero to a negative value.
• Either edge triggers the reset when either a rising or falling edge (as
described above) occurs.
5-327
N-Sample Switch
Dialog Box
Switch count
The number of sample periods, N, for which the output is connected to the
top input before switching to the bottom input. Tunable.
Reset input
Enables the Rst input port when selected.
Trigger type
The type of event at the Rst port that resets the block’s counter. This
parameter is enabled when Reset input is selected. Tunable.
Sample time
The sample period, Ts, for the block’s counter. The block switches inputs at
t=Ts∗(N+1).
5-328
Normalization
Purpose 5Normalization
Normalize an input by its 2-norm or squared 2-norm.
Description The Normalization block independently normalizes each column of the M-by-N
matrix input, u.
2-Norm
When the Norm parameter specifies 2-norm, the block normalizes the jth
input column as follows.
u ij
y ij = ---------------------
u j+b
2 2 2
u j = u1 + u2 + L + uM
Equivalently,
y = u ./ (norm(u) + b) % Equivalent MATLAB code
Squared 2-Norm
When the Norm parameter specifies Squared 2-norm, the block normalizes
the jth input column as follows.
u ij
y ij = ----------------------
2
u j +b
where
2 2 2 2
u j = u1 + u2 + L + uM
Equivalently,
y = u ./ (norm(u).^2 + b) % Equivalent MATLAB code
5-329
Normalization
The output has the same dimension and frame status as the input. For
convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors, and the output retains
the dimensions of the input.
Dialog Box
Norm
The type of normalization to apply, 2-norm or Squared 2-norm. Tunable.
Normalization bias
The value b to be added in the denominator to avoid division by zero.
Tunable.
5-330
Overlap-Add FFT Filter
Description The Overlap-Add FFT Filter block uses an FFT to implement the overlap-add
method, a technique that combines successive frequency-domain filtered
sections of an input sequence.
Valid inputs to this block are 1-D vectors, sample-based vectors, frame-based
vectors, and frame-based full matrices. All outputs are unbuffered into
sample-based row vectors. The length of the output vector is equal to the
number of channels in the input vector. An M-by-1 sample-based input has M
channels, so it would result in a length-M sample-based output vector. An
M-by-1 frame-based input has only one channel, so would result in a 1-by-1
(scalar) output.
The block’s data output rate is M times faster than its data input rate, where
M is the input frame-size. Thus, the block’s data input and output rates are the
same when the inputs are 1-D vectors, sample-based vectors, or frame-based
row vectors. For frame-based column and frame-based full-matrix inputs, the
block’s data output rate is M times greater than the block’s data input rate.
1-D vectors are treated as length-N sample-based vectors, and result in
sample-based length-N row vectors.
The block breaks the scalar input sequence u, of length nu, into length-L
nonoverlapping data sections,
u . . .
L 2L 3L ceil(nu/L)*L
The numerator coefficients for H(z) are specified as a vector by the FIR
coefficients parameter. The coefficient vector, b = [b(1) b(2) ... b(n+1)],
can be generated by one of the filter design functions in the Signal Processing
Toolbox, such as fir1. All filter states are internally initialized to zero.
5-331
Overlap-Add FFT Filter
If either the filter coefficients or the inputs to the block are complex, the
Output parameter should be set to Complex. Otherwise, the default Output
setting, Real, instructs the block to take only the real part of the solution.
The block’s overlap-add operation is equivalent to
y = ifft(fft(u(i:i+L-1),nfft) .* fft(b,nfft))
The block overlaps successive output sections by n points and sums them.
L L+n
2L 2L+n
3L 3L+n
. . .
The first L samples of each summation are output in sequence. The block
chooses the parameter L based on the filter order and the FFT size.
L = nfft - n
Latency
In single-tasking operation, the Overlap-Add FFT Filter block has a latency of
nfft-n+1 samples. The first nfft-n+1 consecutive outputs from the block are
zero; the first filtered input value appears at the output as sample nfft-n+2.
In multitasking operation, the Overlap-Add FFT Filter block has a latency of
2*(nfft-n+1) samples. The first 2*(nfft-n+1) consecutive outputs from the
block are zero; the first filtered input value appears at the output as sample
2*(nfft-n)+3.
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
5-332
Overlap-Add FFT Filter
Dialog Box
FFT size
The size of the FFT, which should be a power-of-two value greater than the
length of the specified FIR filter.
FIR coefficients
The filter numerator coefficients.
Output
The complexity of the output; Real or Complex. If the input signal or the
filter coefficients are complex, this should be set to Complex.
See “Designing Filters with Various Filter Structures” on page 4-6 for related
information.
5-333
Overlap-Save FFT Filter
Description The Overlap-Save FFT Filter block uses an FFT to implement the overlap-save
method, a technique that combines successive frequency-domain filtered
sections of an input sequence.
Valid inputs to this block are 1-D vectors, sample-based vectors, frame-based
vectors, and frame-based full matrices. All outputs are unbuffered into
sample-based row vectors. The length of the output vector is equal to the
number of channels in the input vector. An M-by-1 sample-based input has M
channels, so it would result in a length-M sample-based output vector. An
M-by-1 frame-based input has only one channel, so would result in a 1-by-1
(scalar) output.
The block’s data output rate is M times faster than its data input rate, where
M is the input frame-size. Thus, the block’s data input and output rates are the
same when the inputs are 1-D vectors, sample-based vectors, or frame-based
row vectors. For frame-based column and frame-based full-matrix inputs, the
block’s data output rate is M times greater than the block’s data input rate.
1-D vectors are treated as length-N sample-based vectors, and result in
sample-based length-N row vectors.
Overlapping sections of input u are circularly convolved with the FIR filter
coefficients
–1 –n
H ( z ) = B ( z ) = b1 + b2 z + … + bn + 1 z
The numerator coefficients for H(z) are specified as a vector by the FIR
coefficients parameter. The coefficient vector, b = [b(1) b(2) ... b(n+1)],
can be generated by one of the filter design functions in the Signal Processing
Toolbox, such as fir1. All filter states are internally initialized to zero.
If either the filter coefficients or the inputs to the block are complex, the
Output parameter should be set to Complex. Otherwise, the default Output
setting, Real, instructs the block to take only the real part of the solution.
5-334
Overlap-Save FFT Filter
The first n points of the circular convolution are invalid and are discarded. The
Overlap-Save FFT Filter block outputs the remaining nfft-n points, which are
equivalent to the linear convolution.
Latency
In single-tasking operation, the Overlap-Save FFT Filter block has a latency of
nfft-n+1 samples. The first nfft-n+1 consecutive outputs from the block are
zero; the first filtered input value appears at the output as sample nfft-n+2.
In multitasking operation, the Overlap-Save FFT Filter block has a latency of
2*(nfft-n+1) samples. The first 2*(nfft-n+1) consecutive outputs from the
block are zero; the first filtered input value appears at the output as sample
2*(nfft-n)+3.
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
Dialog Box
5-335
Overlap-Save FFT Filter
FFT size
The size of the FFT, which should be a power-of-two value greater than the
length of the specified FIR filter.
FIR coefficients
The filter numerator coefficients.
Output
The complexity of the output; Real or Complex. If the input signal or the
filter coefficients are complex, this should be set to Complex.
See “Designing Filters with Various Filter Structures” on page 4-6 for related
information.
5-336
Pad
Purpose 5Pad
Alter the input size by padding or truncating rows and/or columns.
Description The Pad block changes the size of the input matrix from Mi-by-Ni to Mo-by-No
by padding or truncating along the rows, the columns, or both dimensions. The
dimensions of the output, Mo and No, are specified by the Number of output
rows and Number of output columns parameters, respectively. The value
with which to pad the input is set by the Value parameter.
The behavior of the Pad block and Zero Pad block are identical, with the
exception that the Pad block can pad the input matrix with values other than
zero. See the Zero Pad block reference for more information on the behavior of
the Pad block.
Dialog Box
Value
The scalar value with which to pad the input matrix. Tunable.
Pad along
The direction along which to pad or truncate. Columns specifies that the
row dimension should be changed to Mo. Rows specifies that the column
dimension should be changed to No. Columns and rows specifies that both
column and row dimensions should be changed. None disables padding and
truncation and passes the input through to the output unchanged.
5-337
Pad
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-338
Permute Matrix
Description The Permute Matrix block reorders the rows or columns of M-by-N input
matrix A as specified by indexing input P.
When the Permute parameter is set to Rows, the block uses the rows of A to
create a new matrix with the same column dimension. Input P is a length-L
vector whose elements determine where each row from A should be placed in
the L-by-N output matrix.
% Equivalent MATLAB code
y = [A(P(1),:) ; A(P(2),:) ; A(P(3),:) ; ... ; A(P(end),:)]
For row permutation, a length-M 1-D vector input at the A port is treated as a
M-by-1 matrix.
When the Permute parameter is set to Columns, the block uses the columns
of A to create a new matrix with the same row dimension. Input P is a length-L
vector whose elements determine where each column from A should be placed
in the M-by-L output matrix.
% Equivalent MATLAB code
y = [A(:,P(1)) A(:,P(2)) A(:,P(3)) ... A(:,P(end))]
For column permutation, a length-N 1-D vector input at the A port is treated as
a 1-by-N matrix.
When an index value in input P references a nonexistent row or column of
matrix A, the block reacts with the behavior specified by the Invalid
permutation index parameter. The following options are available:
• Clip index – Clip the index to the nearest valid value (1 or M for row
permutation, and 1 or N for column permutation), and do not issue an alert.
Example: For a 3-by-7 input matrix, a column index of 9 is clipped to 7, and
a row index of -2 is clipped to 1.
• Clip and warn – Display a warning message in the MATLAB command
window, and clip the index as described above.
• Generate error – Display an error dialog box and terminate the simulation.
5-339
Permute Matrix
When length of the permutation vector P is not equal to the number of rows or
columns of the input matrix A, you can choose to get an error dialog box and
terminate the simulation by checking Error when length of P is not equal
to Permute dimension size.
If input A is frame-based, the output is frame-based; otherwise, the output is
sample-based.
Example In the model below, the top Permute Matrix block places the second row of the
input matrix in both the first and fifth rows of the output matrix, and places
the third row of the input matrix in the three middle rows of the output matrix.
The bottom Permute Matrix block places the second column of the input matrix
in both the first and fifth columns of the output matrix, and places the third
column of the input matrix in the three middle columns of the output matrix.
4 5 6
7 8 9
7 8 9
7 8 9
4 5 6
23332
56665
89998
As shown in the example above, rows and columns of A can appear any number
of times in the output, or not at all.
5-340
Permute Matrix
Dialog Box
Permute
Method of constructing the output matrix; by permuting rows or columns
of the input.
Invalid permutation index
Response to an invalid index value. Tunable, except in Simulink’s external
mode.
Error when length of P is not equal to Permute dimension size
Option to display an error dialog box and terminate the simulation if the
length of the permutation vector P is not equal to the number of rows or
columns of the input matrix A.
5-341
Permute Matrix
5-342
Polynomial Evaluation
Description The Polynomial Evaluation block applies a polynomial function to the real or
complex input at the In port.
y = polyval(u) % Equivalent MATLAB code
[1 2 3 4 5] 4 3 2
y = u + 2u + 3u + 4u + 5
[1 0 3 0 5] 4 2
y = u + 3u + 5
5-343
Polynomial Evaluation
Dialog Box
5-344
Polynomial Stability Test
Description The Polynomial Stability Test block uses the Schur-Cohn algorithm to
determine whether all roots of a polynomial are within the unit circle.
y = all(abs(roots(u)) < 1) % Equivalent MATLAB code
arranged in order of descending exponents, u1, u2, …, uM. The polynomial has
order M-1 and positive integer exponents.
Inputs can be frame-based or sample-based, and both represent the polynomial
coefficients as shown above. For convenience, a length-M 1-D vector input is
treated as an M-by-1 matrix.
The output is a 1-by-N matrix with each column containing the value 1 or 0.
The value 1 indicates that the polynomial in the corresponding column of the
input is stable; i.e., the magnitudes of all solutions to f(x) = 0 are less than 1.
The value 0 indicates that the polynomial in the corresponding column of the
input may be unstable; i.e., the magnitude of at least one solution to f(x) = 0 is
greater than or equal to 1.
The output is always sample-based.
Applications
This block is most commonly used to check the pole locations of the
denominator polynomial, A(z), of a transfer function, H(z).
–1 –( m – 1 )
B(z) b1 + b2 z + … + bm z
H ( z ) = ------------ = ---------------------------------------------------------------------------
A(z) a1 + a2 z + … + an z
–1 –( n – 1 )
The poles are the n-1 roots of the denominator polynomial, A(z). If any poles are
located outside the unit circle, the transfer function H(z) is unstable. As is
5-345
Polynomial Stability Test
Dialog Box
5-346
Pseudoinverse
Purpose 5Pseudoinverse
Compute the Moore-Penrose pseudoinverse of a matrix.
• AA+ = (AA+)*
• A+A = (A+A)*
• AA+A = A
• A+AA+ = A+
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-347
Pseudoinverse
5-348
QR Factorization
A e = QR
The block selects a column permutation vector E, which ensures that the
diagonal elements of matrix R are arranged in order of decreasing magnitude.
r i + 1 , j + 1 > r i, j i=j
Example A sample factorization is shown below. The input to the block is matrix A,
which is permuted according to vector E to produce matrix Ae. Matrix Ae is
factored to produce the Q and R output matrices.
5-349
QR Factorization
(2 1 3)
–1 9 2
A = 8 –1 –5
e
–5 2 7
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-350
QR Solver
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The QR Solver block solves the linear system AX=B, which can be
overdetermined, underdetermined, or exactly determined. The system is solved
by applying QR factorization to the M-by-N matrix, A, at the A port. The input
to the B port is the right-hand-side M-by-L matrix, B. A length-M 1-D vector
input at either port is treated as an M-by-1 matrix.
The output at the x port is the N-by-L matrix, X. X is always sample based, and
is chosen to minimize the sum of the squares of the elements of B-AX. When B
is a vector, this solution minimizes the vector 2-norm of the residual (B-AX is
the residual). When B is a matrix, this solution minimizes the matrix
Frobenius norm of the residual. In this case, the columns of X are the solutions
to the L corresponding systems AXk=Bk, where Bk is the kth column of B, and
Xk is the kth column of X.
X is known as the minimum-norm-residual solution to AX=B. The
minimum-norm-residual solution is unique for overdetermined and exactly
determined linear systems, but it is not unique for underdetermined linear
systems. Thus when the QR Solver is applied to an underdetermined system,
the output X is chosen such that the number of nonzero entries in X is
minimized.
A e = QR
Ae X = Be ,
and
QRX = B e
5-351
QR Solver
is solved for X by noting that Q-1 = Q* and substituting Y = Q*Be. This requires
computing a matrix multiplication for Y and solving a triangular system for X.
RX = Y
Dialog Box
5-352
Queue
Purpose 5Queue
Store inputs in a FIFO register.
Description The Queue block stores a sequence of input samples in a FIFO (first in, first
out) register. The register capacity is set by the Register size parameter, and
inputs can be scalars, vectors, or matrices.
The block pushes the input at the In port onto the end of the queue when a
trigger event is received at the Push port. When a trigger event is received at
the Pop port, the block pops the first element off the queue and holds the Out
port at that value. The first input to be pushed onto the queue is always the
first to be popped off.
1
1
register size
0
0
1 1 0 0 1
empty
empty
empty
first in
1 1 1 0 0 1
empty
empty
1 1 0 0 1 1
0 1 0 0 0 0
0 1 1 0 1 1
1 1 1 0 0
empty
empty
empty
1 1 0 0 1
Popping the queue
0 1 0 0 0
0 1 1 0 1
1
1 first out
0
1
A trigger event at the optional Clr port (enabled by the Clear input check box)
empties the queue contents. If Clear output port on reset is selected, then a
trigger event at the Clr port empties the queue and sets the value at the Out
port to zero. This setting also applies when a disabled subsystem containing
5-353
Queue
the Queue block is reenabled; the Out port value is only reset to zero in this case
if Clear output port on reset is selected.
When two or more of the control input ports are triggered at the same time
step, the operations are executed in the following order:
1 Clr
2 Push
3 Pop
The triggering event for the Push, Pop, and Clr ports is specified by the Trigger
type pop-up menu, and can be one of the following:
• Rising edge triggers execution of the block when the trigger input rises from
a negative value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers execution of the block when the trigger input falls from
a positive value to zero or a negative value, or from zero to a negative value.
• Either edge triggers execution of the block when either a rising or falling
edge (as described above) occurs.
The Push onto full register parameter specifies the block’s behavior when a
trigger is received at the Push port but the register is full. The Pop empty
register parameter specifies the block’s behavior when a trigger is received at
the Pop port but the register is empty. The following options are available for
both cases:
The Push onto full register parameter additionally offers the Dynamic
reallocation option, which dynamically resizes the register to accept as many
additional inputs as memory permits. To find out how many elements are on
the queue at a given time, enable the Num output port by selecting the Output
number of register entries option.
5-354
Queue
Examples Example 1
The table below illustrates the Queue block’s operation for a Register size of 4,
Trigger type of Either edge, and Clear output port on reset enabled.
Because the block triggers on both rising and falling edges in this example,
each transition from 1 to 0 or 0 to 1 in the Push, Pop, and Clr columns below
represents a distinct trigger event. A 1 in the Empty column indicates an empty
queue, while a 1 in the Full column indicates a full queue.
1 0 0 0 top bottom 0 1 0 0
2 1 0 0 top 2 bottom 0 0 0 1
3 0 0 0 top 3 2 bottom 0 0 0 2
4 1 0 0 top 4 3 2 bottom 0 0 0 3
5 0 0 0 top 5 4 3 2 bottom 0 0 1 4
6 0 1 0 top 5 4 3 bottom 2 0 0 3
7 0 0 0 top 5 4 bottom 3 0 0 2
8 0 1 0 top 5 bottom 4 0 0 1
9 0 0 0 top bottom 5 1 0 0
10 1 0 0 top 10 bottom 5 0 0 1
11 0 0 0 top 11 10 bottom 5 0 0 2
12 1 0 1 top 12 bottom 0 0 0 1
Note that at the last step shown, the Push and Clr ports are triggered
simultaneously. The Clr trigger takes precedence, and the queue is first
cleared and then pushed.
Example 2
The dspqdemo demo provides another example of Queue operation.
5-355
Queue
Dialog Box
Register size
The number of entries that the FIFO register can hold.
Trigger type
The type of event that triggers the block’s execution. Tunable.
Push onto full register
Response to a trigger received at the Push port when the register is full.
Pop empty register
Response to a trigger received at the Pop port when the register is empty.
Tunable.
Empty register output
Enable the Empty output port, which is high (1) when the queue is empty,
and low (0) otherwise.
Full register output
Enable the Full output port, which is high (1) when the queue is full, and
low (0) otherwise. The Full port remains low when Dynamic reallocation
is selected from the Push onto full register parameter.
Output number of register entries
Enable the Num output port, which tracks the number of entries currently
on the queue.
5-356
Queue
Clear input
Enable the Clr input port, which empties the queue when the trigger
specified by the Trigger type is received.
Clear output port on reset
Reset the Out port to zero (in addition to clearing the queue) when a trigger
is received at the Clr input port. Tunable.
5-357
Random Source
Description The Random Source block generates a frame of M values drawn from a uniform
or Gaussian pseudorandom distribution, where M is specified by the Samples
per frame parameter.
This reference page contains a detailed discussion of the following Random
Source block topics:
Distribution Type
When the Source type parameter is set to Uniform, the output samples are
drawn from a uniform distribution whose minimum and maximum values are
specified by the Minimum and Maximum parameters, respectively. All values
in this range are equally likely to be selected. A length-N vector specified for
one or both of these parameters generates an N-channel output (M-by-N
matrix) containing a unique random distribution in each channel.
For example, specify
• Minimum = [ 0 0 -3 -3]
• Maximum = [10 10 20 20]
5-358
Random Source
For complex output, the Variance parameter, σ2, specifies the total variance
for each output channel. This is the sum of the variances of the real and
imaginary components in that channel.
2 2 2
σ = σ Re + σ Im
5-359
Random Source
The specified variance is equally divided between the real and imaginary
components, so that
2
2 σ
σ Re = ------
2
2
2 σ
σ Im = ------
2
Output Repeatability
The Repeatability parameter determines whether or not the block outputs the
same signal each time you run the simulation. You can set the parameter to one
of the following options:
• Repeatable — The block outputs the same signal each time you run the
simulation. The first time you run the simulation, the block randomly selects
an initial seed. The block reuses these same initial seeds every time you
rerun the simulation.
• Specify seed — The block outputs the same signal each time you run the
simulation. Every time you run the simulation, the block uses the initial
seed(s) specified by the Initial seed parameter. Also see the next section,
“Specifying the Initial Seed”.
• Not repeatable — The block does not output the same signal each time you
run the simulation. Every time you run the simulation, the block randomly
selects an initial seed.
5-360
Random Source
Sample Period
The Sample time parameter value, Ts, specifies the random sequence sample
period when the Sample mode parameter is set to Discrete. In this mode, the
block generates the number of samples specified by the Samples per frame
parameter value, M, and outputs this frame with a period of M∗Ts. For M=1,
the output is sample-based; otherwise, the output is frame-based.
When Sample mode is set to Continuous, the block is configured for
continuous-time operation, and the Sample time and Samples per frame
parameters are disabled. Note that many blocks in the DSP Blockset do not
accept continuous-time inputs.
5-361
Random Source
Dialog Box
Source type
The distribution from which to draw the random values, Uniform or
Gaussian.
Minimum
The minimum value in the uniform distribution. This parameter is only
enabled when Uniform is selected from the Source type parameter.
Tunable.
5-362
Random Source
Maximum
The maximum value in the uniform distribution. This parameter is only
enabled when Uniform is selected from the Source type parameter.
Tunable.
Mean
The mean of the Gaussian (normal) distribution. This parameter is only
enabled when Gaussian is selected from the Source type parameter.
Tunable.
Variance
The variance of the Gaussian (normal) distribution. This parameter is only
enabled when Gaussian is selected from the Source type parameter.
Tunable.
Repeatability
The repeatability of the block output: Not repeatable, Repeatable, or
Specify seed. In the Repeatable and Specify seed settings, the block
outputs the same signal every time you run the simulation. For details, see
“Output Repeatability” on page 5-360.
Initial seed
The initial seed(s) to use for the random number generator when you set
the Repeatability parameter to Specify seed. For details, see “Specifying
the Initial Seed” on page 5-360.
Inherit output port attributes
When selected, allows the block to inherit the sample mode, sample period,
and complexity of a downstream block. (The Sample mode, Sample time,
Samples per frame, and Output complexity parameters are disabled.)
The output is a length-M sample-based 1-D vector, where length M is
inherited from the downstream block. If the Minimum, Maximum, Mean,
or Variance parameter specifies N channels, the 1-D vector output
contains M/N samples from each channel. An error occurs in this case if M
is not an integer multiple of N.
Sample mode
The sample mode, Continuous or Discrete. This parameter is enabled
when the Inherit output port attributes check box is deselected.
5-363
Random Source
Sample time
The sample period, Ts, of the random output sequence. The output frame
period is M∗Ts. This parameter is enabled when the Inherit output port
attributes check box is deselected.
See “Creating Signals Using Signal Generator Blocks” on page 3-36 for related
information.
5-364
Real Cepstrum
Library Transforms
Description The Real Cepstrum block computes the real cepstrum of each channel in the
real-valued M-by-N input matrix, u. For both sample-based and frame-based
inputs, the block assumes that each input column is a frame containing M
consecutive samples from an independent channel. The block does not accept
complex-valued inputs.
The output is a real Mo-by-N matrix, where Mo is specified by the FFT length
parameter. Each output column contains the length-Mo real cepstrum of the
corresponding input column.
y = real(ifft(log(abs(fft(u,Mo))))) % Equivalent MATLAB code
When the Inherit FFT length from input port dimensions check box is
selected, the output frame size matches the input frame size (Mo=M). In this
case, a sample-based length-M row vector input is processed as a single channel
(i.e., as an M-by-1 column vector), and the output is a length-M row vector. A
1-D vector input is always processed as a single channel, and the output is a
1-D vector.
The output is always sample-based, and the output port rate is the same as the
input port rate.
Dialog Box
5-365
Real Cepstrum
5-366
Reciprocal Condition
Description The Reciprocal Condition block computes the reciprocal of the condition
number for a square input matrix A.
y = rcond(A) % Equivalent MATLAB code
or
1 1
y = --- = -------------------------------
κ –1
A 1 A 1
where κ is the condition number (κ ≥ 1), and y is the scalar sample-based output
(0 ≤ y < 1).
The matrix 1-norm, A 1 , is the maximum column-sum in the M-by-M
matrix A.
M
A 1 = max
1≤j≤M
∑ a ij
i=1
a 11 a 12 a 13
a 21 a 22 a 23 A 1 = max ( A 1, A 2, A 3 )
a 31 a 32 a 33
a 13 + a 23 + a 33 = A 3
a 12 + a 22 + a 32 = A 2
a 11 + a 21 + a 31 = A 1
5-367
Reciprocal Condition
Dialog Box
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-368
Repeat
Purpose 5Repeat
Resample an input at a higher rate by repeating values.
Description The Repeat block upsamples each channel of the Mi-by-N input to a rate
L times higher than the input sample rate by repeating each consecutive input
sample L times at the output. The integer L is specified by the Repetition
count parameter.
Sample-Based Operation
When the input is sample-based, the block treats each of the M∗N matrix
elements as an independent channel, and upsamples each channel over time.
The Frame-based mode parameter must be set to Maintain input frame size.
The output sample rate is L times higher than the input sample rate
(Tso = Tsi/L), and the input and output sizes are identical.
Frame-Based Operation
When the input is frame-based, the block treats each of the N input columns as
a frame containing Mi sequential time samples from an independent channel.
The block upsamples each channel independently by repeating each row of the
input matrix L times at the output. The Frame-based mode parameter
determines how the block adjusts the rate at the output to accommodate the
repeated rows. There are two available options:
• Maintain input frame size
The block generates the output at the faster (upsampled) rate by using a
proportionally shorter frame period at the output port than at the input port.
For L repetitions of the input, the output frame period is L times shorter
than the input frame period (Tfo = Tfi/L), but the input and output frame
sizes are equal.
5-369
Repeat
Latency
Zero Latency. The Repeat block has zero tasking latency for all single-rate
operations. The block is single-rate for the particular combinations of sampling
mode and parameter settings shown in the table below.
5-370
Repeat
The block also has zero latency for all multirate operations in Simulink’s
single-tasking mode.
Zero tasking latency means that the block repeats the first input (received
at t=0) for the first L output samples, the second input for the next L output
samples, and so on. The Initial condition parameter value is not used.
Nonzero Latency. The Repeat block has tasking latency only for multirate
operation in Simulink’s multitasking mode:
• In sample-based mode, the initial condition for each channel is repeated for
the first L output samples. The channel’s first input appears as output
sample L+1. The Initial condition value can be an Mi-by-N matrix
containing one value for each channel, or a scalar to be applied to all signal
channels.
• In frame-based mode, the first row of the initial condition matrix is repeated
for the first L output samples, the second row of the initial condition matrix
is repeated for the next L output samples, and so on. The first row of the first
input matrix appears in the output as sample MiL+1. The Initial condition
value can be an Mi-by-N matrix, or a scalar to be repeated across all elements
of the Mi-by-N matrix. See the example below for an illustration of this case.
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
5-371
Repeat
output frame period of 1 (0.25∗4). The first channel should contain the
positive ramp signal 1, 2, ..., 100, and the second channel should contain the
negative ramp signal -1, -2, ..., -100.
- Signal = [(1:100)' (-1:-1:-100)']
- Sample time = 0.25
- Samples per frame = 4
• Configure the Repeat block to upsample the two-channel input by increasing
the output frame rate by a factor of 2 relative to the input frame rate. Set an
initial condition matrix of
11 – 11
12 – 12
13 – 13
14 – 14
- Repetition count = 2
- Initial condition = [11 -11;12 -12;13 -13;14 -14]
- Frame-based mode = Maintain input frame size
• Configure the Probe blocks by deselecting the Probe width and Probe
complex signal check boxes (if desired).
This model is multirate because there are at least two distinct sample rates, as
shown by the two Probe blocks. To run this model in Simulink’s multitasking
mode, select Fixed-step and discrete from the Type controls in the Solver
panel of the Simulation Parameters dialog box, and select MultiTasking from
the Mode parameter. Also set the Stop time to 30.
Run the model and look at the output, yout. The first few samples of each
channel are shown below.
yout =
11 -11
11 -11
12 -12
12 -12
13 -13
13 -13
14 -14
5-372
Repeat
14 -14
1 -1
1 -1
2 -2
2 -2
3 -3
3 -3
4 -4
4 -4
5 -5
5 -5
Since we ran this frame-based multirate model in multitasking mode, the block
repeats each row of the initial condition matrix for L output samples, where
L is the Repetition count of 2. The first row of the first input matrix appears
in the output as sample 9 (i.e., sample MiL+1, where Mi is the input frame
size).
Dialog Box
Repetition count
The integer number of times, L, that the input value is repeated at the
output. This is the factor by which the output frame size or sample rate is
increased. Tunable.
Initial conditions
The value with which the block is initialized for cases of nonzero latency; a
scalar or matrix. Tunable.
5-373
Repeat
Frame-based mode
For frame-based operation, the method by which to implement the
repetition (upsampling): Maintain input frame size (i.e., increase the
frame rate), or Maintain input frame rate (i.e., increase the frame size).
The Frame-based mode parameter must be set to Maintain input frame
size for sample-base inputs. Tunable.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-374
RLS Adaptive Filter
Description The RLS Adaptive Filter block recursively computes the least squares estimate
(RLS) of the FIR filter coefficients.
The corresponding RLS filter is expressed in matrix form as
–1
λ P ( n – 1 )u ( n )
k ( n ) = -----------------------------------------------------------------------
–1 H
1 + λ u ( n )P ( n – 1 )u ( n )
H
y ( n ) = ŵ ( n – 1 )u ( n )
e(n) = d(n) – y(n)
ŵ ( n ) = ŵ ( n – 1 ) + k ( n )e∗ ( n )
–1 –1 H
P ( n ) = λ P ( n – 1 ) – λ k ( n )u ( n ) P ( n – 1 )
where λ-1 denotes the reciprocal of the exponential weighting factor. The
variables are as follows.
Variable Description
5-375
RLS Adaptive Filter
The block icon has port labels corresponding to the inputs and outputs of the
RLS algorithm. Note that inputs to the In and Err ports must be sample-based
scalars. The signal at the Out port is a scalar, while the signal at the Taps port
is a sample-based vector.
An optional Adapt input port is added when the Adapt input check box is
selected in the dialog box. When this port is enabled, the block continuously
adapts the filter coefficients while the Adapt input is nonzero. A zero-valued
input to the Adapt port causes the block to stop adapting, and to hold the filter
coefficients at their current values until the next nonzero Adapt input.
The implementation of the algorithm in the block is optimized by exploiting the
symmetry of the inverse correlation matrix P(n). This decreases the total
number of computations by a factor of two.
The FIR filter length parameter specifies the length of the filter that the RLS
algorithm estimates. The Memory weighting factor corresponds to λ in the
equations, and specifies how quickly the filter “forgets” past sample
information. Setting λ=1 specifies an infinite memory; typically, 0.95 ≤ λ ≤ 1.
The Initial value of filter taps specifies the initial value ŵ ( 0 ) as a vector, or
as a scalar to be repeated for all vector elements. The initial value of P(n) is
1
I ------
2
σ̂
2
where σ̂ is specified by the Initial input variance estimate parameter.
Example The rlsdemo demo illustrates a noise cancellation system built around the RLS
Adaptive Filter block.
5-376
RLS Adaptive Filter
Dialog Box
References Haykin, S. Adaptive Filter Theory. 3rd ed. Englewood Cliffs, NJ: Prentice Hall,
1996.
5-377
RLS Adaptive Filter
5-378
RMS
Purpose 5RMS
Compute the root-mean-square (RMS) value of an input or sequence of inputs.
Library Statistics
Description The RMS block computes the RMS value of each column in the input, or tracks
the RMS value of a sequence of inputs over a period of time. The Running RMS
parameter selects between basic operation and running operation.
Basic Operation
When the Running RMS check box is not selected, the block computes the
RMS value of each column in M-by-N input matrix u independently at each
sample time.
y = sqrt(sum(u.^2)/size(u,1)) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
The output at each sample time, y, is a 1-by-N vector containing the RMS value
for each column in u. The RMS value of the jth column is
∑ uij2
i=1
yj = ------------------
M
The frame status of the output is the same as that of the input.
Running Operation
When the Running RMS check box is selected, the block tracks the RMS value
of each channel in a time-sequence of M-by-N inputs. For sample-based inputs,
the output is a sample-based M-by-N matrix with each element yij containing
the RMS value of element uij over all inputs since the last reset. For
frame-based inputs, the output is a frame-based M-by-N matrix with each
element yij containing the RMS value of the jth column over all inputs since the
last reset, up to and including element uij of the current input.
If the Reset port parameter is set to Non-zero sample, the optional Rst port
is enabled and the block resets the running RMS when the scalar input at the
Rst port is nonzero. (The Rst port can be disabled by setting the Reset port
5-379
RMS
parameter to None.) For sample-based inputs, the running RMS for each
channel is initialized to the value in the corresponding channel of the current
input. For frame-based inputs, the running RMS for each channel is initialized
to the earliest value in each channel of the current input.
As in basic operation, length-M 1-D vector inputs and sample-based length-M
row vector inputs are both treated as M-by-1 column vectors.
Example The RMS block in the model below calculates the running RMS of a
frame-based 3-by-2 (two-channel) matrix input, u. The running RMS is reset at
t=2 by an impulse to the block’s Rst port.
• Running RMS =
• Reset port = Non-zero sample
• Signal = u
• Sample time = 1/3
• Samples per frame = 3
where
u = [6 1 3 -7 2 5 8 0 -1 -3 2 1;1 3 9 2 4 1 6 2 5 0 4 17]'
• Delay (samples) = 2
• Sample time = 1
• Samples per frame = 1
5-380
RMS
In Rst Output
61 6.00 1.00
First First output
13 t=0 0 4.30 2.24
input 39 3.92 5.51
–7 2 4.87 4.87
2 4 t=1 0 4.45 4.71
5 1 4.55 4.32
8 6 8.00 6.00
Simulation time
–3 0 4.30 4.03
2 4 t=3 0 3.95 4.02
1 17 3.63 7.85
Dialog Box
Running RMS
Enables running operation when selected.
Reset port
Enables the Rst input port when set to Non-zero sample, and disables the
Rst input port when set to None.
5-381
RMS
5-382
Sample and Hold
Description The Sample and Hold block acquires the input at the signal port whenever it
receives a trigger event at the trigger port (marked by ). The block then holds
the output at the acquired input value until the next triggering event occurs. If
the acquired input is frame-based, the output is frame-based; otherwise, the
output is sample-based.
The trigger input must be a sample-based scalar with sample rate equal to the
input frame rate at the signal port. The trigger event is specified by the
Trigger type pop-up menu, and can be one of the following:
• Rising edge triggers the block to acquire the signal input when the trigger
input rises from zero to a positive value.
• Falling edge triggers the block to acquire the signal input when the trigger
input falls from zero to a negative value.
• Either edge triggers the block to acquire the signal input when the trigger
input either rises from zero to a positive value or falls from zero to a negative
value.
The block’s output prior to the first trigger event is specified by the Initial
condition parameter. If the acquired input is an M-by-N matrix, the Initial
condition can be an M-by-N matrix, or a scalar to be repeated across all
elements of the matrix. If the input is a length-M 1-D vector, the Initial
condition can be a length-M row or column vector, or a scalar to be repeated
across all elements of the vector.
Dialog Box
Trigger type
The type of event that triggers the block to acquire the input signal.
5-383
Sample and Hold
Initial condition
The block’s output prior to the first trigger event.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-384
Short-Time FFT
Example The dspstfft demo provides an illustration of using the Short-Time FFT and
Matrix Viewer blocks to create a spectrogram. The dspsacomp demo compares
the ST-FFT with several other spectral estimation methods.
5-385
Short-Time FFT
Dialog Box
Window type
The type of window to apply. (See the Window Function block reference.)
Tunable.
Stopband attenuation in dB
The level (dB) of stopband attenuation, Rs, for the Chebyshev window.
Disabled for other Window type selections. Tunable.
Beta
The β parameter for the Kaiser window. Disabled for other Window type
selections. Increasing Beta widens the mainlobe and decreases the
amplitude of the window sidelobes in the window’s frequency magnitude
response. Tunable.
Window sampling
The window sampling, symmetric or periodic. Tunable.
Inherit FFT length from input dimensions
When selected, uses the input frame size as the number of data points, Nfft,
on which to perform the FFT.
FFT length
The number of data points, Nfft, on which to perform the FFT. If Nfft
exceeds the input frame size, the frame is zero-padded as needed. This
5-386
Short-Time FFT
5-387
Signal From Workspace
Description The Signal From Workspace block imports a signal from the MATLAB
workspace into the Simulink model. The Signal parameter specifies the name
of a MATLAB workspace variable containing the signal to import, or any valid
MATLAB expression defining a matrix or 3-D array.
When the Signal parameter specifies an M-by-N matrix (M≠1), each of the N
columns is treated as a distinct channel. The frame size is specified by the
Samples per frame parameter, Mo, and the output is an Mo-by-N matrix
containing Mo consecutive samples from each signal channel. The output
sample period is specified by the Sample time parameter, Ts, and the output
frame period is Mo∗Ts. For Mo=1, the output is sample-based; otherwise the
output is frame-based. For convenience, an imported row vector (M=1) is
treated as a single channel, so the output dimension is Mo-by-1.
When the Signal parameter specifies an M-by-N-by-P array, each of the
P pages (an M-by-N matrix) is output in sequence with period Ts. The Samples
per frame parameter must be set to 1, and the output is always sample-based.
5-388
Signal From Workspace
• If Cyclic Repetition is specified, the block repeats the signal from the
beginning after generating the last frame. If there are not enough samples
at the end of the signal to fill the final frame, the block zero-pads the final
frame as necessary to ensure that the output for each cycle is identical
(e.g., the ith frame of one cycle contains the same samples as the ith frame
of any other cycle).
Examples Example 1
In the first model below, the Signal From Workspace imports a two-channel
signal from the workspace matrix A. The Sample time is set to 1 and the
Samples per frame is set to 4, so the output is frame-based with a frame size
of 4 and a frame period of 4 seconds. The Form output after final data value
by parameter specifies Setting To Zero, so all outputs after the third frame (at
t=8) are zero.
Ch 1 Ch 2
1 1
2 1
ch1
ch2
ch1
ch2
ch1
ch2
ch1
ch2
3 0
4 0 0 0 9 1 5 1 1 1
A = 5 1 0 0 10 1 6 1 2 1
6 1 0 0 0 0 7 0 3 0
7 0 0 0 0 0 8 0 4 0
8 0
t=12 t=8 t=4 t=0
9 1 (Ts=1, Mo=4)
10 1
first matrix output
Example 2
In the second model below, the Signal From Workspace block imports a
sample-based matrix signal from the 3-D workspace array A. Again, the Form
output after final data value by parameter specifies Setting To Zero, so all
outputs after the third (at t=2) are zero.
5-389
Signal From Workspace
A ( :, :, 1 ) = 1 1
11
A ( :, :, 2 ) = 2 2 00 33 22 11
22 00 33 22 11
Dialog Box
Signal
The name of the MATLAB workspace variable from which to import the
signal, or a valid MATLAB expression specifying the signal.
Sample time
The sample period, Ts, of the output. The output frame period is Mo∗Ts.
Samples per frame
The number of samples, Mo, to buffer into each output frame. This value
must be 1 if a 3-D array is specified in the Signal parameter.
5-390
Signal From Workspace
Supported (MATLAB commands for casting values to certain data types are provided in
Data Types parentheses.)
Boolean (boolean)
8-, 16-, and 32-bit signed integer (int8, int16, int32)
8-, 16-, and 32-bit unsigned integer (uint8, uint16, uint32)
Single-precision floating point (single)
Double-precision floating point (double)
5-391
Signal To Workspace
Description The Signal To Workspace block writes data from your simulation into an array
in MATLAB’s main workspace. The output array can be 2-D or 3-D, depending
on whether the data is 1-D, sample-based, or frame-based. The Signal To
Workspace block and Simulink’s To Workspace block can output the same
arrays if their parameters are set appropriately.
For more information on the Signal To Workspace block, see the following
sections of this reference page:
Parameter Descriptions
The Variable name parameter is the name of the array in the MATLAB
workspace into which the block logs the simulation data. The array is created
in the workspace only after the simulation stops running. If you enter the name
of an existing workspace variable, the block overwrites the variable with an
array of simulation data after the simulation stops running.
When the block input is sample-based or 1-D, the Limit data points to last
parameter indicates how many samples of data to save. If the block input is
frame-based, this parameter indicates how many frames of data to save. If the
simulation generates more than the specified maximum number of samples or
frames, the simulation saves only the most recently generated data. To capture
all data, set Limit data points to last to inf.
The Decimation parameter is the decimation factor. It can be set to any
positive integer d, and allows you to write data at every dth sample. The
default decimation, 1, writes data at every time step.
5-392
Signal To Workspace
The Frames parameter sets the dimension of the output array to 2-D or 3-D for
frame-based inputs. The block ignores this parameter for 1-D and
sample-based inputs. The Frames parameter has the following two settings:
5-393
Signal To Workspace
Examples Example 1: Sample-Based Inputs. In the following Example 1 model, the input to
the Signal To Workspace block is a 2-by-2 sample-based matrix signal with a
sample time of 1 (generated by a Signal From Workspace block). The Signal To
Workspace block logs 11 samples by the end of the simulation, and creates a
2-by-2-by-11 array, A, in the MATLAB workspace.
5-394
Signal To Workspace
A ( :, :, 1 ) = 1 1
–1 0
A ( :, :, 2 ) = 2 1
11 1 ... 3 1 2 1 1 1 –2 0
– 11 0 –3 0 –2 0 –1 0
A ( :, :, 3 ) = 3 1
t=10 . . . t=2 t=1 t=0 –3 0
…
Last Sample First Sample
Sample 11 Sample 1 11 1
A ( :, :, 11 ) =
– 11 0
Example 2: Frame-Based Inputs. In the following Example 2 model, the input to the
Signal To Workspace block is a 2-by-4 frame-based matrix signal with a frame
period of 1 (generated by a Signal From Workspace block). The block logs 11
5-395
Signal To Workspace
frames (two samples per frame) by the end of the simulation. The frames are
concatenated to create a 22-by-4 matrix, A, in the MATLAB workspace.
The block settings for the following Example 2 model are similar to the
Example 1 block settings, except Frames is set to Concatenate frames (2-D
array) and the Signal From Workspace parameter, Signal, is set to input2,
where
input2 = [1 -1 1 0; 2 -2 1 0; 3 -3 1 0;...; 22 -22 1 0]
1 –1 1 0
2 –2 1 0
21 – 21 1 0 ... 3 –3 1 0 1 –1 1 0 3 –3 1 0
22 – 22 1 0 4 –4 1 0 2 –2 1 0 A = 4 –4 1 0
... M M M M
t=10 t=1 t=0
21 – 21 1 0
22 – 22 1 0
Last Frame First Frame
Frame 11 Frame 1
Concatenate Frames
In the 2-D output, there is no indication of where one frame ends and another
begins. By setting Frames to Log frames separately (3-D array) in the
Example 2 model, you can easily see each frame in the MATLAB workspace, as
illustrated in the following model. Each of the 11 frames is logged separately to
create a 2-by-4-by-11 array, A, in the MATLAB workspace.
MATLAB Workspace
2-by-4 frame-based input
A ( :, :, 1 ) = 1 – 1 1 0
2 –2 1 0
A ( :, :, 2 ) = 3 – 3 1 0
21 – 21 1 0 ... 3 –3 1 0 1 –1 1 0 4 –4 1 0
22 – 22 1 0 4 –4 1 0 2 –2 1 0
t=10 ... t=1 t=0 A ( :, :, 3 ) = 5 – 5 1 0
6 –6 1 0
…
5-396
Signal To Workspace
Dialog Box
Variable name
The name of the array that holds the input data. Tunable.
Limit data points to last
The maximum number of input samples (for sample-based inputs) or input
frames (for frame-based inputs) to be saved. Tunable.
Decimation
The decimation factor, d. Data is written at every dth sample. Tunable.
Frames
The output dimensionality for frame-based inputs. Frames can be set to
Concatenate frames (2-D array) or Log frames separately (3-D array).
This parameter is ignored when inputs are not frame-based. Tunable.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-397
Sine Wave
Description The Sine Wave block generates a multichannel real or complex sinusoidal
signal, with independent amplitude, frequency, and phase in each output
channel. A real sinusoidal signal is generated when the Output complexity
parameter is set to Real, and is defined by an expression of the type
y = A sin ( 2πft + φ )
where A is specified by the Amplitude parameter, f is specified in hertz by the
Frequency parameter, and φ is specified in radians by the Phase parameter.
A complex exponential signal is generated when the Output complexity
parameter is set to Complex, and is defined by an expression of the type
j ( 2πft + φ )
y = Ae = A { cos ( 2πft + φ ) + j sin ( 2πft + φ ) }
Each parameter value (A, f, φ) for real and complex sinusoids can be a scalar or
length-N vector, where N is the desired number of channels in the output. If at
least one parameter is specified as a length-N vector, scalar values specified for
the other parameters are scalar expanded to length N (i.e., they are applied to
every channel).
For example, specify
• Amplitude = [1 2 3]
• Frequency = [1000 500 250]
• Phase = [0 0 pi/2]
5-398
Sine Wave
sin ( 2000πt ) ( channel 1 )
y = 2 sin ( 1000πt ) ( channel 2 )
3 sin 500πt + --π- ( channel 3 )
2
In all discrete modes (see below), the block buffers the sampled sinusoids into
frames of size M, where M is specified by the Samples per frame parameter.
The output is a frame-based M-by-N matrix with frame period M∗Ts, where Ts
is specified by the Sample time parameter. For M=1, the output is
sample-based.
The Sample mode parameter specifies the block’s sampling property, which
can be Continuous or Discrete, described below:
• Continuous
In continuous mode, the sinusoid in the ith channel, yi, is computed as a
continuous function,
y i = A i sin ( 2πf i t + φ i ) ( real )
or
j ( 2πf i t + φ i )
yi = Ai e ( complex )
and the block’s output is continuous. In this mode, the block’s operation is the
same as that of a Simulink Sine Wave block with Sample time set to 0. This
mode offers high accuracy, but requires trigonometric function evaluations
at each simulation step, which is computationally expensive. Additionally,
because this method tracks absolute simulation time, a discontinuity will
eventually occur when the time value reaches its maximum limit.
Note also that many blocks in the DSP Blockset do not accept
continuous-time inputs.
5-399
Sine Wave
• Discrete
In discrete mode, the block’s discrete-time output can be generated by
directly evaluating the trigonometric function, by table look-up, or by a
differential method. The three options are explained below.
or
j ( 2πf i t + φ i )
yi = Ai e ( complex )
with a period of Ts, where Ts is specified by the Sample time parameter. This
mode of operation shares the same benefits and liabilities as the Continuous
sample mode described above.
If the period of every sinusoid in the output is evenly divisible by the sample
period, meaning that 1/(fiTs) = ki is an integer for every output yi, then the
sinusoidal output in the ith channel is a repeating sequence with a period of
ki samples. At each sample time, the block evaluates the sine function at the
appropriate time value within the first cycle of the sinusoid. By constraining
trigonometric evaluations to the first cycle of each sinusoid, the block avoids
the imprecision of computing the sine of very large numbers, and eliminates
the possibility of discontinuity during extended operations (when an absolute
time variable might overflow). This method therefore avoids the memory
demands of the table look-up method at the expense of many more
floating-point operations.
5-400
Sine Wave
Table Lookup. The table look-up method precomputes the unique samples of
every output sinusoid at the start of the simulation, and recalls the samples
from memory as needed. Because a table of finite length can only be
constructed if all output sequences repeat, the method requires that the period
of every sinusoid in the output be evenly divisible by the sample period. That
is, 1/(fiTs) = ki must be an integer value for every channel i = 1, 2, ..., N. When
the Optimize table for parameter is set to Speed, the table constructed for
each channel contains ki elements. When the Optimize table for parameter is
set to Memory, the table constructed for each channel contains ki/4 elements.
For long output sequences, the table look-up method requires far fewer
floating-point operations than any of the other methods, but may demand
considerably more memory, especially for high sample rates (long tables). This
is the recommended method for models that are intended to emulate or
generate code for DSP hardware, and that therefore need to be optimized for
execution speed.
The update equations for the sinusoid in the ith channel, yi, can therefore be
written in matrix form (for real output) as
5-401
Sine Wave
This mode offers reduced computational load, but is subject to drift over time
due to cumulative quantization error. Because the method is not contingent on
an absolute time value, there is no danger of discontinuity during extended
operations (when an absolute time variable might overflow).
Examples The dspsinecomp demo provides a comparison of all the available sine
generation methods.
Dialog Box
Amplitude
A length-N vector containing the amplitudes of the sine waves in each of N
output channels, or a scalar to be applied to all N channels. The vector
5-402
Sine Wave
length must be the same as that specified for the Frequency and Phase
parameters. Tunable; the amplitude values can be altered while a
simulation is running, but the vector length must remain the same.
Frequency
A length-N vector containing the frequencies, in rad/s, of the sine waves in
each of N output channels, or a scalar to be applied to all N channels. The
vector length must be the same as that specified for the Amplitude and
Phase parameters. Tunable; the frequency values can be altered while a
simulation is running, but the vector length must remain the same. Not
tunable in Simulink’s external mode when using the differential method.
Phase
A length-N vector containing the phase offsets, in radians, of the sine
waves in each of N output channels, or a scalar to be applied to all N
channels. The vector length must be the same as that specified for the
Amplitude and Frequency parameters. Tunable; the phase values can be
altered while a simulation is running, but the vector length must remain
the same. Not tunable in Simulink’s external mode when using the
differential method.
Sample mode
The block’s sampling behavior, Continuous or Discrete.
Output complexity
The type of waveform to generate: Real specifies a real sine wave,
Complex specifies a complex exponential. Tunable.
Computation method
The method by which discrete-time sinusoids are generated:
Trigonometric fcn, Table lookup, or Differential. This parameter is
disabled when Continuous is selected from the Sample mode parameter.
For details, see “Discrete Computational Methods” on page 5-400.
Optimize table for
Optimizes the table of sine values for Speed or Memory (this parameter is
enabled only when the Computation method parameter is set to Table
lookup). When optimized for speed, the table contains k elements, and
when optimized for memory, the table contains k/4 elements, where k is the
number of input samples in one full period of the sine wave.
5-403
Sine Wave
Sample time
The period with which the sine wave is sampled, Ts. The block’s output
frame period is M∗Ts, where M is specified by the Samples per frame
parameter. This parameter is disabled when Continuous is selected from
the Sample mode parameter.
Samples per frame
The number of consecutive samples from each sinusoid to buffer into the
output frame, M. This parameter is disabled when Continuous is selected
from the Sample mode parameter.
State when re-enabled
The behavior of the block when a disabled subsystem containing it is
reenabled. The block can either reset itself to its starting state (Restart at
time zero), or resume generating the sinusoid based on the current
simulation time (Catch up to simulation time). This parameter is
disabled when Continuous is selected from the Sample mode parameter.
See “Creating Signals Using Signal Generator Blocks” on page 3-36 for related
information.
5-404
Singular Value Decomposition
Description The Singular Value Decomposition block factors the M-by-N input matrix A
such that
A = U∗ diag ( S ) ⋅ V T
where U is an M-by-P matrix, V is an N-by-P matrix, S is a length-P vector, and
P is defined as min(M,N).
When M = N, U and V are both M-by-M unitary matrices. When M > N, V is an
N-by-N unitary matrix, and U is an M-by-N matrix whose columns are the first
N columns of a unitary matrix. When N > M, U is an M-by-M unitary matrix,
and V is an M-by-N matrix whose columns are the first N columns of a unitary
matrix. In all cases, S is a 1-D vector of positive singular values having length
P. The output is always sample-based.
Length-N row inputs are treated as length-N columns.
[U,S,V] = svd(A,0) % Equivalent MATLAB code for M > N
Note that the first (maximum) element of output S is equal to the 2-norm of the
matrix A.
You can enable the U and V output ports by selecting the Output the singular
vectors parameter.
Dialog Box
5-405
Singular Value Decomposition
References Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed.
Baltimore, MD: Johns Hopkins University Press, 1996.
5-406
Sort
Purpose 5Sort
Sort the elements in the input by value.
Library Statistics
Description The Sort block sorts the elements in each column of the input using a Quicksort
algorithm. The Mode parameter specifies the block’s mode of operation, and
can be set to Value, Index, or Value and Index.
Value Mode
When Mode is set to Value, the block sorts the elements in each column of the
M-by-N input matrix u in order of ascending or descending value, as specified
by the Sort order parameter.
val = sort(u) % Equivalent MATLAB code (ascending)
val = flipud(sort(u)) % Equivalent MATLAB code (descending)
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
The output at each sample time, val, is a M-by-N matrix containing the sorted
columns of u. Complex inputs are sorted by magnitude, and the output has the
same frame status as the input.
Index Mode
When Mode is set to Index, the block sorts the elements in each column of the
M-by-N input matrix u,
[val,idx] = sort(u) % Equivalent MATLAB code (ascending)
[val,idx] = flipud(sort(u))% Equivalent MATLAB code (descending)
and outputs the sample-based M-by-N index matrix, idx. The jth column of idx
is an index vector that permutes the jth column of u to the desired sorting
order:
val(:,j) = u(idx(:,j),j)
As in Value mode, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors.
5-407
Sort
Dialog Box
Mode
The block’s mode of operation: Output the sorted matrix (Value), the index
matrix (Index), or both (Value and Index).
Sort order
The order in which to sort the input values, Descending or Ascending.
Tunable, except in Simulink’s external mode.
5-408
Spectrum Scope
Description The Spectrum Scope block computes and displays the magnitude-squared FFT
of the input. The input be a 1-D vector or a 2-D matrix of any frame status.
When the input is a 1-by-N sample-based vector or M-by-N sample-based
matrix, you must select the Buffer input check box. Each of the N vector
elements (or M∗N matrix elements) is then treated as an independent channel,
and the block buffers and displays the data in each channel independently.
When the input is frame-based, you can leave the input as is, or rebuffer data
by checking the Buffer input check box and specifying the new buffer size. In
the latter case, you can also specify an optional Buffer overlap.
Buffering 1-D vector inputs is recommended. In this case, the inputs are
buffered into frames (the length of which are specified in the Buffer size
parameter), where each 1-D input vector becomes a row in the buffered
outcome. If a 1-D vector input is left unbuffered, you will get a warning because
the block is computing the FFT of a scalar; though the scope window appears,
it is unlikely you will be able to see the plot, and a warning is also displayed on
the scope itself. It is not recommended that you leave 1-D inputs unbuffered.
The number of input samples that the block buffers before computing and
displaying the magnitude FFT is specified by the Buffer size parameter, Mo.
The Buffer overlap parameter, L, specifies the number of samples from the
previous buffer to include in the current buffer. The number of new input
samples the block acquires before computing and displaying the magnitude
FFT is the difference between the Buffer size and Buffer overlap, Mo-L.
The display update period is (Mo-L)∗Ts, where Ts is the input sample period,
and is equal to the input sample period when the Buffer overlap is Mo-1. For
negative Buffer overlap values, the block simply discards the appropriate
number of input samples after the buffer fills, and updates the scope display at
a slower rate than the zero-overlap case.
When the FFT length check box is deselected and the input is buffered, the
block uses the buffer size as the FFT size. If the check box is deselected and the
input is not buffered, the block uses the input size as the FFT size. When the
check box is selected, the FFT length parameter, Nfft, is enabled, and specifies
5-409
Spectrum Scope
the number of samples on which to perform the FFT. The block zero pads or
truncates every channel’s buffer to Nfft before computing the FFT.
The number of spectra to average is set by the Number of spectral averages
parameter. Setting this parameter to 1 effectively disables averaging; See
Short-Time FFT for more information.
In order to correctly scale the frequency axis (i.e., to determine the frequencies
against which the transformed input data should be plotted), the block needs
to know the actual sample period of the time-domain input. This is specified by
the Sample time of original time series parameter, Ts.
When the Inherit sample time from input check box is selected, the block
computes the frequency data from the sample period of the input to the block.
This is valid when the following conditions hold:
• The input to the block is the original signal, with no samples added or deleted
(by insertion of zeros, for example).
• The sample period of the time-domain signal in the simulation is equal to the
period with which the physical signal was originally sampled.
One example when these conditions do not hold, is such as when the input to
the block is not the original signal, but a zero-padded or otherwise rate-altered
version. In such cases, you should specify the appropriate value for the Sample
time of original time-series parameter.
The Frequency units parameter specifies whether the frequency axis values
should be in units of Hertz or rad/s, and the Frequency range parameter
specifies the range of frequencies over which the magnitudes in the input
should be plotted. The available options are [0..Fs/2], [-Fs/2..Fs/2], and [0..Fs],
where Fs is the time-domain signal’s actual sample frequency. If the
Frequency units parameter specifies Hertz, the spacing between frequency
points is 1/(NfftTs). For Frequency units of rad/sec, the spacing between
frequency points is 2π/(NfftTs).
Note that all of the FFT-based blocks in the DSP Blockset, including those in
the Power Spectrum Estimation library, compute the FFT at frequencies in the
range [0,Fs). The Frequency range parameter controls only the displayed
range of the signal.
5-410
Spectrum Scope
For information about the scope window, as well as the Display properties,
Axis properties, and Line properties panels in the dialog box, see the
reference page for the Vector Scope block.
Dialog Box
Scope properties
Select to expose Scope properties panel. Tunable.
Buffer input
Select to expose Buffer input panel. Tunable.
Buffer size
The number of signal samples to include in each buffer. Tunable.
Buffer overlap
The number of samples by which consecutive buffers overlap. Tunable.
Specify FFT length
Select to expose Specify FFT length panel. Tunable.
5-411
Spectrum Scope
FFT length
The number of samples on which to perform the FFT. If the FFT length
differs from the buffer size, the data is zero-padded or truncated as needed.
Tunable.
Number of spectral averages
The the number of spectra to average. Setting this parameter to 1 effectively
disables averaging. See Short-Time FFT for more information. Tunable.
Display properties
Select to expose the Display properties panel. See Vector Scope for more
information. Tunable.
Axis properties
Select to expose the Axis properties panel. See Vector Scope for more
information. Tunable.
Line properties
Select to expose the Line properties panel. See Vector Scope for more
information. Tunable.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-412
Stack
Purpose 5Stack
Store inputs into a LIFO register.
Description The Stack block stores a sequence of input samples in a LIFO (last in, first out)
register. The register capacity is set by the Stack depth parameter, and inputs
can be scalars, vectors, or matrices.
The block pushes the input at the In port onto the top of the stack when a
trigger event is received at the Push port. When a trigger event is received at
the Pop port, the block pops the top element off the stack and holds the Out port
at that value. The last input to be pushed onto the stack is always the first to
be popped off.
Pushing the stack Popping the stack
1100 1100
last in first out
A trigger event at the optional Clr port (enabled by the Clear input check box)
empties the stack contents. If Clear output port on reset is selected, then a
trigger event at the Clr port empties the stack and sets the value at the Out
port to zero. This setting also applies when a disabled subsystem containing
the Stack block is re-enabled; the Out port value is only reset to zero in this case
if Clear output port on reset is selected.
5-413
Stack
When two or more of the control input ports are triggered at the same time
step, the operations are executed in the following order:
1 Clr
2 Push
3 Pop
The triggering event for the Push, Pop, and Clr ports is specified by the Trigger
type pop-up menu, and can be one of the following:
• Rising edge triggers execution of the block when the trigger input rises from
a negative value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers execution of the block when the trigger input falls from
a positive value to zero or a negative value, or from zero to a negative value.
• Either edge triggers execution of the block when either a rising or falling
edge (as described above) occurs.
The Push full stack parameter specifies the block’s behavior when a trigger is
received at the Push port but the register is full. The Pop empty stack
parameter specifies the block’s behavior when a trigger is received at the Pop
port but the register is empty. The following options are available for both
cases:
The Push full stack parameter additionally offers the Dynamic reallocation
option, which dynamically resizes the register to accept as many additional
inputs as memory permits. To find out how many elements are on the stack at
a given time, enable the Num output port by selecting the Output number of
stack entries option.
Examples Example 1
The table below illustrates the Stack block’s operation for a Stack depth of 4,
Trigger type of Either edge, and Clear output port on reset enabled.
Because the block triggers on both rising and falling edges in this example,
each transition from 1 to 0 or 0 to 1 in the Push, Pop, and Clr columns below
5-414
Stack
1 0 0 0 top bottom 0 1 0 0
2 1 0 0 top 2 bottom 0 0 0 1
3 0 0 0 top 3 2 bottom 0 0 0 2
4 1 0 0 top 4 3 2 bottom 0 0 0 3
5 0 0 0 top 5 4 3 2 bottom 0 0 1 4
6 0 1 0 top 4 3 2 bottom 5 0 0 3
7 0 0 0 top 3 2 bottom 4 0 0 2
8 0 1 0 top 2 bottom 3 0 0 1
9 0 0 0 top bottom 2 1 0 0
10 1 0 0 top 10 bottom 2 0 0 1
11 0 0 0 top 11 10 bottom 2 0 0 2
12 1 0 1 top 12 bottom 0 0 0 1
Note that at the last step shown, the Push and Clr ports are triggered
simultaneously. The Clr trigger takes precedence, and the stack is first cleared
and then pushed.
Example 2
The dspqdemo demo provides an example of the related Queue block.
5-415
Stack
Dialog Box
Stack depth
The number of entries that the LIFO register can hold.
Trigger type
The type of event that triggers the block’s execution. Tunable.
Push full stack
Response to a trigger received at the Push port when the register is full.
Pop empty stack
Response to a trigger received at the Pop port when the register is empty.
Tunable.
Empty stack output
Enable the Empty output port, which is high (1) when the stack is empty,
and low (0) otherwise.
Full stack output
Enable the Full output port, which is high (1) when the stack is full, and
low (0) otherwise. The Full port remains low when Dynamic reallocation
is selected from the Push full stack parameter.
Output number of stack entries
Enable the Num output port, which tracks the number of entries currently
on the stack.
5-416
Stack
Clear input
Enable the Clr input port, which empties the stack when the trigger
specified by the Trigger type is received.
Clear output port on reset
Reset the Out port to zero (in addition to clearing the stack) when a trigger
is received at the Clr input port. Tunable.
5-417
Standard Deviation
Library Statistics
Description The Standard Deviation block computes the standard deviation of each column
in the input, or tracks the standard deviation of a sequence of inputs over a
period of time. The Running standard deviation parameter selects between
basic operation and running operation.
Basic Operation
When the Running standard deviation check box is not selected, the block
computes the standard deviation of each column in M-by-N input matrix u
independently at each sample time.
y = std(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors. (A scalar input
generates a zero-valued output.)
The output at each sample time, y, is a 1-by-N vector containing the standard
deviation for each column in u. For purely real or purely imaginary inputs, the
standard deviation of the jth column is the square root of the variance
∑
2
u ij – µ j
yj = σj = i=1
----------------------------------- 1≤j≤N
M–1
where µj is the mean of jth column. For complex inputs, the output is the total
standard deviation for each column in u, which is the square root of the total
variance for that column.
2 2
σj = σ j, Re + σ j, Im
Note that the total standard deviation is not equal to the sum of the real and
imaginary standard deviations. The frame status of the output is the same as
that of the input.
5-418
Standard Deviation
Running Operation
When the Running standard deviation check box is selected, the block tracks
the standard deviation of each channel in a time-sequence of M-by-N inputs.
For sample-based inputs, the output is a sample-based M-by-N matrix with
each element yij containing the standard deviation of element uij over all inputs
since the last reset. For frame-based inputs, the output is a frame-based
M-by-N matrix with each element yij containing the standard deviation of the
jth column over all inputs since the last reset, up to and including element uij
of the current input.
If the Reset port parameter is set to Non-zero sample, the optional Rst port
is enabled and the block resets the running standard deviation when the scalar
input at the Rst port is nonzero. (The Rst port can be disabled by setting the
Reset port parameter to None.)
Example The Standard Deviation block in the model below calculates the running
standard deviation of a frame-based 3-by-2 (two-channel) matrix input, u. The
running standard deviation is reset at t=2 by an impulse to the block’s Rst port.
• Signal = u
• Sample time = 1/3
• Samples per frame = 3
5-419
Standard Deviation
where
u = [6 1 3 -7 2 5 8 0 -1 -3 2 1;1 3 9 2 4 1 6 2 5 0 4 17]'
• Delay (samples) = 2
• Sample time = 1
• Samples per frame = 1
61 0 0
First First output
13 t=0 0 3.54 1.41
input 39 2.52 4.16
–7 2 5.56 3.59
2 4 t=1 0 4.85 3.11
5 1 4.63 3.01
8 6 0 0
Simulation time
–3 0 4.83 2.75
2 4 t=3 0 4.21 2.41
1 17 3.76 5.96
5-420
Standard Deviation
Dialog Box
5-421
Submatrix
Purpose 5Submatrix
Select a subset of elements (submatrix) from a matrix input.
Description The Submatrix block extracts a contiguous submatrix from the M-by-N input
matrix u. A length-M 1-D vector input is treated as an M-by-1 matrix. The Row
span parameter provides three options for specifying the range of rows in u to
be retained in submatrix output y:
• All rows
Specifies that y contains all M rows of u.
• One row
Specifies that y contains only one row from u. The Starting row parameter
(described below) is enabled to allow selection of the desired row.
• Range of rows
Specifies that y contains one or more rows from u. The Row and Ending row
parameters (described below) are enabled to allow selection of the desired
range of rows.
The Column span parameter contains a corresponding set of three options for
specifying the range of columns in u to be retained in submatrix y: All
columns, One column, or Range of columns. The One column option enables
the Column parameter, and Range of columns options enable the Starting
column and Ending column parameters.
5-422
Submatrix
The Row, Column, Starting row or Starting column can be specified in six
ways:
• First
For rows, this specifies that the first row of u should be used as the first row
of y. If all columns are to be included, this is equivalent to y(1,:) = u(1,:).
For columns, this specifies that the first column of u should be used as the
first column of y. If all rows are to be included, this is equivalent to
y(:,1) = u(:,1).
• Index
For rows, this specifies that the row of u, firstrow, forward-indexed by the
Row index parameter or the Starting row index parameter, should be used
as the first row of y. If all columns are to be included, this is equivalent to
y(1,:) = u(firstrow,:).
For columns, this specifies that the column of u, forward-indexed by the
Column index parameter or the Starting column index parameter,
firstcol, should be used as the first column of y. If all rows are to be
included, this is equivalent to y(:,1) = u(:,firstcol).
• Offset from last
For rows, this specifies that the row of u offset from row M by the Row offset
or Starting row offset parameter, firstrow, should be used as the first row
of y. If all columns are to be included, this is equivalent to
y(1,:) = u(M-firstrow,:).
For columns, this specifies that the column of u offset from column N by the
Column offset or Starting column offset parameter, firstcol, should be
used as the first column of y. If all rows are to be included, this is equivalent
to y(:,1) = u(:,N-firstcol).
• Last
For rows, this specifies that the last row of u should be used as the only row
of y. If all columns are to be included, this is equivalent to y = u(M,:).
For columns, this specifies that the last column of u should be used as the
only column of y. If all rows are to be included, this is equivalent to
y = u(:,N).
• Offset from middle
For rows, this specifies that the row of u offset from row M/2 by the Starting
row offset parameter, firstrow, should be used as the first row of y. If all
5-423
Submatrix
The Ending row or Ending column can similarly be specified in five ways:
• Index
For rows, this specifies that the row of u forward-indexed by the Ending row
index parameter, lastrow, should be used as the last row of y. If all columns
are to be included, this is equivalent to y(end,:) = u(lastrow,:).
For columns, this specifies that the column of u forward-indexed by the
Ending column index parameter, lastcol, should be used as the last
column of y. If all rows are to be included, this is equivalent to
y(:,end) = u(:,lastcol).
• Offset from last
For rows, this specifies that the row of u offset from row M by the Ending
row offset parameter, lastrow, should be used as the last row of y. If all
columns are to be included, this is equivalent to
y(end,:) = u(M-lastrow,:).
For columns, this specifies that the column of u offset from column N by the
Ending column offset parameter, lastcol, should be used as the last
column of y. If all rows are to be included, this is equivalent to
y(:,end) = u(:,N-lastcol).
5-424
Submatrix
• Last
For rows, this specifies that the last row of u should be used as the last row
of y. If all columns are to be included, this is equivalent to
y(end,:) = u(M,:).
For columns, this specifies that the last column of u should be used as the
last column of y. If all rows are to be included, this is equivalent to
y(:,end) = u(:,N).
• Offset from middle
For rows, this specifies that the row of u offset from row M/2 by the Ending
row offset parameter, lastrow, should be used as the last row of y. If all
columns are to be included, this is equivalent to
y(end,:) = u(M/2-lastrow,:).
For columns, this specifies that the column of u offset from column N/2 by the
Ending column offset parameter, lastcol, should be used as the last
column of y. If all rows are to be included, this is equivalent to
y(:,end) = u(:,N/2-lastcol).
• Middle
For rows, this specifies that the middle row of u should be used as the last
row of y. If all columns are to be included, this is equivalent to
y(end,:) = u(M/2,:).
For columns, this specifies that the middle column of u should be used as the
last column of y. If all rows are to be included, this is equivalent to
y(:,end) = u(:,N/2).
Example To extract the lower-right 3-by-2 submatrix from a 5-by-7 input matrix, enter
the following set of parameters:
5-425
Submatrix
The figure below shows the operation for a 5-by-7 matrix with random integer
elements, randint(5,7,10).
8 6 5 3 0 1 6
2 4 7 8 3 6 3 2 7
5 0 8 8 7 2 7 4 7
4 7 6 3 0 4 7 1 5
8 4 1 8 1 1 5
There are often several possible parameter combinations that select the same
submatrix from the input. For example, instead of specifying Last for Ending
column, you could select the same submatrix by specifying:
Dialog Box
The parameters displayed in the dialog box vary for different menu
combinations. Only some of the parameters listed below are visible in the
dialog box at any one time.
5-426
Submatrix
Row span
The range of input rows to be retained in the output. Options are All rows,
One row, or Range of rows.
Row/Starting row
The input row to be used as the first row of the output. Row is enabled
when One row is selected from Row span, and Starting row when Range
of rows is selected from Row span.
Ending row
The input row to be used as the last row of the output. This parameter is
enabled when Range of rows is selected from Row span and any option
but Last is selected from Starting row.
Ending row index
The index of the input row to be used as the last row of the output. This
parameter is enabled when Index is selected from Ending row.
Ending row offset
The offset of the input row to be used as the last row of the output. This
parameter is enabled when Offset from middle or Offset from last is
selected from Ending row.
Column span
The range of input columns to be retained in the output. Options are All
columns, One column, or Range of columns.
5-427
Submatrix
Column/Starting column
The input column to be used as the first column of the output. Column is
enabled when One column is selected from Column span, and Starting
column is enabled when Range of columns is selected from Column span.
Ending column
The input column to be used as the last column of the output. This
parameter is enabled when Range of columns is selected from Column
span and any option but Last is selected from Starting column.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-428
Submatrix
5-429
SVD Solver
Library Math Functions / Matrices and Linear Algebra / Linear System Solvers
Description The SVD Solver block solves the linear system AX=B, which can be
overdetermined, underdetermined, or exactly determined. The system is solved
by applying SVD factorization to the M-by-N matrix, A, at the A port. The input
to the B port is the right hand-side M-by-L matrix, B. A length-M 1-D vector
input at either port is treated as an M-by-1 matrix.
The output at the x port is the N-by-L matrix, X. X is always sample based, and
is chosen to minimize the sum of the squares of the elements of B-AX. When B
is a vector, this solution minimizes the vector 2-norm of the residual (B-AX is
the residual). When B is a matrix, this solution minimizes the matrix
Frobenius norm of the residual. In this case, the columns of X are the solutions
to the L corresponding systems AXk=Bk, where Bk is the kth column of B, and
Xk is the kth column of X.
X is known as the minimum-norm-residual solution to AX=B. The
minimum-norm-residual solution is unique for overdetermined and exactly
determined linear systems, but it is not unique for underdetermined linear
systems. Thus when the SVD Solver is applied to an underdetermined system,
the output X is chosen such that the number of nonzero entries in X is
minimized.
Dialog Box
5-430
SVD Solver
5-431
Time Scope
5Time Scope
The Time Scope block is the same as the Scope block in Simulink. To learn how
to use the Time Scope block, see the Scope block reference page in the Simulink
documentation.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-432
Time-Varying Direct-Form II Transpose Filter
x( k) ...
b( m) b(3) b(2) b(1)
Σ z-1
... Σ z-1 Σ z-1 Σ y(k)
zn-1(k) z2( k) z 1 ( k)
-a(n) -a(3) -a(2)
...
This is a canonical form that has the minimum number of delay elements. The
filter order is max(m,n)-1.
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and an M-by-N frame-based matrix input is treated as N
independent channels. In both cases, the block filters each channel
independently over time, and the output has the same size and frame status as
the input.
The block’s two lower inputs (Num and Den) specify the filter’s transfer function,
–1 –( m – 1 )
B(z) b1 + b2 z + … + bm + 1 z
H ( z ) = ------------ = -----------------------------------------------------------------------------------
A(z) –1
a1 + a2 z + … + an + 1 z
–( n – 1 )
Filter Type
The Filter type parameter specifies whether the filter is an all-zero (FIR or
MA) filter, all-pole (AR) filter, or pole-zero (IIR or ARMA) filter:
5-433
Time-Varying Direct-Form II Transpose Filter
• Pole-zero
The block accepts inputs for both the numerator (Num) and denominator (Den)
vectors.
Input Num is a vector of numerator coefficients,
[b(1) b(2) ... b(m)]
• All-zero
The block accepts only the numerator vector (Num). The denominator of the
all-zero filter is 1.
• All-pole
The block accepts only the denominator vector (Den). The numerator of the
all-pole filter is 1.
For any of these designs, the coefficient vector inputs can change over time to
alter the filter’s response characteristics during the simulation.
Initial Conditions
In its default form, the filter initializes the internal filter states to zero, which
is equivalent to assuming past inputs and outputs are zero. The block also
accepts optional nonzero initial conditions for the filter delays. Note that the
number of filter states (delay elements) per input channel is
max(m,n)-1
• Empty matrix
The empty matrix, [], causes a zero (0) initial condition to be applied to all
delay elements in each filter channel.
• Scalar
The scalar value is copied to all delay elements in each filter channel. Note
that a value of zero is equivalent to setting the Initial conditions parameter
to the empty matrix, [].
5-434
Time-Varying Direct-Form II Transpose Filter
• Vector
The vector has a length equal to the number of delay elements in each filter
channel, max(m,n)-1, and specifies a unique initial condition for each delay
element in the filter channel. This vector of initial conditions is applied to
each filter channel.
• Matrix
The matrix specifies a unique initial condition for each delay element, and
can specify different initial conditions for each filter channel. The matrix
must have the same number of rows as the number of delay elements in the
filter, max(m,n)-1, and must have one column per filter channel.
5-435
Time-Varying Direct-Form II Transpose Filter
Dialog Box
Filter type
The type of filter to apply: Pole-Zero (IIR), All-Zero (FIR), or All-Pole
(AR). The Num and Den input ports are enabled or disabled as appropriate.
Initial conditions
The filter’s initial conditions, a scalar, vector, or matrix.
Support non-normalized filters
Normalizes the filter by a1 when selected.
Filter update rate
The frequency with which the block updates the filter coefficients; once per
sample, or once per frame.
5-436
Time-Varying Direct-Form II Transpose Filter
See “Designing Filters with Various Filter Structures” on page 4-6 for related
information.
5-437
Time-Varying Lattice Filter
Description The Time-Varying Lattice Filter block applies a moving average (MA) or
autoregressive (AR) lattice filter to the top input (In). The filter reflection
coefficients are specified by the vector input to the MA or AR port, and can vary
with time.
An M-by-N sample-based matrix input to the In port is treated as M∗N
independent channels, and an M-by-N frame-based matrix input is treated as
N independent channels. In both cases, the block filters each channel
independently over time, and the output has the same size and frame status as
the input.
Filter Type
The Filter type parameter specifies whether the filter is an all-zero
(FIR or MA) filter or all-pole (AR) filter.
• All-zero
The block constructs an nth order MA filter using the n reflection coefficients
contained in the vector input to the MA port.
k = [k(1) k(2) ... k(n)]
• All-pole
The block constructs an nth order AR filter using the n reflection coefficients
contained in the vector input to the AR port.
k = [k(1) k(2) ... k(n)]
For both designs, the coefficient vector inputs can change over time to alter the
filter’s response characteristics during the simulation.
Initial Conditions
In its default form, the filter initializes the internal filter states to zero, which
is equivalent to assuming past inputs and outputs are zero. The block also
accepts optional nonzero initial conditions for the filter delays. Note that the
number of filter states (delay elements) per input channel is
length(k)
5-438
Time-Varying Lattice Filter
• Empty matrix
The empty matrix, [], causes a zero (0) initial condition to be applied to all
delay elements in each filter channel.
• Scalar
The scalar value is copied to all delay elements in each filter channel. Note
that a value of zero is equivalent to setting the Initial conditions parameter
to the empty matrix.
• Vector
The vector has a length equal to the number of delay elements in each filter
channel, length(k), and specifies a unique initial condition for each delay
element in the filter channel. This vector of initial conditions is applied to
each filter channel.
• Matrix
The matrix specifies a unique initial condition for each delay element, and
can specify different initial conditions for each filter channel. The matrix
must have the same number of rows as the number of delay elements in the
filter, length(k), and must have one column per filter channel.
5-439
Time-Varying Lattice Filter
Dialog Box
Filter type
The type of filter to apply: MA or AR. The MA or AR input port is enabled or
disabled appropriately.
Initial conditions
The filter’s initial conditions.
Filter update rate
The frequency with which the block updates the filter coefficients; once per
sample, or once per frame.
5-440
Time-Varying Lattice Filter
See “Designing Filters with Various Filter Structures” on page 4-6 for related
information.
5-441
Toeplitz
Purpose 5Toeplitz
Generate a matrix with Toeplitz symmetry.
Description The Toeplitz block generates a Toeplitz matrix from inputs defining the first
column and first row. The top input (Col) is a vector containing the values to
be placed in the first column of the matrix, and the bottom input (Row) is a
vector containing the values to be placed in the first row of the matrix.
y = toeplitz(Col,Row) % Equivalent MATLAB code
1 7 3 3 2 1 3
2 1 7 3 3 2 1
3 2 1 7 3 3 2
4 3 2 1 7 3 3
5 4 3 2 1 7 3
The output has dimension [length(u) length(u)]. For example, the Toeplitz
matrix generated from the input vector [1 2 3 4] is
5-442
Toeplitz
1 2 3 4
2 1 2 3
3 2 1 2
4 3 2 1
Dialog Box
Symmetric
When selected, enables the single-input configuration for symmetric
Toeplitz matrix output.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-443
To Wave Device
Description The To Wave Device block sends audio data to a standard Windows audio
device in real-time. It is compatible with most popular Windows hardware,
including Sound Blaster cards. (Models that contain both this block and the
From Wave Device block require a duplex-capable sound card.) The data is sent
to the hardware in uncompressed PCM (pulse code modulation) format, and
should typically be sampled at one of the standard Windows audio device rates:
8000, 11025, 22050, or 44100 Hz. Some hardware may support other rates in
addition to these.
The Use default audio device parameter allows the block to detect and use the
system’s default audio hardware. This option should be selected on systems
that have a single sound device installed, or when the default sound device on
a multiple-device system is the desired target. In cases when the default sound
device is not the desired output device, deselect Use default audio device, and
enter the desired device identification number in the Audio device ID
parameter. The device ID is an integer value that the block associates with the
sound device. A 3-device system, for example, has device ID numbers of 1, 2,
and 3.
The input to the block, u, can contain audio data from a mono or stereo signal.
A mono signal is represented as either a sample-based scalar or frame-based
length-M vector, while a stereo signal is represented as a sample-based
length-2 vector or frame-based M-by-2 matrix. If the input data type is double,
single, or int16, the block conveys the signal samples to the audio device
using 16 bits. If the input data type is uint8, the block conveys the signal
samples to the audio device using 8 bits.
sound(u,Fs,bits) % Equivalent MATLAB code
Note that the block does not support uint16 or int8 data types. The 16-bit
sample width requires more memory but in general yields better fidelity. The
amplitude of the input should be in the range ±1. Values outside this range are
clipped to the nearest allowable value.
5-444
To Wave Device
Buffering
Because the audio device generates real-time audio output, Simulink must
maintain a continuous flow of data to the device throughout the simulation.
Delays in passing data to the audio hardware can result in hardware errors or
distortion of the output. This means that the To Wave Device block must in
principle supply data to the audio hardware as quickly as the hardware reads
the data. However, the To Wave Device block often cannot match the
throughput rate of the audio hardware, especially when the simulation is
running from within Simulink rather than as generated code. (Simulink
execution speed routinely varies during the simulation as the host operating
system services other processes.) The block must therefore rely on a buffering
strategy to ensure that signal data is accessible to the hardware on demand.
At the start of the simulation, the To Wave Device block writes Td seconds
worth of signal data to the device (hardware) buffer, where Td is specified by
the Initial output delay parameter. When this initial data is loaded into the
buffer, the audio device begins processing the buffered data, and continues at
a constant rate until the buffer empties. The size of the buffer, Tb, is specified
by the Queue duration parameter. As the audio device reads data from the
front of the buffer, the To Wave Device block continues appending inputs to the
back of the buffer at the rate they are received.
The following figure shows an audio signal with 8 samples per frame. The
buffer of the sound board has a five-frame capacity, not fully used at the instant
shown. (If the signal sample rate was 8kHz, for instance, this small buffer
could hold approximately 0.005 seconds of data.)
Simulink execution rate varies Hardware execution rate is constant
board
Simulation delay
Hardware buffer with no delays
5-frame capacity
5-445
To Wave Device
the hardware throughput rate is higher than the simulation throughput rate,
and the buffer tends to empty over the duration of the simulation.
Under normal operation, an empty buffer indicates that the simulation is
finished, and the entire length of the audio signal has been processed.
However, if the buffer size is too small in relation to the simulation throughput
rate, the buffer may also empty before the entire length of signal is processed.
This usually results in a device error or undesired device output.
When the device fails to process the entire signal length because the buffer
prematurely empties, you can choose to either increase the buffer size or the
simulation throughput rate.
• Increase the buffer size. The Queue duration parameter specifies the length
of signal, Tb (in real-time seconds), to buffer to the audio device during the
simulation. The number of frames buffered is approximately
Tb Fs
-------------
Mo
where Fs is the sample rate of the signal and Mo is the number of samples
per frame. The optimal buffer size for a given signal depends on the signal
length, the frame size, and the speed of the simulation. The maximum
number of frames that can be buffered is 1024.
• Increase the simulation throughput rate. Two useful methods for improving
simulation throughput rates are increasing the signal frame size and
compiling the simulation into native code.
- Increase frame sizes (and convert sample-based signals to frame-based
signals) throughout the model to reduce the amount of block-to-block
communication overhead. This can drastically increase throughput rates
in many cases. However, larger frame sizes generally result in greater
model latency due to initial buffering operations. (Note that increasing the
audio signal frame size does not affect the number of samples buffered to
the hardware since the Queue duration is specified in seconds.)
- Generate executable code with Real-Time Workshop. Native code runs
much faster than Simulink, and should provide rates adequate for
real-time audio processing.
Audio problems at startup can often be corrected by entering a larger value for
the Initial output delay parameter, which allows a greater portion of the
5-446
To Wave Device
signal to be preloaded into the hardware buffer. A value of 0 for the Initial
output delay parameter specifies the smallest possible initial delay, which is
one frame.
More general ways to improve throughput rates include simplifying the model,
and running the simulation on a faster PC processor. See the Simulink
documentation and “Delay and Latency” on page 3-85 for other ideas on
improving simulation performance.
Dialog Box
5-447
To Wave Device
a value of 2 selects the second audio card, and so on. Select Use default
audio device if the system has only a single audio card installed.
See “Exporting and Playing WAV Files” on page 3-79 for related information.
5-448
To Wave File
Description The To Wave File block writes audio data to a Microsoft Wave (.wav) file in the
uncompressed PCM (pulse code modulation) format. For compatibility reasons,
the sample rate of the discrete-time input signal should typically be one of the
standard Windows audio device rates (8000, 11025, 22050, or 44100 Hz),
although the block supports arbitrary rates.
The input to the block, u, can contain audio data from a mono or stereo signal.
A mono signal is represented as either a sample-based scalar or frame-based
length-M vector, while a stereo signal is represented as a sample-based
length-2 vector or frame-based M-by-2 matrix. The amplitude of the input
should be in the range ±1. Values outside this range are clipped to the nearest
allowable value.
wavwrite(u,Fs,bits,'filename') % Equivalent MATLAB code
The Sample Width (bits) parameter specifies the number of bits used to
represent the signal samples in the file. Two settings are available:
The 16-bit sample width setting requires more memory but yields better
fidelity for double-precision inputs.
The File name parameter can specify an absolute or relative path to the file.
You do not need to specify the.wav extension. To reduce the required number
of file accesses, the block writes L consecutive samples to the file during each
access, where L is specified by the Minimum number of samples for each
write to file parameter (L ≥ M). For L < M, the block instead writes M
consecutive samples during each access. Larger values of L result in fewer file
accesses, which reduces run-time overhead.
5-449
To Wave File
Dialog Box
File name
The path and name of the file to write. Paths can be relative or absolute.
Tunable.
Sample width (bits)
The number of bits used to represent each signal sample. Tunable.
Minimum number of samples for each write to file
The number of consecutive samples to write with each file access, L.
Tunable.
See “Exporting and Playing WAV Files” on page 3-79 for related information.
5-450
Transpose
Purpose 5Transpose
Compute the transpose of a matrix.
Description The Transpose block transposes the M-by-N input matrix to size N-by-M. When
the Hermitian check box is selected, the block performs the Hermitian
(complex conjugate) transpose
y = u' % Equivalent MATLAB code
u *11 u *21
u 11 u 12 u 13
u' u *12 u *22
u 21 u 22 u 23
u *13 u *23
When the Hermitian check box is not selected, the block performs the
nonconjugate transpose
y = u.' % Equivalent MATLAB code
u 11 u 21
u 11 u 12 u 13
u.' u 12 u 22
u 21 u 22 u 23
u 13 u 23
Dialog Box
Hermitian
When selected, specifies the complex conjugate transpose. Tunable, except
in Simulink’s external mode.
5-451
Transpose
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-452
Triggered Delay Line
Description The Triggered Delay Line block acquires a collection of Mo input samples into
a frame, where Mo is specified by the Delay line size parameter. The block
buffers a single sample from input 1 whenever it is triggered by the control
signal at input 2 ( ). The newly acquired input sample is appended to the
output frame (in the same simulation step) so that the new output overlaps the
previous output by Mo-1 samples. Between triggering events the block ignores
input 1 and holds the output at its last value.
The triggering event at input 2 is specified by the Trigger type pop-up menu,
and can be one of the following:
• Rising edge triggers execution of the block when the trigger input rises from
a negative value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers execution of the block when the trigger input falls from
a positive value to zero or a negative value, or from zero to a negative value.
• Either edge triggers execution of the block when either a rising or falling
edge (as described above) occurs.
The Triggered Delay Line block has zero latency, so the new input appears at
the output in the same simulation time step. The output frame period is the
same as the input sample period, Tfo=Tsi.
Sample-Based Operation
In sample-based operation, the Triggered Delay Line block buffers a sequence
of sample-based length-N vector inputs (1-D, row, or column) into a sequence
of overlapping sample-based Mo-by-N matrix outputs, where Mo is specified by
the Delay line size parameter (Mo>1). That is, each input vector becomes a row
in the sample-based output matrix. When Mo=1, the input is simply passed
through to the output, and retains the same dimension. Sample-based
full-dimension matrix inputs are not accepted.
Frame-Based Operation
In frame-based operation, the Triggered Delay Line block rebuffers a sequence
of frame-based Mi-by-N matrix inputs into an sequence of overlapping
5-453
Triggered Delay Line
Initial Conditions
The Triggered Delay Line block’s buffer is initialized to the value specified by
the Initial condition parameter. The block always outputs this buffer at the
first simulation step (t=0). If the block’s output is a vector, the Initial
condition can be a vector of the same size, or a scalar value to be repeated
across all elements of the initial output. If the block’s output is a matrix, the
Initial condition can be a matrix of the same size, a vector (of length equal to
the number of matrix rows) to be repeated across all columns of the initial
output, or a scalar to be repeated across all elements of the initial output.
Dialog Box
Trigger type
The type of event that triggers the block’s execution. Tunable.
Delay line size
The length of the output frame (number of rows in output matrix), Mo.
Initial condition
The value of the block’s initial output, a scalar, vector, or matrix.
5-454
Triggered Delay Line
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-455
Triggered Signal From Workspace
Description The Triggered Signal From Workspace block imports signal samples from the
MATLAB workspace into the Simulink model when triggered by the control
signal at the input port ( ). The Signal parameter specifies the name of a
MATLAB workspace variable containing the signal to import, or any valid
MATLAB expression defining a matrix or 3-D array.
When the Signal parameter specifies an M-by-N matrix (M≠1), each of the N
columns is treated as a distinct channel. The frame size is specified by the
Samples per frame parameter, Mo, and the output when triggered is an
Mo-by-N matrix containing Mo consecutive samples from each signal channel.
For Mo=1, the output is sample-based; otherwise the output is frame-based.
For convenience, an imported row vector (M=1) is treated as a single channel,
so the output dimension is Mo-by-1.
When the Signal parameter specifies an M-by-N-by-P array, the block
generates a single page of the array (an M-by-N matrix) at each trigger time.
The Samples per frame parameter must be set to 1, and the output is always
sample-based.
Trigger Event
The triggering event at the input port is specified by the Trigger type pop-up
menu, and can be one of the following:
• Rising edge triggers execution of the block when the trigger input rises from
a negative value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers execution of the block when the trigger input falls from
a positive value to zero or a negative value, or from zero to a negative value.
• Either edge triggers execution of the block when either a rising or falling
edge (as described above) occurs.
5-456
Triggered Signal From Workspace
5-457
Triggered Signal From Workspace
Dialog Box
Signal
The name of the MATLAB workspace variable from which to import the
signal, or a valid MATLAB expression specifying the signal.
Trigger type
The type of event that triggers the block’s execution. Tunable, except in
Simulink’s external mode.
Initial output
The value to output until the first trigger event is received.
Samples per frame
The number of samples, Mo, to buffer into each output frame. This value
must be 1 if a 3-D array is specified in the Signal parameter.
Form output after final data value by
Specifies the output after all of the specified signal samples have been
generated. The block can output zeros for the duration of the simulation
(Setting to zero), repeat the final data sample (Holding Final Value) or
repeat the entire signal from the beginning (Cyclic Repetition).
5-458
Triggered Signal From Workspace
Supported (MATLAB commands for casting values to certain data types are provided in
Data Types parentheses.)
Boolean (boolean)
8-, 16-, and 32-bit signed integer (int8, int16, int32)
8-, 16-, and 32-bit unsigned integer (uint8, uint16, uint32)
Single-precision floating point (single)
Double-precision floating point (double)
5-459
Triggered To Workspace
Description The Triggered To Workspace block creates a matrix or array variable in the
workspace, where it stores the acquired inputs at the end of a simulation. An
existing variable with the same name is overwritten.
For an M-by-N frame-based input, the block creates an N-column workspace
matrix in which each group of M rows represents a single input frame from
each of N channels (the most recent frame occupying the last M rows). The
maximum size of this workspace variable is limited to P-by-N, where P is the
Maximum number of rows parameter. (If the simulation progresses long
enough for the block to acquire more than P samples, it stores only the most
recent P samples.) The Decimation factor, D, allows you to store only every
Dth input frame.
For an M-by-N sample-based input, the block creates a three-dimensional
array in which each M-by-N page represents a single sample from each of M∗N
channels (the most recent input matrix occupying the last page). The
maximum size of this variable is limited to M-by-N-by-P, where P is the
Maximum number of rows parameter. (If the simulation progresses long
enough for the block to acquire more than P inputs, it stores only the last P
inputs.) The Decimation factor, D, allows you to store only every Dth input
matrix.
The block acquires and buffers a single frame from input 1 whenever it is
triggered by the control signal at input 2 ( ). At all other times, the block
ignores input 1. The triggering event at input 2 is specified by the Trigger type
pop-up menu, and can be one of the following:
• Rising edge triggers execution of the block when the trigger input rises from
a negative value to zero or a positive value, or from zero to a positive value.
• Falling edge triggers execution of the block when the trigger input falls from
a positive value to zero or a negative value, or from zero to a negative value.
• Either edge triggers execution of the block when either a rising or falling
edge (as described above) occurs.
To save a record of the sample time corresponding to each sample value, check
the Time box in the Save to workspace parameters list of the Simulation
5-460
Triggered To Workspace
Dialog Box
Trigger type
The type of event that triggers the block’s execution. Tunable.
Variable name
The name of the workspace matrix in which to store the data.
Maximum number of rows
The maximum number of rows (one row per time step) to be saved, P. The
default is 100 rows.
Decimation
The decimation factor, D. The default is 1.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-461
Triggered To Workspace
5-462
Unbuffer
Purpose 5Unbuffer
Unbuffer a frame input to a sequence of scalar outputs.
Description The Unbuffer block unbuffers an Mi-by-N frame-based input into a 1-by-N
sample-based output. That is, inputs are unbuffered row-wise so that each
matrix row becomes an independent time-sample in the output. The rate at
which the block receives inputs is generally less than the rate at which the
block produces outputs.
“slow-time” input “fast-time” output
(frame size = 3, frame period = 3∗Tsi) (frame size = 1, sample period = T si)
7 4 1
8 5 2 9 8 7 6 5 4 3 2 1
9 6 3
The block adjusts the output rate so that the sample period is the same at both
the input and output, Tso=Tsi. Therefore, the output sample period for an input
of frame size Mi and frame period Tfi is Tfi/Mi, which represents a rate Mi times
higher than the input frame rate. In the example above, the block receives
inputs only once every three sample periods, but produces an output once every
sample period. To rebuffer frame-based inputs to a larger or smaller frame size,
use the Buffer block.
In the model below, the block unbuffers a four-channel frame-based input with
frame size 3. The Initial conditions parameter is set to zero and the tasking
mode is set to multitasking, so the first three outputs are zero vectors (see
“Latency” below).
5-463
Unbuffer
ch2 ch3
ch1 ch4 ch2 ch3
ch1 ch4
7 0 0 –7 0000 t=0
t=6 8 0 0 –8
9 0 1 –9 initial condition 0000 t=1
(multitasking delay)
Tfi = 3 0000 t=2
Frame-based input ,
4 0 0 –4 frame period = T fi 1 0 1 –1 t=3
t=3 5 0 1 –5
6 0 1 –6 2 0 1 –2 t=4
Sample-based output ,
sample period = Tfi/Mi 3 0 0 –3 t=5
1 0 1 –1 4 0 0 –4 t=6
t=0 2 0 1 –2 first matrix input Tso = Tsi = 1
3 0 0 –3 5 0 1 –5 t=7
Latency
Zero Latency. The Unbuffer block has zero tasking latency in Simulink’s
single-tasking mode. Zero tasking latency means that the first input sample
(received at t=0) appears as the first output sample.
5-464
Unbuffer
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
Dialog Box
Initial conditions
The value of the block’s initial output for cases of nonzero latency; a scalar,
vector, or matrix.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-465
Uniform Decoder
Library Quantizers
Description The Uniform Decoder block performs the inverse operation of the Uniform
Encoder block, and reconstructs quantized floating-point values from encoded
integer input. The block adheres to the definition for uniform decoding
specified in ITU-T Recommendation G.701.
Inputs can be real or complex values of the following six integer data types:
uint8, uint16, uint32, int8, int16, or int32.
The block first casts the integer input values to floating-point values, and then
uniquely maps (decodes) them to one of 2B uniformly spaced floating point
values in the range [-V, (1-21-B)V], where B is specified by the Bits parameter
(as an integer between 2 and 32) and V is a floating-point value specified by the
Peak parameter. The smallest input value representable by B bits (0 for an
unsigned input data type; -2B-1 for a signed input data type) is mapped to the
value -V. The largest input value representable by B bits (2B-1 for an unsigned
input data type; 2B-1-1 for a signed input data type) is mapped to the value
(1-21-B)V. Intermediate input values are linearly mapped to the intermediate
values in the range [-V, (1-21-B)V].
To correctly decode values encoded by the Uniform Encoder block, the Bits and
Peak parameters of the Uniform Decoder block should be set to the same
values as the Bits and Peak parameters of the Uniform Encoder block. The
Overflow mode parameter specifies the Uniform Decoder block’s behavior
when the integer input is outside the range representable by B bits. If
Saturate is selected, unsigned input values greater than 2B-1 saturate at 2B-1;
signed input values greater than 2B-1-1 or less than -2B-1 saturate at those
limits. The real and imaginary components of complex inputs saturate
independently.
If Wrap is selected, unsigned input values, u, greater than 2B-1 are wrapped
back into the range [0, 2B-1] using mod-2B arithmetic.
u = mod(u,2^B) % Equivalent MATLAB code
5-466
Uniform Decoder
Signed input values, u, greater than 2B-1-1 or less than -2B-1 are wrapped back
into that range using mod-2B arithmetic.
u = (mod(u+2^B/2,2^B)-(2^B/2)) % Equivalent MATLAB code
Example Consider a Uniform Decoder block with the following parameter settings:
• Peak = 2
• Bits = 3
The input to the block is the uint8 output of a Uniform Encoder block with
comparable settings: Peak = 2, Bits = 3, and Output type = Unsigned.
(Comparable settings ensure that inputs to the Uniform Decoder block do not
saturate or wrap. See the example on the Uniform Encoder reference page for
more about these settings.)
The real and complex components of each input are independently mapped to
one of 23 distinct levels in the range [-2.0,1.5].
0 is mapped to -2.0
1 is mapped to -1.5
2 is mapped to -1.0
3 is mapped to -0.5
4 is mapped to 0.0
5 is mapped to 0.5
6 is mapped to 1.0
7 is mapped to 1.5
5-467
Uniform Decoder
Dialog Box
Peak
The largest amplitude represented in the encoded input. To correctly
decode values encoded with the Uniform Encoder block, set the Peak
parameters in both blocks to the same value.
Bits
The number of input bits, B, used to encode the data. (This can be less than
the total number of bits supplied by the input data type.) To correctly
decode values encoded with the Uniform Encoder block, set the Bits
parameters in both blocks to the same value.
Overflow mode
The block’s behavior when the integer input is outside the range
representable by B bits. Out-of-range inputs can either saturate at the
extreme value, or wrap back into range.
Output type
The precision of the floating-point output, single or double.
5-468
Uniform Decoder
5-469
Uniform Encoder
Library Quantizers
Description The Uniform Encoder block performs the following two operations on each
floating-point sample in the input vector or matrix:
In the first step, the block quantizes an input value to one of 2B uniformly
spaced levels in the range [-V, (1-21-B)V], where B is specified by the Bits
parameter and V is specified by the Peak parameter. The quantization process
rounds both positive and negative inputs downward to the nearest
quantization level, with the exception of those that fall exactly on a
quantization boundary. The real and imaginary components of complex inputs
are quantized independently.
The number of bits, B, can be any integer value between 2 and 32, inclusive.
Inputs greater than (1-21-B)V or less than -V saturate at those respective
values. The real and imaginary components of complex inputs saturate
independently.
In the second step, the quantized floating-point value is uniquely mapped
(encoded) to one of 2B integer values. If the Output type is set to Unsigned
integer, the smallest quantized floating-point value, -V, is mapped to the
integer 0, and the largest quantized floating-point value, (1-21-B)V, is mapped
to the integer 2B-1. Intermediate quantized floating-point values are linearly
(uniformly) mapped to the intermediate integers in the range [0, 2B-1]. For
efficiency, the block automatically selects an unsigned output data type (uint8,
uint16, or uint32) with the minimum number of bits equal to or greater
than B.
If the Output type is set to Signed integer, the smallest quantized
floating-point value, -V, is mapped to the integer -2B-1, and the largest
quantized floating-point value, (1-21-B)V, is mapped to the integer 2B-1-1.
Intermediate quantized floating-point values are linearly mapped to the
intermediate integers in the range [-2B-1, 2B-1-1]. The block automatically
selects a signed output data type (int8, int16, or int32) with the minimum
number of bits equal to or greater than B.
5-470
Uniform Encoder
Inputs can be real or complex, double or single precision. The output data types
that the block uses are shown in the table below. Note that most of the blocks
in the DSP Blockset accept only double precision inputs. Use the Simulink
Data Type Conversion block to convert integer data types to double precision.
See “Working with Data Types” in the Simulink documentation for a complete
discussion of data types, as well as a list of Simulink blocks capable of
reduced-precision operations.
2 to 8 uint8 int8
9 to 16 uint16 int16
17 to 32 uint32 int32
The Uniform Encoder block operations adhere to the definition for uniform
encoding specified in ITU-T Recommendation G.701.
Example The figure below illustrates uniform encoding with the following parameter
settings:
• Peak = 2
• Bits = 3
• Output type = Unsigned
7
Output Value (real or imaginary component)
−1
−3 −2 −1 0 1 2 3
Input Value (real or imaginary component)
5-471
Uniform Encoder
The real and complex components of each input (horizontal axis) are
independently quantized to one of 23 distinct levels in the range [-2,1.5] and
then mapped to one of 23 integer values in the range [0,7].
-2.0 is mapped to 0
-1.5 is mapped to 1
-1.0 is mapped to 2
-0.5 is mapped to 3
0.0 is mapped to 4
0.5 is mapped to 5
1.0 is mapped to 6
1.5 is mapped to 7
The table below shows the results for a few particular inputs.
The output data type is automatically set to uint8, the most efficient format for
this input range.
5-472
Uniform Encoder
Dialog Box
Peak
The largest input amplitude to be encoded, V. Real or imaginary input
values greater than (1-21-B)V or less than -V saturate (independently for
complex inputs) at those limits.
Bits
The number of levels at which to quantize the floating-point input. (Also
the number of bits needed to represent the integer output.)
Output type
The data type of the block’s output, Unsigned integer or Signed integer.
Unsigned outputs are uint8, uint16, or uint32, while signed outputs are
int8, int16, or int32.
5-473
Unwrap
Purpose 5Unwrap
Unwrap the phase of a signal.
Description The Unwrap block unwraps each input channel by adding or subtracting
appropriate multiples of 2π to each channel element. The input can be any
matrix or 1-D vector, and must have radian phase entries. The block recognizes
phase discontinuities larger than the Tolerance parameter setting.
The block preserves the input size, dimension, and frame status, and the
output port rate equals the input port rate.
For a detailed discussion of the Unwrap block, see the following sections:
• “Acceptable Inputs and Corresponding Output Characteristics” on
page 5-474
• “The Two Unwrap Modes” on page 5-475
• “Unwrap Method” on page 5-479
• “Definition of Phase Unwrap” on page 5-479
5-474
Unwrap
5-475
Unwrap
In both unwrap modes, the block adds 2πk to each input channel’s elements, where it updates k
at each phase discontinuity. (For more on the updating of k, see “Unwrap Method” on
page 5-479.) The number of times that k is reset to 0 depends on the unwrap mode.
Default Unwrap Mode: Nondefault Unwrap Mode:
Initialize k to 0 For Only the First Input Frame Set k to 0 For Each Successive Input Matrix
or Input Vector
In this mode, k is initialized to 0 for only the In this mode, k is reset to 0 for each
first input matrix or input vector. As k gets successive input matrix or input vector. As k
updated, the value of k is retained between gets updated, the value of k is only retained
successive input matrices or input vectors. That within the current input matrix or vector.
is, the block unwraps each input’s channel by That is, the block unwraps each input’s
considering phase discontinuities in all channel by considering phase discontinuities
previous frames and the current frame. in the current input matrix or input vector
only, ignoring discontinuities in previous
inputs.
Depending on input characteristics, the block Depending on input characteristics, the block
unwraps the columns or each individual unwraps the columns or rows of the input:
element of the input:
• Frame-based inputs — unwrap columns
• Frame-based inputs — unwrap columns • Sample-based nonrow inputs — unwrap
• Sample-based inputs — unwrap each element columns
of the input. • Sample-based row vector inputs — unwrap
• 1-D vector inputs — treat as frame-based the row.
column • 1-D vector inputs — treat as frame-based
column
See the following diagrams. See the following diagrams.
5-476
Unwrap
The following diagrams illustrate how the two unwrap modes operate on
various inputs.
The block treats each input column as an The block treats each element of the input
independent channel. It unwraps by treating matrix as an independent channel. (The first
Channel 1 of Frame 2 as a continuation of sample in Channel 1 is in the upper left corner
Channel 1 of Frame 1. of the Sample 1 matrix. The second sample of
Channel 1 is in the corresponding corner of the
Sample 2 matrix, and so on.)
Channel 2
Channel 1
0 0
Tolerance parameter =π 0 0
Tolerance parameter =π
2π 2π
Channel 1
Frame 1 --- 0
3
--- 0
3 Ch 3
–2 π 4π 00 Ch 4 00
----- 0 --- 0
3 Phase discontinuity (jump in 3 Sample 1 00 00
0 0
adjacent phase values greater 2π 2π
than the value of the
6π
--- 0 --- 0
3
Phase discontinuity --- 0
3
Frame 2
2π
--- 0 3 Sample 2 0 0
3 Tolerance parameter) 8π
--- 0
0 0
–2 π 3
----- 0 4π
3 10π – 2π --- 0
3
----- 0
3 Sample 3 ----- 0
3 0 0
0 0 0 0
2π
Frame 3 --- 0
3
12π
----- 0 00
6π
--- 0
–2 π
3 Sample 4 3
----- 0 14π 00 0 0
3 ----- 0
3
2π 8π
16π Sample 5 --- 0 --- 0
----- 0 3 3
3
0 0 0 0
5-477
Unwrap
The block unwraps each column, treating each The block unwraps each row, treating each
input matrix as completely unrelated to the input row vector as completely independent of
other input matrices. the other input row vectors.
0 0 0 0
2π 2π
Input 3 --- 0
3
--- 0
3
–2 π 4π
----- 0 --- 0
3 3
5-478
Unwrap
Unwrap Method
The Unwrap block unwraps each channel of its input matrix or input vector by
adding 2πk to each successive channel element, and updating k at each phase
jump. See the following steps to the unwrap method for details.
Relevant Unwrap Terms:
• ui — ith element of the input channel on which the algorithm operates
• α — Tolerance parameter value
• phase jump or phase discontinuity — difference between phase values of
two adjacent channel entries that exceeds α . The diagram in the next
section indicates phase jumps with red arrows.
5-479
Unwrap
diagram. For more on phase unwrap, see the previous section, “Unwrap
Method” on page 5-479.
5-480
Unwrap
and – π < θ ′n ≤ π
[ sin ( 0 ), sin ------ , sin ------ , sin ------ , …, sin 15---------- ]
2π 4π 6π 28π
0 pi
5 2pi
5 3pi
5 4pi
5 5pi 6pi
Restricted Phases (Radians)
10
–2 π ⁄ 5
Output: [ θ 0, θ 1, …, θ N ] – 4π ⁄5
−5
0 2 4 6 8 10 12 14 16
where θ n = θ ′n + 2πk
2π 4π – 4 π – 2π 2π 4π – 4 π – 2π 2π 4π – 4 π – 2π
Update the value of k after every large [0,------, ------, ----------, ----------, 0, ------, ------, ----------, ----------, 0, ------, ------, ----------, ----------]
5 5 5 5 5 5 5 5 5 5 5 5
jump in phase value, indicated by .
Add 2π Add 4π Add 6π
30
Unwrapped phase data ranging over all numbers.
28π ⁄ 5
25
Unwrapped Phases (Radians)
20 4π
15
10 2π
2π ⁄ 5 Time
0 0
5-481
Unwrap
Range of restricted phase data: – π < θ ′ ≤ π Range of unwrapped phase data: all numbers
sin ( θ ′ ) sin ( θ )
2π 2π 12π 22π
4π ------ ------, ----------, ----------, …
------ 5 4π 14π 24π 5 5 5
5 ------, ----------, ----------, …
5 5 5
Large jump in π θ′ 0 cos ( θ ′ ) θ 0, 2π, 4π, … cos ( θ )
phase value ( –π )
6π 16π 26π
– 4π ------, ----------, ----------, …
---------- 5 5 5
5 – 2π 8π 18π 28π
---------- ------, ----------, ----------, …
5 5 5 5
Limitations The Unwrap block detects branch cut crossings, but can be fooled by sparse,
rapidly changing phase values.
Dialog Box
5-482
Unwrap
5-483
Upsample
Purpose 5Upsample
Resample an input at a higher rate by inserting zeros.
Description The Upsample block resamples each channel of the Mi-by-N input at a rate
L times higher than the input sample rate by inserting L-1 zeros between
consecutive samples. The integer L is specified by the Upsample factor
parameter. The Sample offset parameter delays the output samples by an
integer number of sample periods D, where 0 ≤ D < (L-1), so that any of the L
possible output phases can be selected.
Sample-Based Operation
When the input is sample-based, the block treats each of the M∗N matrix
elements as an independent channel, and upsamples each channel over time.
The Frame-based mode parameter must be set to Maintain input frame size.
The output sample rate is L times higher than the input sample rate
(Tso = Tsi/L), and the input and output sizes are identical.
Frame-Based Operation
When the input is frame-based, the block treats each of the N input columns as
a frame containing Mi sequential time samples from an independent channel.
The block upsamples each channel independently by inserting L-1 rows of
zeros between each row in the input matrix. The Frame-based mode
parameter determines how the block adjusts the rate at the output to
accommodate the added rows. There are two available options:
• Maintain input frame size
The block generates the output at the faster (upsampled) rate by using a
proportionally shorter frame period at the output port than at the input port.
For upsampling by a factor of L, the output frame period is L times shorter
than the input frame period (Tfo = Tfi/L), but the input and output frame
sizes are equal.
5-484
Upsample
5-485
Upsample
Zero Latency. The Upsample block has zero tasking latency for all single-rate
operations. The block is single-rate for the particular combinations of sampling
mode and parameter settings shown in the table below.
The block also has zero latency for all multirate operations in Simulink’s
single-tasking mode.
Zero tasking latency means that the block propagates the first input (received
at t=0) immediately following the D consecutive zeros specified by the Sample
offset parameter. This output (D+1) is followed in turn by the L-1 inserted
zeros and the next input sample. The Initial condition parameter value is not
used.
Nonzero Latency. The Upsample block has tasking latency only for multirate
operation in Simulink’s multitasking mode:
5-486
Upsample
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
11 – 11
12 – 12
13 – 13
14 – 14
- Upsample factor = 2
- Sample offset = 1
- Initial condition = [11 -11;12 -12;13 -13;14 -14]
- Frame-based mode = Maintain input frame size
5-487
Upsample
• Configure the Probe blocks by deselecting the Probe width and Probe
complex signal check boxes (if desired).
This model is multirate because there are at least two distinct frame rates, as
shown by the two Probe blocks. To run this model in Simulink’s multitasking
mode, select Fixed-step and discrete from the Type controls in the Solver
panel of the Simulation Parameters dialog box, and select MultiTasking from
the Mode parameter. Also set the Stop time to 30.
Run the model and look at the output, yout. The first few samples of each
channel are shown below.
yout =
0 0
11 -11
0 0
12 -12
0 0
13 -13
0 0
14 -14
0 0
1 -1
0 0
2 -2
0 0
3 -3
0 0
4 -4
0 0
5 -5
0 0
Since we ran this frame-based multirate model in multitasking mode, the first
row of the initial condition matrix appears as output sample 2
(i.e., sample D+1, where D is the Sample offset value). It is followed by the
other three initial condition rows, each separated by L-1 inserted rows of zeros,
where L is the Upsample factor value of 2. The first row of the first input
matrix appears in the output as sample 10 (i.e., sample MiL+D+1, where Mi is
the input frame size).
5-488
Upsample
Dialog Box
Upsample factor
The integer factor, L, by which to increase the input sample rate.
Sample offset
The sample offset, D, which must be an integer in the range [0,L-1].
Initial condition
The value with which the block is initialized for cases of nonzero latency, a
scalar or matrix. This value (first row in frame-based mode) appears in the
output as sample D+1.
Frame-based mode
For frame-based operation, the method by which to implement the
upsampling: Maintain input frame size (i.e., increase the frame rate), or
Maintain input frame rate (i.e., increase the frame size). The Framing
parameter must be set to Maintain input frame size for sample-base
inputs.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-489
Upsample
5-490
Variable Fractional Delay
Description The Variable Fractional Delay block delays each channel of the Mi-by-N input
matrix, u, by a variable (possibly noninteger) number of sample intervals.
The block computes the value for each channel of the output based on the
stored samples in memory most closely indexed by the Delay input, v, and the
interpolation method specified by the Mode parameter. In Linear
Interpolation mode, the block stores the D+1 most recent samples received at
the In port for each channel, where D is the Maximum delay. In FIR
Interpolation mode, the block stores the D+P+1 most recent samples received
at the In port for each channel, where P is the Interpolation filter
half-length.
See the Variable Integer Delay block for further discussion of how input
samples are stored in the block’s memory. The Variable Fractional Delay block
differs only in the way that these stored sample are accessed; a fractional delay
requires the computation of a value by interpolation from the nearby samples
in memory.
Sample-Based Operation
When the input is sample-based, the block treats each of the Mi∗N matrix
elements as an independent channel. The input to the Delay port, v, is an
Mi-by-N matrix of floating-point values in the range 0 ≤ v ≤ D that specifies the
number of sample intervals to delay each channel of the input.
A 1-D vector input is treated as an Mi-by-1 matrix, and the output is 1-D.
The Initial conditions parameter specifies the values in the block’s memory at
the start of the simulation in the same manner as for the Variable Integer
Delay block. See the section on sample-based initial conditions there for
complete information.
Frame-Based Operation
When the input is frame-based, the block treats each of the N input columns as
a frame containing Mi sequential time samples from an independent channel.
5-491
Variable Fractional Delay
The input to the Delay port, v, contains floating-point values in the range
0 ≤ v ≤ D specifying the number of sample intervals to delay the current input.
The input to the Delay port can be:
For example, if v is the Mi-by-1 matrix [v(1) v(2) ... v(Mi)]', the earliest
sample in the current frame is delayed by v(1) fractional sample intervals, the
following sample in the frame is delayed by v(2) fractional sample intervals,
and so on. The set of fractional delays contained in v is applied identically to
every channel of a multichannel input.
The Initial conditions parameter specifies the values in the block’s memory at
the start of the simulation in the same manner as for the Variable Integer
Delay block. See the section on frame-based initial conditions there for
complete information.
Interpolation Modes
The delay value specified at the Delay port is used as an index into the block’s
memory, U, which stores the D+1 most recent samples received at the In port
for each channel. For example, an integer delay of 5 on a scalar input sequence
retrieves and outputs the fifth most recent input sample from the block’s
memory, U(6). Fractional delays are computed by interpolating between stored
samples; the two available interpolation modes are described below.
Linear Interpolation Mode. For noninteger delays, at each sample time the Linear
Interpolation mode uses the two samples in memory nearest to the specified
delay to compute a value for the sample at that time. If v is the specified
fractional delay for a scalar input, the output sample, y, is computed as follows.
vi = floor(v) % vi = integer delay
vf = v-vi % vf = fractional delay
y = (1-vf)*U(vi) + vf*U(vi+1)
5-492
Variable Fractional Delay
Delay values less than 0 are clipped to 0, and delay values greater than D are
clipped to D, where D is the Maximum delay. Note that a delay value of 0
causes the block to pass through the current input sample, U(1), in the same
simulation step that it is received.
FIR Interpolation Mode. In FIR Interpolation mode, the block computes a value
for the sample at the desired delay by applying an FIR filter of order 2P to the
stored samples on either side of the desired delay, where P is the Interpolation
filter half-length. For periodic signals, a larger value of P (i.e., a higher order
filter) yields a better estimate of the sample at the specified delay. A value
between 4 and 6 for this parameter (i.e. a 7th to 11th order filter) is usually
adequate.
A vector of 2P filter tap weights is precomputed at the start of the simulation
for each of Q-1 discrete points between input samples, where Q is specified by
the Interpolation points per input sample parameter. For a delay
corresponding to one of the Q interpolation points, the unique filter computed
for that interpolation point is applied to obtain a value for the sample at the
specified delay. For delay times that fall between interpolation points, the
value computed at the nearest interpolation point is used. Since Q controls the
number of locations where a unique interpolation filter is designed, a larger
value results in a better estimate of the sample at a given delay.
Note that increasing the Interpolation filter half length (P) increases the
number of computations performed per input sample, as well as the amount of
memory needed to store the filter coefficients. Increasing the Interpolation
points per input sample (Q) increases the simulation’s memory requirements
but does not affect the computational load per sample.
The Normalized input bandwidth parameter allows you to take advantage of
the bandlimited frequency content of the input. For example, if you know that
the input signal does not have frequency content above Fs/4, you can specify a
value of 0.5 for the Normalized input bandwidth to constrain the frequency
content of the output to that range.
(Each of the Q interpolation filters can be considered to correspond to one
output phase of an “upsample-by-Q” FIR filter. In this view, the Normalized
input bandwidth value is used to improve the stopband in critical regions, and
to relax the stopband requirements in frequency regions where there is no
signal energy.)
5-493
Variable Fractional Delay
For delay values less than P/2-1, the output is computed using linear
interpolation. Delay values greater than D are clipped to D, where D is the
Maximum delay.
The block uses the intfilt function in the Signal Processing Toolbox to
compute the FIR filters.
Note When the Variable Fractional Delay block is used in a feedback loop, at
least one block with nonzero delay (e.g., an Integer Delay block with
Delay > 0) should be included in the loop as well. This prevents the occurrence
of an algebraic loop if the delay of the Variable Fractional Delay block is
driven to zero.
Examples The dspafxf demo illustrates an audio flanger system built around the
Variable Fractional Delay block.
Dialog Box
Mode
The method by which to interpolate between adjacent stored samples to
obtain a value for the sample indexed by the input at the Delay port.
5-494
Variable Fractional Delay
Maximum delay
The maximum delay that the block can produce, D. Delay input values
exceeding this maximum are clipped at the maximum.
Interpolation filter half-length
Half the number of input samples to use in the FIR interpolation filter.
Interpolation points per input sample
The number of points per input sample, Q, at which a unique FIR
interpolation filter is computed.
Normalized input bandwidth
The bandwidth to which the interpolated output samples should be
constrained. A value of 1 specifies half the sample frequency.
Initial conditions
The values with which the block’s memory is initialized. See the Variable
Integer Delay block for more information.
5-495
Variable Integer Delay
Description The Variable Integer Delay block delays the discrete-time input at the In port
by the integer number of sample intervals specified by the input to the
Delay port. The Delay port input rate must be an integer multiple of the
In port input rate. The delay for a sample-based input sequence is a scalar
value to uniformly delay every channel. The delay for a frame-based input
sequence can be a scalar value to uniformly delay every sample in every
channel, a vector containing one delay value for each sample in the input
frame, or a vector containing one delay value for each channel in the input
frame.
The delay values should be in the range of 0 to D, where D is the Maximum
delay. Delay values greater than D or less than 0 are clipped to those
respective values and noninteger delays are rounded to the nearest integer
value.
The Variable Integer Delay block differs from the Integer Delay block in the
following ways.
Delay can vary with time; for Delay cannot vary with time; for
example, for a frame-based input, example, for a frame-based input,
the nth element’s delay in the first the nth element’s delay is the same
input frame can differ from the nth for every input frame.
element’s delay in the second input
frame.
Sample-Based Operation
When the input is an M-by-N sample-based matrix, the block treats each of the
M∗N matrix elements as an independent channel, and applies the delay at the
Delay port to each channel.
5-496
Variable Integer Delay
The Variable Integer Delay block stores the D+1 most recent samples received
at the In port for each channel. At each sample time the block outputs the
stored sample(s) indexed by the input to the Delay port.
For example, if the input to the In port, u, is a scalar signal, the block stores a
vector, U, of the D+1 most recent signal samples. If the current input sample
is U(1), the previous input sample is U(2), and so on, then the block’s output is
y = U(v+1); % Equivalent MATLAB code
where v is the input to the Delay port. Note that a delay value of 0 (v=0) causes
the block to pass through the sample at the In port in the same simulation step
that it is received. The block’s memory is initialized to the Initial conditions
value at the start of the simulation (see below).
The figure below shows the block output for a scalar ramp sequence at the In
port, a Maximum delay of 5, an Initial conditions of 0, and a variety of
different delays at the Delay port.
In Delay Memory (U) Output
0 3 [0 0 0 0 0 0] i.c. 0
1 1 [1 0 0 0 0 0] 0
2 0 [2 1 0 0 0 0] 2
3 2 [3 2 1 0 0 0] 1
4 1 [4 3 2 1 0 0] 3
Simulation time
5 2 [5 4 3 2 1 0] 3
6 2.3 [6 5 4 3 2 1] 4
7 3 rounded to 2 [7 6 5 4 3 2] 4
8 –1 [8 7 6 5 4 3] 8
9 4 clipped to 0 [9 8 7 6 5 4] 5
10 10 [10 9 8 7 6 5] 5
...
...
...
...
clipped to 5
Note that the current input at each time-step is immediately stored in memory
as U(1). This allows the current input to be available at the output for a delay
of 0 (v=0).
The Initial conditions parameter specifies the values in the block’s memory at
the start of the simulation. Unlike the Integer Delay block, the Variable
5-497
Variable Integer Delay
Integer Delay block does not have a fixed initial delay period during which the
initial conditions appear at the output. Instead, the initial conditions are
propagated to the output only when they are indexed in memory by the value
at the Delay port. Both fixed and time-varying initial conditions can be
specified in a variety of ways to suit the dimensions of the input sequence.
Fixed Initial Conditions. The settings shown below specify fixed initial conditions.
For a fixed initial condition, the block initializes each of D samples in memory
to the value entered in the Initial conditions parameter. A fixed initial
condition in sample-based mode can be specified in one of the following ways:
• Array of size M-by-N-by-D. In this case, you can specify different fixed initial
conditions for each channel. See the Array bullet in “Time-Varying Initial
Conditions” below for details.
Initial conditions cannot be specified by full matrices.
5-498
Variable Integer Delay
the block initializes U(2:6) with values [-1, -1, -1, 0, 1].
• Array of dimension M-by-N-by-D with which to initialize memory samples
U(2:D+1), where D is the Maximum delay and M and N are the number of
rows and columns, respectively, in the input matrix. For a 2-by-3 input and
the parameters below,
Frame-Based Operation
When the input is an M-by-N frame-based matrix, the block treats each of the
N input columns as a frame containing M sequential time samples from an
independent channel.
In frame-based mode, the input at the Delay port can be a scalar value to
uniformly delay every sample in every channel. It can also be a length-M
vector, v = [v(1) v(2) ... v(M)], containing one delay for each sample in
the input frame(s). The set of delays contained in vector v is applied identically
to every channel of a multichannel input. The Delay port entry can also be a
length-N vector, containing one delay for each channel.
Vector v does not specify when the samples in the current input frame will
appear in the output. Rather, v indicates which previous input samples (stored
in memory) should be included in the current output frame. The first sample in
the current output frame is the input sample v(1) intervals earlier in the
5-499
Variable Integer Delay
sequence, the second sample in the current output frame is the input sample
v(2) intervals earlier in the sequence, and so on.
The illustration below shows how this works for an input with a sample period
of 1 and frame size of 4. The Maximum delay (Dmax) is 5, and the Initial
conditions parameter is set to -1. The delay input changes from [1 3 0 5] to
[2 0 0 2] after the second input frame. Note that the samples in each output
frame are the values in memory indexed by the elements of v.
y(1) = U(v(1)+1)
y(2) = U(v(2)+1)
y(3) = U(v(3)+1)
y(4) = U(v(4)+1)
1 1 [ 1 -1 -1 -1 -1 -1] –1 U(2)
2 3 [ 2 1 -1 -1 -1 -1] –1 U(4)
(t=0) [ 3 2 1 -1 -1 -1] U(1)
3 0 3
4 5 [ 4 3 2 1 -1 -1] –1 U(6)
5 1 [ 5 4 3 2 1 -1] 4 U(2)
6 3 [ 6 5 4 3 2 1] 3 U(4)
(t=4) [ 7 6 5 4 3 2] U(1)
7 0 7
Simulation time
8 5 [ 8 7 6 5 4 3] 3 U(6)
9 2 [ 9 8 7 6 5 4] 7 U(3)
10 0 [10 9 8 7 6 5] 10 U(1)
(t=8) [11 10 9 8 7 6] U(1)
11 0 11
12 2 [12 11 10 9 8 7] 10 U(3)
13 2 [13 12 11 10 9 8] 11 U(3)
14 0 [14 13 12 11 10 9] 14 U(1)
(t=12) [15 14 13 12 11 10] U(1)
15 0 15
16 2 [16 15 14 13 12 11] 14 U(3)
The Initial conditions parameter specifies the values in the block’s memory at
the start of the simulation. Both fixed and time-varying initial conditions can
be specified.
5-500
Variable Integer Delay
Fixed Initial Conditions. The settings shown below specify fixed initial conditions.
For a fixed initial condition, the block initializes each of D samples in memory
to the value entered in the Initial conditions parameter. A fixed initial
condition in frame-based mode can be one of the following:
• Array of size 1-by-N-by-D. In this case, you can specify different fixed initial
conditions for each channel. See the Array bullet in “Time-Varying Initial
Conditions” below for details.
Initial conditions cannot be specified by full matrices.
• Vector of dimensions 1-by-D. In this case, all channels have the same set of
time-varying initial conditions specified by the entries of the vector. For the
ramp input [100; 100]' with a frame size of 4, delay of 5, and the parameter
settings below,
the block outputs the following sequence of frames at the start of the
simulation.
5-501
Variable Integer Delay
–1 –1 –5 –5 4 4
–2 –2 , 1 1 , 5 5 , …
–3 –3 2 2 6 6
–4 –4 3 3 7 7
• Array of size 1-by-N-by-D. In this case, you can specify different time-varying
initial conditions for each channel. For the ramp input [100; 100]' with a
frame size of 4, delay of 5, and the parameter settings below,
the block outputs the following sequence of frames at the start of the
simulation.
–1 – 11 –5 – 55 44
–2 – 22 , 1 1 , 5 5 ,…
–3 – 33 2 2 66
–4 – 44 3 3 77
Note that by specifying a 1-by-N-by-D initial condition array such that each
1-by-N vector entry is identical, you can implement different fixed initial
conditions for each channel.
Initial conditions cannot be specified by full matrices.
Dialog Box
5-502
Variable Integer Delay
Maximum delay
The maximum delay that the block can produce for any sample. Delay
input values exceeding this maximum are clipped at the maximum.
Initial conditions
The values with which the block’s memory is initialized.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-503
Variable Selector
Description The Variable Selector block extracts a subset of rows or columns from the
M-by-N input matrix at the In port, u.
When the Select parameter is set to Rows, the Variable Selector block
extracts rows from the input matrix, while if the Select parameter is set to
Columns, the block extracts columns.
When the Selector mode parameter is set to Variable, the length-L vector
input to the Idx port selects L rows or columns of u to pass through to the
output. The elements of the indexing vector can be updated at each sample
time, but the vector length must remain the same throughout the simulation.
When the Selector mode parameter is set to Fixed, the Idx port is disabled,
and the length-L vector specified in the Elements parameter selects L rows or
columns of u to pass through to the output. The Elements parameter is
tunable, so you can change the values of the indexing vector elements at any
time during the simulation; however, the vector length must remain the same.
For both variable and fixed indexing modes, the row selection operation is
equivalent to
y = u(idx,:) % Equivalent MATLAB code
where idx is the length-L indexing vector. The row selection output size is
L-by-N and the column selection output size is M-by-L. Input rows or columns
can appear any number of times in the output, or not at all.
When the input is a 1-D vector, the Select parameter is ignored; the output is
a 1-D vector of length L containing those elements specified by the length-L
indexing vector.
When an element of the indexing vector references a nonexistent row or column
of the input, the block reacts with the behavior specified by the Invalid index
parameter. The following options are available:
5-504
Variable Selector
• Clip index – Clip the index to the nearest valid value, and do not issue an
alert. Example: For a 64-by-N input, an index of 72 is clipped to 64; an index
of -2 is clipped to 1.
• Clip and warn – Display a warning message in the MATLAB command
window, and clip as above.
• Generate error – Display an error dialog box and terminate the simulation.
Note The Variable Selector block always copies the selected input rows to a
contiguous block of memory (unlike the Simulink Selector block).
Dialog Box
Select
The dimension of the input to select, Rows or Columns. Tunable.
Selector mode
The type of indexing operation to perform, Variable or Fixed. Variable
indexing uses the input at the Idx port to select rows or columns from the
input at the In port. Fixed indexing uses the Elements parameter value to
select rows from the input at the In port, and disables the Idx port.
5-505
Variable Selector
Elements
A vector containing the indices of the input rows or columns that will
appear in the output matrix. This parameter is available when Fixed is
selected in the Selector mode parameter. Tunable.
Invalid index
Response to an invalid index value. Tunable.
5-506
Variance
Purpose 5Variance
Compute the variance of an input or sequence of inputs.
Library Statistics
Description The Variance block computes the variance of each column in the input, or
tracks the variance of a sequence of inputs over a period of time. The Running
variance parameter selects between basic operation and running operation.
Basic Operation
When the Running variance check box is not selected, the block computes the
variance of each column in M-by-N input matrix u independently at each
sample time.
y = var(u) % Equivalent MATLAB code
For convenience, length-M 1-D vector inputs and sample-based length-M row
vector inputs are both treated as M-by-1 column vectors. (A scalar input
generates a zero-valued output.)
The output at each sample time, y, is a 1-by-N vector containing the variance
for each column in u. For purely real or purely imaginary inputs, the variance
of the jth column is the square of the standard deviation:
M
∑
2
u ij – µ j
2 i=1
y j = σ j = ----------------------------------- 1≤j≤N
M–1
where µj is the mean of the jth column. For complex inputs, the output is the
total variance for each column in u, which is the sum of the real and imaginary
variances for that column:
2 2 2
σ j = σ j, Re + σ j, Im
The frame status of the output is the same as that of the input.
Running Operation
When the Running variance check box is selected, the block tracks the
variance of each channel in a time-sequence of M-by-N inputs. For
sample-based inputs, the output is a sample-based M-by-N matrix with each
5-507
Variance
element yij containing the variance of element uij over all inputs since the last
reset. For frame-based inputs, the output is a frame-based M-by-N matrix with
each element yij containing the variance of the jth column over all inputs since
the last reset, up to and including element uij of the current input.
If the Reset port parameter is set to Non-zero sample, the optional Rst port
is enabled and the block resets the running variance when the scalar input at
the Rst port is nonzero. (The Rst port can be disabled by setting the Reset port
parameter to None.)
As in basic operation, length-M 1-D vector inputs and sample-based length-M
row vector inputs are both treated as M-by-1 column vectors.
Example The Variance block in the model below calculates the running variance of a
frame-based 3-by-2 (two-channel) matrix input, u. The running variance is
reset at t=2 by an impulse to the block’s Rst port.
• Running variance =
• Reset port = Non-zero sample
• Signal = u
• Sample time = 1/3
• Samples per frame = 3
where
u = [6 1 3 -7 2 5 8 0 -1 -3 2 1;1 3 9 2 4 1 6 2 5 0 4 17]'
• Delay (samples) = 2
5-508
Variance
• Sample time = 1
• Samples per frame = 1
61 0 0
First
13 t=0 0 First output 12.50 2.00
input 39 6.33 17.33
–7 2 30.92 12.92
2 4 t=1 0 23.50 9.70
5 1 21.47 9.07
8 6 0 0
Simulation time
–3 0 23.33 7.58
2 4 t=3 0 17.70 5.80
1 17 14.17 35.47
The statsdem demo illustrates the operation of several blocks from the
Statistics library.
Dialog Box
Running variance
Enables running operation when selected.
5-509
Variance
Reset port
Enables the Rst input port when set to Non-zero sample, and disables the
Rst input port when set to None.
5-510
Vector Scope
Description The Vector Scope block is a comprehensive tool, similar to a digital oscilloscope,
for displaying time-domain, frequency-domain, or user-defined signals. The
scope window, display-property settings, axis-property settings, and
line-property settings are shared with the Spectrum Scope block.
The input to this block can be any M-by-N matrix or 1-D vector, where 1-D
vectors are treated as column vectors. The frame-status for inputs are ignored;
the input to the block is always assumed to be a data frame, even if the input
is not identified as a frame. Thus, any M-by-N matrix input is interpreted as
having N independent channels of data, each with M consecutive samples to be
plotted sequentially across the horizontal axis of the plot.
The Vector Scope is most commonly used to plot consecutive time samples
(from a frame-based vector). However, it is just as appropriate to use the Vector
Scope to plot vectors containing data such as filter coefficients or spectral
magnitudes.
Displaying Data
The domain of the data is specified by the Input domain parameter under the
Scope properties check box, and can be Time, Frequency, or User-defined.
5-511
Vector Scope
➀ ➁ ➂ ➃
5-512
Vector Scope
In other cases, the frame rate and frame size do not provide enough
information for the block to correctly scale the horizontal axis, and you should
specify the appropriate value for the Increment per sample in input frame
parameter. The range of the horizontal axis is [0,M∗Is∗S], where M is the
number of samples in each consecutive input frame, and S is the Horizontal
display span parameter.
5-513
Vector Scope
• Each frame of frequency-domain data shares the same length as the frame
of time-domain data from which it was generated; for example, when the
FFT is computed on the same number of points as are contained in the
time-domain input.
• The sample period of the time-domain signal in the simulation is equal to the
period with which the physical signal was originally sampled.
• Consecutive frames containing the time-domain signal do not overlap each
other; that is, a particular signal sample does not appear in more than one
sequential frame.
In cases where not all of these conditions hold, you should specify the
appropriate value for the Sample time of original time-series parameter.
The Frequency units parameter specifies whether the frequency axis values
should be in units of Hertz or rad/sec, and the Frequency range parameter
specifies the range of frequencies over which the magnitudes in the input
should be plotted. The available options are [0..Fs/2], [-Fs/2..Fs/2], and [0..Fs],
where Fs is the original time-domain signal’s sample frequency.
The Vector Scope block assumes that the input data spans the range [0,Fs), as
does the output from an FFT. To plot over the range [0..Fs/2] the scope
truncates the input vector leaving only the first half of the data, then plots
these remaining samples over half the frequency range. To plot over the range
[-Fs/2..Fs/2], the scope reorders the input vector elements such that the last
half of the data becomes the first half, and vice versa; then it relabels the x-axis
accordingly.
If the Frequency units parameter specifies Hertz, the spacing between
frequency points is 1/(M∗Ts). For Frequency units of rad/sec, the spacing
between frequency points is 2π/(M∗Ts). The Amplitude scaling parameter
allows you to select Magnitude or dB scaling along the y-axis.
Scope Properties
The Vector Scope block allows you to plot time-domain, frequency-domain, or
user-defined data, and adjust the frame span of the plot. Selecting the Scope
Properties check box displays the Input domain parameter, which specifies
the domain of the input data. In addition, for time-domain data, a Time
display span parameter allows you to specify the number of frames to be
displayed across the width of the scope window at any given time. For
5-514
Vector Scope
Display Properties
The Vector Scope and Spectrum Scope blocks offer a similar collection of
display property settings. These can be exposed in the parameter dialog box by
selecting the Display properties check box. Many of the properties can be
accessed under the Axes menu in the unzoomed scope view (when Compact
display is deselected), or by right-clicking on the scope window.
The Show grid parameter toggles the background grid on and off. This option
can also be set in the Axes menu of the scope window.
When Persistence is selected, the window maintains successive displays. That
is, the scope does not erase the display after each frame (or collection of
frames), but overlays successive input frames in the scope display. This option
can also be set in the Axes menu of the scope window.
When Frame number is selected, the number of the current frame in the input
sequence is displayed on the scope window, incrementing the count as each
new input is received. Counting starts at 1 with the first input frame, and
continues until the simulation stops.
When Channel legend is selected, a legend indicating the line color, style, and
marker of each channel’s data is added. If the input signal is labeled, that label
is displayed in the channel legend. If the input signal is not labeled, but comes
from a Matrix Concatenation block with labeled inputs, those labels are
displayed in the channel legend. Otherwise, each channel in the legend is
labeled with the channel number (CH 1, CH 2, etc.). Click and drag on the legend
5-515
Vector Scope
to reposition it in the scope window; double click on the line label to edit the
text. Note that when the simulation is rerun, the new edits are lost and the
labels revert to the defaults. The Channel legend option can also be set in the
Axes menu of the scope window.
When Compact display is selected, the scope completely fills the containing
figure window. Menus and axis titles are not displayed, and the numerical axis
labels are shown within the axes. When Compact display is deselected, the
axis labels and titles are displayed in a gray border surrounding the scope axes,
and the window’s menus (including Axes and Channels) and toolbar are
visible. This option can also be set in the Axes menu of the scope window.
When Open scope at start of simulation is selected, the scope opens at the
start of the simulation. When this parameter is deselected, the scope does not
open automatically during the simulation. To view the scope, double-click on
the Vector Scope block, which brings up the scope as well as the block
parameter dialog box. This feature is useful when you have several scope
blocks in a model, and you do not want to view all the associated scopes during
the simulation.
Open scope immediately allows you to open the scope from the Vector Scope
parameters dialog box while the simulation is running. If the simulation is
running and the scope window is not visible, you can double-click on the scope
block to expose the scope window and the parameters dialog box. If you close
the scope window during simulation, you can make it visible again by checking
the Open scope immediately check box as long as the simulation is running.
The check box will become deselected as soon as the scope opens.
The Scope position parameter specifies a four-element vector of the form
[left bottom width height]
specifying the position of the scope window on the screen, where (0,0) is the
lower-left corner of the display. See the MATLAB figure command for more
information.
Axis Properties
The Vector Scope and Spectrum Scope blocks also share a similar collection of
axis property settings. For the Vector Scope, the parameters listed under the
Axis properties check box vary with the domain of the input. The dialogue box
below shows the parameters available for frequency-domain data.
5-516
Vector Scope
Minimum Y-limit and Maximum Y-limit set the range of the vertical axis. If
Autoscale is selected from the right-click pop-up menu or from the Axes menu
option, the Minimum Y-limit and Maximum Y-limit values are automatically
recalculated to best fit the range of the data on the scope. Both of these
parameters are available for all input domains.
Y-axis title is the text to be displayed to the left of the y-axis. This parameter
is available for all input domains. X-axis title is an analogous parameter
available only when plotting user-defined data (this parameter is not visible in
the dialog box shown).
Frequency-domain and user-defined data need extra information to scale the
horizontal axis. For user-defined data, the parameters that provide this
information are Inherit sample increment from input and Increment in
sample in input frame. See “Scaling the Horizontal Axis for User-Defined
Signals” on page 5-513 for more information. For frequency-domain data, an
analogous pair of parameters, Inherit sample time from input and Sample
time of original time series, must be specified. See “Scaling the Horizontal
Axis for Frequency-Domain Signals” on page 5-513 for more information.
Three other parameters related to scaling the x-axis for frequency-domain
signals are Frequency units, Frequency range, and Amplitude scaling.
These are also described in “Scaling the Horizontal Axis for Frequency-Domain
Signals” on page 5-513.
5-517
Vector Scope
Line Properties
Both the Vector Scope and Spectrum scope also offer a similar collection of line
property settings. These can be exposed in the parameter dialog box by
selecting the Line properties check box. These properties can also be accessed
under the Channels menu in the unzoomed scope view (when Compact
display is deselected), or by right-clicking on the scope window.
The Line properties setting are typically used to help distinguish between two
or more independent channels of data on the scope.
The Line visibilities parameter specifies which channels’ data is displayed on
the scope, and which is hidden. The syntax specifies the visibilities in list form,
where the term on or off as a list entry specifies the visibility of the
corresponding channel’s data. The list entries are separated by the pipe
symbol, |.
For example, a five-channel signal would ordinarily generate five distinct plots
on the scope. To disable plotting of the third and fifth lines, enter the following
visibility specification.
on | on | off | on | off
➀ ➁ ➂ ➃ ➄
Note that the first (leftmost) list item corresponds to the first signal channel
(leftmost column of the input matrix).
The Line styles parameter specifies the line style with which each channel’s
data is displayed on the scope. The syntax specifies the channel line styles in
list form, with each list entry specifying a style for the corresponding channel’s
data. The list entries are separated by the pipe symbol, |.
5-518
Vector Scope
For example, a five-channel signal would ordinarily generate all five plots with
a solid line style. To instead plot each line with a different style, enter
- | -- | : | -. | -
➀ ➁ ➂ ➃ ➄
These settings plot the signal channels with the following styles.
Solid
Dashed
Dotted
Dash-dot
Solid
Note that the first (leftmost) list item, '-', corresponds to the first signal
channel (leftmost column of the input matrix). See LineStyle property of the
line function in the MATLAB documentation for more information about the
style syntax. To specify a marker for the individual sample points, use the Line
markers parameter, described below.
The Line markers parameter specifies the marker style with which each
channel’s samples are represented on the scope. The syntax specifies the
channels’ marker styles in list form, with each list entry specifying a marker
for the corresponding channel’s data. The list entries are separated by the pipe
symbol, |.
For example, a five-channel signal would ordinarily generate all five plots with
no marker symbol (i.e., the individual sample points are not marked on the
scope). To instead plot each line with a different marker style, you could enter
* | . | x | s | d
➀ ➁ ➂ ➃ ➄
5-519
Vector Scope
These settings plot the signal channels with the following styles.
Asterisk
Point
Cross
Square
Diamond
Note that the first (leftmost) list item, '*', corresponds to the first signal
channel (leftmost column of the input matrix). See the Marker property of the
line function in the MATLAB documentaion for more information about the
available markers.
Type the word stem instead of one of the basic Marker shapes to produce a stem
plot for the data in a particular channel.
The Line colors parameter specifies the color in which each channel’s data is
displayed on the scope. The syntax specifies the channel colors in list form,
with each list entry specifying a color (in one of MATLAB’s ColorSpec formats)
for the corresponding channel’s data. The list entries are separated by the pipe
symbol, |.
For example, a five-channel signal would ordinarily generate all five plots in
the color black. To instead plot the lines with the color order below, enter
[0 0 0] | [0 0 1] | [1 0 0 ] | [0 1 0] | [.7529 0 .7529]
➀ ➁ ➂ ➃ ➄
or
'k' | 'b' | 'r' | 'g' | [.7529 0 .7529]
➀ ➁ ➂ ➃ ➄
5-520
Vector Scope
These settings plot the signal channels in the following colors (8-bit RGB
equivalents shown in the center column).
Black (0,0,0)
Blue (0,0,255)
Red (255,0,0)
Green (0,255,0)
Note that the first (leftmost) list item, 'k', corresponds to the first signal
channel (leftmost column of the input matrix). See ColorSpec in the online
MATLAB documentaion for more information about the color syntax.
Scope Window
The scope title (in the window title bar) is the same as the block title. The axis
scaling is set by parameters listed under the Axis properties check box in the
dialog box.
In addition to the standard MATLAB figure window menus (File, Edit,
Window, Help), the Vector Scope window has an Axes and a Channels menu.
The properties listed in the Axes menu apply to all channels. Many of the
parameters in this menu are also accessible through the block parameter
dialog box. These are Persistence, Show grid, Compact display, Frame
number, and Channel legend; see “Display Properties” on page 5-515 for more
information. Below are descriptions of the other parameters listed in the Axes
menu:
• Refresh erases all data on the scope display, except for the most recent trace.
This command is useful in conjunction with the Persistence setting.
• Autoscale resizes the y-axis to best fit the vertical range of the data. The
numerical limits selected by the autoscale feature are displayed in the
Minimum Y-limit and Maximum Y-limit parameters in the parameter
dialog box. You can change them by editing those values.
5-521
Vector Scope
The properties listed in the Channels menu apply to a particular channel. The
parameters listed in this menu are Visible, Style, Marker, and Color; they
correspond to the parameters listed in the dialog box under the Line
properties check box. See “Line Properties” on page 5-518 for more
information.
Many of these options can also be accessed by right-clicking with the mouse
anywhere on the scope display. The menu that pops up contains a combination
of the options available in both the Axes and Channels menus. The right-click
menu is very helpful when the scope is in zoomed mode, when the Axes and
Channels menus are not visible.
5-522
Vector Scope
Scope properties
Select to expose Scope properties panel. Tunable.
Input domain
The domain of the input; Time, Frequency, or User-defined. Tunable.
Time display span
The number of consecutive frames to display (horizontally) on the scope at
any one time. (Visible when the Input domain parameter is Time.)
Horizontal display span
(Not visible in the dialog box shown; appears under Scope properties
when the Input domain parameter is User-defined.) The number of
consecutive frames to display (horizontally) on the scope at any one time.
5-523
Vector Scope
Display properties
Select to expose Display properties panel. Tunable.
Show grid
Toggles the scope grid on and off. Tunable.
Persistence
Causes the window to maintain successive displays. That is, the scope does
not erase the display after each frame (or collection of frames), but overlays
successive input frames in the scope display. Tunable.
Frame number
Displays the number of the current frame in the input sequence, when
selected with Compact display off. The frame number is not shown when
Compact display is selected. Tunable.
Channel legend
Toggles the legend on and off. Tunable.
Compact display
Resizes the scope to fill the window. Tunable.
Open scope at start of simulation
Opens the scope at the start of the simulation. When this parameter is
deselected, the scope will not open automatically during the simulation; to
view the scope, double click on the Vector Scope block during the
simulation. This will bring up the scope as well as the block parameter
dialog box. Tunable.
5-524
Vector Scope
Axis properties
Select to expose the Axis Properties panel. Tunable.
Frequency units
The frequency units for the x-axis, Hertz or rad/sec. (Visible when the
Input domain parameter is Frequency.) Tunable.
Frequency range
The frequency range over which to plot the data, [0..Fs/2], [-Fs/2..Fs/2],
or [0..Fs], where Fs is the sample frequency of the original time-domain
signal, 1/Ts. (Visible when the Input domain parameter is Frequency.)
Tunable.
Inherit sample time from input
Computes the time-domain sample period from the frame period and frame
size of the frequency-domain input; use only if the length of the each frame
5-525
Vector Scope
5-526
Vector Scope
Line properties
Select to expose the Line Properties panel. Tunable.
Line visibilities
The visibility of the various channels’ scope traces, on or off. Channels are
separated by a pipe (|) symbol. Tunable.
Line styles
The line styles of the various channels’ scope traces. Channels are
separated by a pipe (|) symbol. Tunable.
Line markers
The line markers of the various channels’ scope traces. Channels are
separated by a pipe (|) symbol. Tunable.
Line colors
The colors of the various channels’ scope traces, in one of the ColorSpec
formats. Channels are separated by a pipe (|) symbol. Tunable.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-527
Vector Scope
5-528
Wavelet Analysis
Description The Wavelet Analysis block uses the wfilters function from the Wavelet
Toolbox to construct a dyadic analysis filter bank that decomposes a broadband
signal into a collection of successively more bandlimited components. An
n-level filter bank structure is shown below, where n is specified by the
Number of levels parameter.
u HP ↓2 2Ts y1
LP ↓2 HP ↓2 4Ts y2
LP ↓2 HP ↓2 8Ts y3
LP ↓2 ... HP ↓2 yn
Tsi = Ts LP ↓2 yn+1
At each level, the low-frequency output of the previous level is decomposed into
adjacent high- and low-frequency subbands by a highpass (HP) and lowpass
(LP) filter pair. Each of the two output subbands is half the bandwidth of the
input to that level. The bandlimited output of each filter is maximally
decimated by a factor of 2 to preserve the bit rate of the original signal.
5-529
Wavelet Analysis
Filter Coefficients
The filter coefficients for the highpass and lowpass filters are computed by the
Wavelet Toolbox function wfilters, based on the wavelet specified in the
Wavelet name parameter. The table below lists the available options.
Haar wfilters('haar')
Daubechies wfilters('db4')
Symlets wfilters('sym3')
Coiflets wfilters('coif1')
Biorthogonal wfilters('bior3.1')
See the Wavelet Toolbox decantation for more information about the wfilters
function. If you want to explicitly specify the FIR coefficients for the analysis
filter bank, use the Dyadic Analysis Filter Bank block.
Tree Structure
The wavelet tree structure has n+1 outputs, where n is the number of levels.
The sample rate and bandwidth of the top output are half the input sample rate
and bandwidth. The sample rate and bandwidth of each additional output
5-530
Wavelet Analysis
(except the last) are half that of the output from the previous level. In general,
for an input with sample period Tsi = Ts, and bandwidth BW, output yk has
sample period Tso,k and bandwidth BWk.
k
( 2 )T s (1 ≤ k ≤ n)
T so, k =
( 2 n )T (k = n + 1)
s
BW
---------- (1 ≤ k ≤ n)
2
k
BW k =
BW
---------- (k = n + 1)
n
2
Note that in frame-based mode, the change in the sample period of output yk is
reflected by its frame size, Mo,k, rather than by its frame rate.
Mi
------- (1 ≤ k ≤ n)
2
k
M o, k =
Mi
------- (k = n + 1)
n
2
The bottom two outputs (yn and yn+1) share the same sample period,
bandwidth, and frame size because they originate at the same tree level.
Sample-Based Operation
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and the block filters each channel independently over time. The
output at each port is the same size as the input, one output channel for each
input channel. As described earlier, each output port has a different sample
period.
The figure below shows the input and output sample periods for a 64-channel
sample-based input to a three-level filter bank. The input has a period of 1, so
the fastest output has a period of 2.
5-531
Wavelet Analysis
Tso = 2
Tso = 4
Tsi = 1
Tso = 8
Tso = 8
Frame-Based Operation
An Mi-by-N frame-based matrix input is treated as N independent channels,
and the block filters each channel independently over time. The input frame
size Mi must be a multiple of 2n, and n is the number of filter bank levels. For
example, a frame size of 8 would be appropriate for a three-level tree (23=8).
The number of columns in each output is the same as the number of columns
in the input.
Each output port has the same frame period as the input. The reduction in the
output sample rates results from the smaller output frame sizes, as shown in
the example below for a four-channel input to a three-level filter bank.
Tso = 1/32)
Tso = 1/8)
Latency
Zero Latency. The Wavelet Analysis block has no tasking latency for frame-based
operation, which is always single-rate. The block therefore analyzes the first
input sample (received at t=0) to produce the first output sample at each port.
5-532
Wavelet Analysis
2n-1 output samples, before propagating the first analyzed input sample
(computed from the input received at t=0).
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
Dialog Box
The parameters displayed in the dialog box vary for different wavelet types.
Only some of the parameters listed below are visible in the dialog box at any
one time.
Wavelet name
The wavelet used in the analysis.
Wavelet order
The order for the Daubechies, Symlets, and Coiflets wavelets. This
parameter is available only when one of these wavelets is selected in the
Wavelet name menu.
5-533
Wavelet Analysis
5-534
Wavelet Synthesis
Description The Wavelet Synthesis block uses the wfilters function from the Wavelet
Toolbox to reconstruct a signal that was decomposed by the Wavelet Analysis
block. The reconstruction or synthesis process is the inverse of the analysis
process, and restores the original signal by upsampling, filtering, and summing
the bandlimited inputs in stages corresponding to the analysis process. An
n-level synthesis filter bank structure is shown below, where n is specified by
the Number of levels parameter.
Wavelet Synthesis Filter Bank, n Levels
u1 2Ts ↑2 HP Σ y
u2 4Ts ↑2 HP Σ ↑2 LP
u3 8Ts ↑2 HP Σ ↑2 LP
un ↑2 HP Σ ... ↑2 LP
un+1 ↑2 LP Tso = Ts
Tsi = (2k)Ts for input uk, 1 ≤ k ≤ n HP: highpass filter with fc ≈ 1/2 Nyquist
LP: lowpass filter with fc ≈ 1/2 Nyquist
Tsi = (2n)Ts for input un+1
↑2: upsample by 2
5-535
Wavelet Synthesis
For perfect reconstruction, the Wavelet Synthesis and Wavelet Analysis blocks
must have the same parameter settings.
Filter Coefficients
The filter coefficients for the highpass and lowpass filters are computed by the
Wavelet Toolbox function wfilters, based on the wavelet specified in the
Wavelet name parameter. The table below lists the available options.
Haar wfilters('haar')
Daubechies wfilters('db4')
Symlets wfilters('sym3')
Coiflets wfilters('coif1')
Biorthogonal wfilters('bior3.1')
See the Wavelet Toolbox documentation for more information about the
wfilters function. If you want to explicitly specify the FIR coefficients for the
synthesis filter bank, use the Dyadic Synthesis Filter Bank block.
5-536
Wavelet Synthesis
Tree Structure
The wavelet tree structure has n+1 inputs, where n is the number of levels. The
sample rate and bandwidth of the output are twice the sample rate and
bandwidth of the top input. The sample rate and bandwidth of each additional
input (except the last) are half that of the input to the previous level.
BW k
BW k + 1 = ------------- 1≤k<n
2
The bottom two inputs (un and un+1) should have the same sample rate and
bandwidth since they are processed by the same level.
T si, n + 1 = T si, n
BW n + 1 = BW n
Note that in frame-based mode, the sample period of input uk is reflected by its
frame size, Mi,k, rather than by its frame rate.
M i, k
M i, k + 1 = ------------ 1≤k<n
2
M i, n + 1 = M i, n
Sample-Based Operation
An M-by-N sample-based matrix input is treated as M∗N independent
channels, and the block filters each channel independently over time. The
output is the same size as the input at each port, one output channel for each
input channel. As described earlier, each input port has a different sample
period.
5-537
Wavelet Synthesis
The figure below shows the input and output sample periods for the four
64-channel sample-based inputs to a three-level filter bank. The fastest input
has a period of 2, so the output period is 1.
Tsi = 2
Tsi = 4
Tso = 1
Tsi = 8
Tsi = 8
Frame-Based Operation
An Mi-by-N frame-based matrix input is treated as N independent channels,
and the block filters each channel independently over time. The number of
columns in the output is the same as the number of columns in the input.
All inputs must have the same frame period, which is also the output frame
period. The different input sample rates should be represented by the input
frame sizes: If the input to the top port has frame size Mi, the input to the
second-from-top port should have frame size Mi/2, the input to the
third-from-top port should have frame size Mi/4, and so on. The input to the
bottom port should have the same frame size as the second-from-bottom port.
The increase in the sample rate of the output is also represented by its frame
size, which is twice the largest input frame size.
The relationship between sample periods, frame periods, and frame sizes is
shown below for a four-channel frame-based input to a 3-level filter bank.
(Tsi=1/32)
(Tsi=1/16) Tfo = 1
Tfi = 1
Tso = 1/64
(Tsi=1/8)
(Tsi=1/8)
5-538
Wavelet Synthesis
Latency
Zero Latency. The Wavelet Synthesis block has no tasking latency for
frame-based operation, which is always single-rate. The block therefore uses
the first input samples (received at t=0) to synthesize the first output sample.
In the above cases, the block repeats a zero initial condition in each channel for
the first D output samples, where D is the latency shown above. For example,
in single-tasking mode the block generates 2n-2 zero-valued output samples in
each channel before propagating the first synthesized output sample
(computed from the inputs received at t=0).
See “Excess Algorithmic Delay (Tasking Latency)” on page 3-91 and “The
Simulation Parameters Dialog Box” in the Simulink documentation for more
information about block rates and Simulink’s tasking modes.
Dialog Box
The parameters displayed in the dialog box vary for different wavelet types.
Only some of the parameters listed below are visible in the dialog box at any
one time.
Wavelet name
The wavelet used in the synthesis.
5-539
Wavelet Synthesis
Wavelet order
The order for the Daubechies, Symlets, and Coiflets wavelets. This
parameter is available only when one of these wavelets is selected in the
Wavelet name menu.
5-540
Window Function
Description The Window Function block has three modes of operation, selected by the
Operation parameter as described below.
Operation Modes
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:
5-541
Window Function
Window Sampling
For the generalized-cosine windows (Blackman, Hamming, and Hann), the
Sampling parameter determines whether the window samples are computed
in a periodic or a symmetric manner. For example, if Sampling is set to
Symmetric, a Hamming window of length M is computed as
w = hamming(M) % Symmetric (aperiodic) window
Window Type
The available window types are shown in the table below. The Stopband
attenuation in dB and Beta parameters specify the characteristics of the
Chebyshev and Kaiser windows, respectively, and are only available when
those window designs are selected.
When Window type is set to User defined, the Window function block
computes the user-defined window specified by the Window function name
parameter. If the user-defined window requires parameters other than the
window length, select the Additional parameters for user defined window
check box. The cell array entered in Window function parameters determines
the values of the additional parameters.
For complete information about the other window functions, consult the Signal
Processing Toolbox documentation.
Window Description
Type
5-542
Window Function
Window Description
Type
5-543
Window Function
Dialog Box
Operation
The block’s operation: Apply window to input, Generate window, or
Generate and apply window. The input/output port configuration is
updated to match the parameter setting.
Window type
The type of window to apply. Tunable.
Window length
The length of the window to apply. This parameter is available only when
Generate window is selected in the Operation menu. Otherwise, the
window vector length is computed to match the input frame size, M.
Sampling
The window sampling for generalized-cosine windows, Symmetric or
Periodic. Tunable.
Stopband attenuation in dB
(Not shown in dialog above. Visible for the Chebyshev window.) The level
(dB) of stopband attenuation, Rs. Tunable.
Beta
(Not shown in dialog above. Visible for the Kaiser window.) The Kaiser
window β parameter. Increasing β widens the mainlobe and decreases the
amplitude of the window sidelobes in the window’s frequency magnitude
response. Tunable.
5-544
Window Function
5-545
Yule-Walker AR Estimator
Description The Yule-Walker AR Estimator block uses the Yule-Walker AR method, also
called the autocorrelation method, to fit an autoregressive (AR) model to the
windowed input data by minimizing the forward prediction error in the
least-squares sense. This formulation leads to the Yule-Walker equations,
which are solved by the Levinson-Durbin recursion.
The Yule-Walker AR Estimator block can output the AR model coefficients as
polynomial coefficients, reflection coefficients, or both. The input is a
sample-based vector (row, column, or 1-D) or frame-based vector (column only)
representing a frame of consecutive time samples from a single-channel signal,
which is assumed to be the output of an AR system driven by white noise. The
block computes the normalized estimate of the AR system parameters, A(z),
independently for each successive input frame.
G G
H ( z ) = ------------ = -------------------------------------------------------------------------------
A(z) –1
1 + a ( 2 )z + … + a ( p + 1 )z
–p
5-546
Yule-Walker AR Estimator
Dialog Box
Output(s)
The type of AR model coefficients output by the block. The block can output
polynomial coefficients (A), reflection coefficients (K), or both (A and K).
Tunable.
Inherit estimation order from input dimensions
When selected, sets the estimation order p to one less than the length of the
input vector. Tunable.
Estimation order
The order of the AR model, p. This parameter is enabled when Inherit
estimation order from input dimensions is not selected.
5-547
Yule-Walker AR Estimator
5-548
Yule-Walker Method
Description The Yule-Walker Method block estimates the power spectral density (PSD) of
the input using the Yule-Walker AR method. This method, also called the
autocorrelation method, fits an autoregressive (AR) model to the windowed
input data by minimizing the forward prediction error in the least-squares
sense. This formulation leads to the Yule-Walker equations, which are solved
by Levinson-Durbin recursion.
The input is a sample-based vector (row, column, or 1-D) or frame-based vector
(column only) representing a frame of consecutive time samples from a
single-channel signal. The block’s output (a column vector) is the estimate of
the signal’s power spectral density at Nfft equally spaced frequency points in
the range [0,Fs), where Fs is the signal’s sample frequency.
When Inherit estimation order from input dimensions is selected, the order
of the all-pole model is one less that the input frame size. Otherwise, the order
is the value specified by the Estimation order parameter. The spectrum is
computed from the FFT of the estimated AR model parameters.
When Inherit FFT length from estimation order is selected, Nfft is specified
by (estimation order + 1), which must be a power of 2. When Inherit FFT
length from estimation order is not selected, Nfft is specified as a power of 2
by the FFT length parameter, and the block zero pads or truncates the input
to Nfft before computing the FFT. The output is always sample-based.
See the Burg Method block reference for a comparison of the Burg Method,
Covariance Method, Modified Covariance Method, and Yule-Walker AR
Estimator blocks. The Yule-Walker AR Estimator and Burg Method blocks
return similar results for large buffer lengths.
5-549
Yule-Walker Method
Dialog Box
5-550
Yule-Walker Method
5-551
Zero Pad
Description The Zero Pad block changes the size of the input matrix from Mi-by-Ni to
Mo-by-No by zero-padding or truncating along the rows, the columns, or both
dimensions. The dimensions of the output, Mo and No, are specified by the
Number of output rows and Number of output columns parameters,
respectively. You can set Action when truncation occurs so that the block
gives a warning or an error when truncation occurs.
The Zero pad along parameter specifies how the input should be altered. The
options are:
• Columns
When Columns is selected, the Number of output rows parameter (Mo) is
enabled, and the block pads or truncates each input column by an equal
amount. If Mo>Mi, the block pads by adding Mo-Mi rows of zeros to the
bottom of the matrix. If Mo<Mi, the block truncates by deleting Mi-Mo rows
from the bottom of the matrix. In both cases, the number of columns is
unchanged (No=Ni). A 1-D vector input is zero padded or truncated at the
“bottom,” and the output is a 1-D vector.
• Rows
When Rows is selected, the Number of output columns parameter (No) is
enabled, and the block pads or truncates each input row by an equal amount.
If No>Ni, the block pads by adding No-Ni columns of zeros to the right side of
the matrix. If No<Ni, the block truncates by deleting Ni-No columns from the
right side of the matrix. In both cases, the number of rows is unchanged
(Mo=Mi). A 1-D vector input is zero padded or truncated at the “bottom,” and
the output is a 1-D vector.
• Columns and rows
When Columns and rows is selected, both the Number of output rows
parameter (Mo) and the Number of output columns parameter (No) are
enabled, and the block pads or truncates rows and columns as specified. A
length-Mi 1-D vector input is treated as an Mi-by-1 matrix and the output is
an Mo-by-No matrix.
5-552
Zero Pad
• None
When None is selected, the input is passed through to the output without
padding or truncation.
Example In the model below, the 3-by-3 input is zero-padded along the column
dimension to 5-by-3. The parameter settings in the Zero Pad block are:
Dialog Box
5-553
Zero Pad
column and row dimensions should be changed; None disables padding and
truncation and passes the input through to the output unchanged.
Number of output rows
The desired number of rows in the output, Mo. This parameter is enabled
when Columns or Columns and rows is selected in the Zero pad along
menu.
Number of output columns
The desired number of columns in the output, No. This parameter is
enabled when Rows or Columns and rows is selected in the Zero pad
along menu.
Supported Fixed-point
Data Types Custom data types
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Single-precision floating point
Double-precision floating point
5-554
6
6-2
dsp_links
Purpose 6dsp_links
Display library link information for blocks linked to the DSP Blockset.
Syntax dsp_links
dsplinks(sys)
dsplinks(sys,mode)
Description dsp_links displays library link information for blocks linked to the DSP
Blockset. For each block in the current model, dsp_links replaces the block
name with the full pathname to the block’s library link in the DSP Blockset.
Blocks linked to v4 or later DSP Blockset blocks are highlighted in green while
blocks linked to v3 DSP Blockset blocks are highlighted in yellow. Blocks at all
levels of the model are analyzed.
A summary report indicating the number of blocks linked to each blockset
version is also displayed in the MATLAB command window. The highlighting
and link display is disabled when the model is executed or saved, or when
dsp_links is executed a second time from the MATLAB command line.
dsp_links(sys) toggles the display of block links in system sys. If sys is the
current model (gcs), this is the same as the plain dsp_links syntax.
dsp_links(sys,mode) directly sets the link display state, where mode can be
'on', 'off', or 'toggle'. The default is 'toggle'.
6-3
dsplib
Purpose 6dsplib
Open the main DSP Blockset library.
Syntax dsplib
dsplib ver
Description dsplib opens the current version of the main DSP Blockset library.
dsplib ver opens version ver of the DSP Blockset library, where ver can be 2,
3, or 4.
When you launch an older version of the DSP Blockset, MATLAB displays a
message reminding you that a newer version exists.
6-4
dspstartup
Purpose 6dspstartup
Configure the Simulink environment for DSP systems.
Syntax dspstartup
dspstartup;
For more information, see the description for the startup command in the
MATLAB documentation, “Using dspstartup.m” on page 2-12.
The dspstartup.m script sets the following Simulink environment parameters.
See Appendix A, “Model and Block Parameters,” in the Simulink
documentation for complete information about a particular setting.
Parameter Setting
SingleTaskRate error
TransMsg
Solver fixedstepdiscrete
SolverMode SingleTasking
6-5
dspstartup
Parameter Setting
StartTime 0.0
StopTime inf
FixedStep auto
SaveTime off
SaveOutput off
AlgebraicLoopMsg error
InvariantConstants on
RTWOptions [get_param(0,'RTWOptions')',
-aRollThreshold=2']
6-6
liblinks
Purpose 6liblinks
Display library link information for blocks linked to the DSP Blockset.
Syntax liblinks
liblinks(sys)
liblinks(sys,mode,lib)
liblinks(sys,mode,lib,clrs)
blks = liblinks(...)
Description Please see the command line help for liblinks. Type
help liblinks
6-7
rebuffer_delay
Purpose 6rebuffer_delay
Compute the number of samples of delay introduced by buffering and
unbuffering operations.
Syntax d = rebuffer_delay(f,n,m)
d = rebuffer_delay(f,n,m,'singletasking')
• Buffer
• Unbuffer
6-8
Index
Symbols
Numerics
f (linear frequency). See frequencies 0s
fnyq (Nyquist frequency). See frequencies inserting 5-200, 5-207, 5-484
Fs (sample frequency or rate) outputting
See sample periods Counter block 5-105
M (frame size). See frame sizes and matrices Discrete Impulse block 5-138
Mi (input frame size). See frame sizes Integer Delay block 5-244
Mo (output frame size). See frame sizes N-Sample Enable block 5-325
N (number of channels) Signal From Workspace block 5-388, 5-457
See sample vectors and matrices padding with 3-27, 3-31
ω (digital frequency). See frequencies 1s, outputting 5-325
Ω (angular frequency). See frequencies 2-norm 5-405
Ωp (passband edge frequency)
See edge frequencies
Ωp1 (lower passband edge frequency) A
See edge frequencies acquiring data, blocks for 5-10
Ωp2 (upper passband edge frequency) adaptive filter designs
See edge frequencies blocks for 1-4
Ωs (stopband edge frequency) FIR 5-268
See edge frequencies Kalman 5-249
Ωs1 (lower stopband edge frequency) LMS 5-268
See edge frequencies RLS 5-375
Ωs2 (upper stopband edge frequency) adaptive filters 4-3
See edge frequencies Adaptive Filters library 5-9
Rp (passband ripple). See passband ripple addition, cumulative 5-116
Rs (stopband attenuation) algebraic loop errors 3-92
See stopband attenuation algorithmic delay 3-86
T (signal period). See periods adjustable 3-90
T (tunable parameter). See tuning parameters and initial conditions 3-90
Tf (frame period). See frame periods basic 3-89
Tfi (input frame period). See frame periods excess 3-91
Tfo (output frame period). See frame periods relation to latency 3-91
Ts (sample period). See sample periods zero 3-87
Tsi (input sample period). See sample periods Analog Filter Design block 4-7, 5-23
Tso (output sample period). See sample periods analog filter designs 5-23, 5-24
See also filter designs, continuous-time
I-1
Index
I-2
Index
I-3
Index
I-4
Index
discrete sample time, defined 3-10 Dyadic Analysis Filter Bank block 3-22, 5-151
discrete-time blocks Dyadic Synthesis Filter Bank block 3-22, 5-159
nonsource 3-10
source 3-10
discrete-time signals E
characteristics 3-4 Edge Detector block 5-166
defined 3-3 edge frequencies
terminology 3-4, 3-5 of analog filters 4-8
See also signals edge frequencies, of analog filters 4-8
discretizing a continuous-time signal 3-10 ellip 4-8
Display block 5-10 elliptic filter designs
displaying analog 4-8
blocks for 5-10 band configurations for 4-8
frame-based data 5-511 using Analog Filter Design block 5-23
matrices as images 5-292 errors
doc 1-8 algebraic loop 3-92
documentation discrete-time source block 3-10
Signal Processing Toolbox 5-542 due to continuous-time input to a discrete-time
Downsample block 3-22, 3-23, 5-141 block 3-10
downsampling 5-141, 5-193, 5-207 due to insufficient audio buffer size 5-446
See also rate conversion sample-rate mismatch 3-7
DSP Blockset ERT 5-6
accessing 1-8 estimation
documentation 1-9 nonparametric 5-277, 5-385
features 1-3 parametric 1-5
getting started with 1-8 using Burg AR Estimator block 5-48
installation 1-7 using Burg Method block 5-50
organization 1-6 using Covariance AR Estimator block 5-111
overview 1-3 using Covariance Method block 5-113
required products 1-13 using Modified Covariance AR Estimator
DSP Constant block 5-148 block 5-314
DSP Sinks library 5-9 using Modified Covariance Method block
DSP Sources library 5-9 5-316
dsp_links 6-3 using Yule-Walker AR Estimator block
dsplib 1-6, 1-8, 6-4 5-546
dspstartup M-file 2-11, 2-15, 6-5 using Yule-Walker Method block 5-549
editing 2-12 Estimation library 5-9
I-5
Index
I-6
Index
I-7
Index
I-8
Index
continuous-time 4-7 K
images, displaying matrices as 5-292 Kaiser windows 5-542, 5-543
importing Kalman Adaptive Filter block 5-249
arrays 3-65
blocks for 5-10
frame-based signals 3-68 L
pages of an array 3-65 last-input, first-output (LIFO) registers 5-413
sample-based matrices 3-65 latency 3-91
sample-based signals 3-63, 3-65, 3-68 due to frame-based processing 3-15
sample-based vectors 3-63 example 3-93
scalars 5-222 predicting 3-92
signals 3-62, 5-388, 5-456 reducing 3-91
vectors 5-222 relation to delay 3-91
indexing lattice filters 5-438
to deconstruct multichannel signals 3-55 LDL Factorization block 5-254
Indexing library 5-10 LDL Inverse block 5-257
inf parameter setting 2-6 LDL Solver block 5-259
info 1-9 least mean-square algorithm 5-268
Inherit Complexity block 5-239 Least Squares Polynomial Fit block 5-261
inheriting sample periods 3-10 length of a vector
initial conditions, with basic algorithmic delay defined 1-11
3-90 See also frame sizes
Inline Parameters check box 2-14 Levinson-Durbin block 5-264
input frame periods libraries
defined 3-16 Adaptive Filters 5-9
See also frame periods Buffers 5-10
input frame sizes. See frame sizes Demos 1-6
input periods. See also frame periods displaying link information 6-3
input sample periods. See sample periods DSP Sinks 5-9
installing the DSP Blockset 1-7 DSP Sources 5-9
Integer Delay block 5-241 Estimation 5-9
initial conditions for 5-241, 5-244 Filter Designs 5-9
interpolating 5-200, 5-207 Filtering 5-9
procedure 5-200 Indexing 5-10
InvariantConstants parameter 2-13 Linear Prediction 5-9
inverse discrete cosine transforms. See IDCTs Linear System Solvers 5-9
listed 5-9
I-9
Index
I-10
Index
I-11
Index
O
ω (digital frequency) P
defined 3-5 Pad block 5-337
See also frequencies pages of an array
Ω (angular frequency) defined 1-11
defined 3-5 exporting 3-73
See also frequencies pages of an array, importing 3-65
Ωp (passband edge frequency) parameters
See edge frequencies Buffer overlap, negative values for 3-50
Ωp1 (lower passband edge frequency) continuous-time filter 4-8
See edge frequencies definition of 2-7
Ωp2 (upper passband edge frequency) InvariantConstants 2-13
See edge frequencies normalized frequency 4-8
Ωs (stopband edge frequency) RTWOptions 2-15
See edge frequencies SaveOutput 2-13
Ωs1 (lower stopband edge frequency) SaveTime 2-13
See edge frequencies setting 2-7
Ωs2 (upper stopband edge frequency) Simulink 2-11
See edge frequencies Solver 2-15
ones, outputting 5-325 StopTime 2-15
online help 1-8 tuning 2-9, 5-3
Out block, suppressing output 2-13 with T symbol 5-3
Output check box 2-13 parametric estimation 1-5
output frame periods Parametric Estimation library 5-9
defined 3-16 Partial Unbuffer block 3-27
See also frame periods partial unbuffering 3-25
output frame sizes. See frame sizes passband ripple
output periods. See frame periods analog filter 4-8
output sample periods. See sample periods performance, improving 2-13, 3-14, 3-86
Overlap-Add FFT Filter block 5-331, 5-332 periodograms 5-277
overlap-add method 5-331 periods
overlapping buffers 3-25, 3-50 defined 3-4
causing unintentional rate conversions 3-31 See sample periods and frame periods
Overlap-Save FFT Filter block 5-334, 5-335 Permute Matrix block 5-339
I-12
Index
I-13
Index
I-14
Index
I-15
Index
I-16
Index
I-17
Index
I-18
Index
Z
Zero Pad block 3-25, 3-27, 5-552
Zero-Order Hold block 3-10
zero-padding 3-30, 5-337, 5-552
causing unintentional rate conversions 3-31
zeros
inserting 5-200, 5-207, 5-484
outputting
Counter block 5-105
Discrete Impulse block 5-138
Integer Delay block 5-244
N-Sample Enable block 5-325
Signal From Workspace block 5-388, 5-457
padding with 3-27, 3-31
I-19