Professional Documents
Culture Documents
Simulink Tutorial
Product Version 6.1.1
November 2006
2006 Cadence Design Systems, Inc. All rights reserved.
Printed in the United States of America.
Cadence Design Systems, Inc., 555 River Oaks Parkway, San Jose, CA 95134, USA
Trademarks: Trademarks and service marks of Cadence Design Systems, Inc. (Cadence) contained in this
document are attributed to Cadence with the appropriate symbol. For queries regarding Cadence’s trademarks,
contact the corporate legal department at the address shown above or call 800.862.4522.
All other trademarks are the property of their respective holders.
Restricted Print Permission: This publication is protected by copyright and any unauthorized use of this
publication may violate copyright, trademark, and other laws. Except as specified in this permission statement,
this publication may not be copied, reproduced, modified, published, uploaded, posted, transmitted, or
distributed in any way, without prior written permission from Cadence. This statement grants you permission to
print one (1) hard copy of this publication subject to the following conditions:
1. The publication may be used solely for personal, informational, and noncommercial purposes;
2. The publication may not be modified in any way;
3. Any copy of the publication or portion thereof must include all original copyright, trademark, and other
proprietary notices and this permission statement; and
4. Cadence reserves the right to revoke this authorization at any time, and any such use shall be
discontinued immediately upon written notice from Cadence.
Disclaimer: Information in this publication is subject to change without notice and does not represent a
commitment on the part of Cadence. The information contained herein is the proprietary and confidential
information of Cadence or its licensors, and is supplied subject to, and may be used only by Cadence’s customer
in accordance with, a written agreement between Cadence and its customer. Except as may be explicitly set
forth in such agreement, Cadence does not make, and expressly disclaims, any representations or warranties
as to the completeness, accuracy or usefulness of the information contained in this document. Cadence does
not warrant that use of such information will not infringe any third party rights, nor does Cadence assume any
liability for damages or costs of any kind that may result from use of such information.
Restricted Rights: Use, duplication, or disclosure by the Government is subject to restrictions as set forth in
FAR52.227-14 and DFAR252.227-7013 et seq. or its successor.
Co-Simulation with SpectreRF MATLAB/Simulink Tutorial
Contents
Cosimulation with SpectreRF MATLAB®/Simulink Tutorial . . . 5
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Tutorial 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Preparing the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Validating the Simulink Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Modifying the Design and Setting Up the cosimulation . . . . . . . . . . . . . . . . . . . . . . . 10
For ADE Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
For Users of Standalone SpectreRF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Cosimulation with SpectreRF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Tutorial 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
First Use Mode (for Users of ADE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Viewing the Netlist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Running the Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Second Use Mode (for ADE and Standalone Users) . . . . . . . . . . . . . . . . . . . . . . . . . 31
Q&A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Introduction
The high level system concept is often specified in the early stages of design work. This
process is well supported by both concept engineering and system-level simulation tools
such as MATLAB®/Simulink®.
To run the tutorials described here, Cadence recommends using software versions
MMSIM6.1 USR1 or later, and MATLAB R14 or later, with Simulink® and the signal process
blockset installed.
It takes about an hour to run through the two tutorials described in this document.
Tutorial 1
Tutorial 1 describes cosimulation for the system-level module of a wireless LAN. Figure 1-1
on page 6 shows the system-level schematic. The transmitter blocks encode and modulate
binary random data and send the OFDM signal to a white Gaussian noise channel model.
The receiver blocks demodulate and decode the channel output. Finally, the received bits are
compared with the original bit stream to compute the bit error rate.
The designs for the tutorial are provided in the tutorial database libraries. Assuming that the
standalone simulations work correctly in MATLAB/Simulink and SpectreRF, only three steps
are required to set up the cosimulation:
1. Insert and configure the SpectreRF Engine in the Simulink schematic.
2. Setup the netlist to adopt the SpectreRF and MATLAB cosimulation.
3. Run the cosimulation.
to your directory.
The `cds_root spectre` command in one way to determine where the Spectre
simulator is installed. If you already know the path to the Spectre hierarchy, you can just
substitute it into path given above.
This is the best place to start MATLAB, because the cosimulation modules load
automatically here in accordance with the statements provided in the startup.m file.
4. Add the SpectreRF and MATLAB/Simulink engine install paths to the MATLABPATH
environment variable. You can automate this step by adding the appropriate command
to your .cshrc file. For example, if you are using a C shell, you can add the command
setenv MATLABPATH `cds_root spectre`/tools/spectre/simulink:${MATLABPATH}
simulation again. The scatter diagram is now distorted and after some seconds bit errors
do occur. The final plots from the unmodified testbench look like Figure 1-4 on page 9.
Field Meaning
Number of input pins The number of input pins to the engine block
(0…100). The input to the block is the input signal
from Simulink.
Number of output pins The number of output pins from the engine block
(0…100). The output from the block is the resulting
signal from the SpectreRF simulator.
Frame size The number of samples per frame (any positive
integer or -1; default: -1). Set this value to -1 to inherit
the frame size from the input.
Sample time Sample period of the block, in seconds (default: -1).
The Sample time is the frame period, not the time
between the samples inside the frame. Set this value
to -1 to inherit the sample period of the connected
blocks.
Socket port The number of the service that is identified by TCP/
IP. Normally, the system reverses port numbers less
than 1024, so this value can range from 1024 to
65535 (default: 38520).
Simulation response timeout Maximum time, in seconds, to wait for an answer
from the SpectreRF simulator during simulation.
During simulation, if MATLAB does not receive a
response from Spectre before the timeout period
expires, simulation ends with an error.
Socket mode TCP or UDP. Choose UDP if frame size is less 50.
TCP and UDP are two different translate protocols in
TCP/IP. Without CRC, UDP is usually faster in a good
net environment with small data packages and TCP
is usually better for large data packages.
Spectre command Used to run a Spectre simulation. This parameter
enables a use mode where Spectre is called
internally by the Simulink simulation.
Show engine port labels If checked, the SpectreRF Engine shows the label
information.
To make each signal connection, move the mouse pointer over the module pin. The
pointer changes to a cross. Press the left mouse button, move the cursor to the
destination pin and release the button.
This completes the necessary modifications on the MATLAB side. To continue, you can use
the Simulink schematic that you modified, or you can use the already modified schematic
included in the tutorial database.
This schematic includes an RF transmitter module design with filters, an up-converting mixer,
and an amplifier. To speed-up the simulations, the RF components are modeled in the
complex base-band domain using Verilog-A. You can use the same approach to perform
equivalent behavioral pass-band and transistor-level simulations.
Note: This schematic has two placed pwl vsources in the input. These are used as input to
test the model. For cosimulation, these two sources are overloaded and generate output with
the input data from MATLAB.
1. Start the icms tool from the SpectreRF_simulink_example directory, using the
command
icms &
5. In the Cosimulation Options form, click the Select button located beside Cosimulation
inputs. Switch to the schematic viewer, where you see the following information below
the schematic.
Select source instance as cosimulation inputs. Press Esc when done.
Select the vsources VI and VQ, then press the Esc key.
6. In the Cosimulation Options form, click the Select button beside Cosimulation outputs.
Switch to the schematic viewer, where you see the following information below the
schematic.
Select Net/Terminal as cosimulation outputs. Press Esc when done.
Select the TX_AFE_OUT_BB_I and TX_AFE_OUT_BB_Q nets, then press the Esc key.
The Cosimulation Options form looks like this:
The netlist used in this tutorial is based on the behavioral RF Front-End transmitter model.
The schematic, shown in Figure 1-8 on page 15, can be found in the tutorial1 directory.
1. Edit the netlist file tutorial1/tutorial1.scs.
2. Add a cosim statement in the netlist.
For example,
matlab cosim server="bj2lnx20" port=38525 inputs=["VI:wave" "VQ:wave"]
outputs=[TX_AFE_OUT_BB_I TX_AFE_OUT_BB_Q]
Parameter Meaning
design Refers to the file Simulink associates with the netlist.
design="env_d.mdl"
means the testbench whose file is env_d.mdl.
inputs Input vector to identify the flow from MATLAB to SpectreRF Engine.
The format is
[“instance_name:wave” “instance_name1:wave” …]
where wave, is a key word.
Note: The sequence of instances in square brackets follows the same
one as the SpectreRF Engine port labels. This label information can be
found by double-clicking the SpectreRF Engine and then by
checking the Show engine port labels at the bottom in Function
Block Parameters of the SpectreRF Engine.
Once the inputs are set in the netlist, the sources (such as VI and VQ
in the step 2 example) associated with the inputs are meaningless
and their parameters (such as type=sine freq=2M
fundname="n2" for VQ source) do not affect the simulation.
outputs Output vector from SpectreRF Engine to MATLAB. It can be the net
name or terminal name of interest. Note that if net name is selected,
only voltage is given; if terminal name is set, only current is output.
To get current in an envlp analysis, you must add probes in the
topology.
port The one on the server running MATLAB. Its value should be the same
as the value in the SpectreRF Engine in your current MATLAB design.
server The name of the machine that MATLAB starts. It can be set with the
machine name or with the IP address of that machine. The accepted
form is
server = ”155.110.110.110”
and
server = “bj2lnx20”
server=localhost means that Spectre and MATLAB use the same
machine.
The cosimulation begins. The MATLAB desktop issues a message similar to the following
when simulation ends.
block 'modified/SpectreRF Engine': (COSIM_OK) Simulation finished
Bit errors do not occur with these settings but the input spectrum and output spectrum
are different because the RF transmitter chain is non-ideal. The results are captured
below.
Tutorial 2
Tutorial 2 demonstrates Simulink, SpectreRF cosimulation while the SpectreRF simulator
runs an envlp analysis. The MATLAB schematic is as in Figure 1-13 on page 22, in which the
Sine Wave block outputs a sine wave into two chains.
The top chain contains Buffer, SpectreRF Engine, and Unbuffer. The bottom chain
contains only Buffer1 and Unbuffer1 and provides the reference for the top chain. The
results are displayed in Scope.
In this tutorial, the SpectreRF Engine performs the mixing function. Its schematic is shown
in Figure 1-14 on page 23.
The low frequency signal in MATLAB is fed into the SpectreRF modulating circuit, mixed there
with a high frequency signal, and then output back to MATLAB. With the envlp analysis, the
envelope is obtained at the terminal of interest from MATLAB.
a. First Use Mode: Manually running Spectre with ADE and calling MATLAB from ADE.
b. Second Use Mode: Manually running Simulink and activating Spectre through
Simulink.
Value Behavior
now ADE launches a MATLAB session and opens a MATLAB
desktop that is no different than it would be if you launched it
manually. When you use the now value, you must start the
simulation in the Simulink design before starting the
SpectreRF simulation.
Using the now value is a good way to test whether ADE can
start MATLAB and open the design successfully.
before Simulation ADE launches an internal MATLAB session. and no
MATLAB desktop appears. ADE opens the specified
MATLAB design and initiates the MATLAB simulation before
Spectre simulation starts. ADE starts MATLAB once but
cannot start it again before you close the first session.
Cadence suggests using the now value as a test before you
run with the before Simulation value.
The now and before Simulation values share one log file,
which can be opened by choosing Setup — Matlab/
Simulink — Log file. You can use the log file to monitor the
simulation when no MATLAB desktop is visible.
no The MATLAB start command, MATLAB startup
directory, and MATLAB design name fields become
active. When you use the no value, you must start the
simulation in the Simulink design before starting the
SpectreRF simulation.
5. In the Start MATLAB field of the Cosimulation Options form, select now.
The MATLAB start command, MATLAB startup directory, and MATLAB design
name fields become active.
6. Type env_d.mdl in the MATLAB design name field.
After these steps, the Cosimulation Options form looks like this.
11. Set the Sample time to 2.5e-4, which is the sample time of Sine Wave * 50 * frame size.
The Sample time can also be set to -1, if you are uncertain about the appropriate time to
use.
12. Set Socket Port to the value you set in the Cosimulation Options form.
13. Leave the Spectre Command field empty. The use of this field is explained later.
3. In the Cosimulation Options form, click the Select beside Cosimulation outputs.
4. On the schematic, select net OUT, then press the Esc key to finish.
The OUT entry appears in the Cosimulation outputs field.
5. Click Fit Expression for envlp output.
The Fit Expression form appears.
6. Select OUT, change harmonic to 1, and change type to mag as below.
After these steps, the Choosing Analyses form looks like this.
ADE starts an internal MATLAB and no MATLAB desktop appears. ADE controls the
MATLAB simulation automatically, first opening the design and then simulating it.
Spectre resumes running when MATLAB finishes initialization.
2. When the simulation ends, click the Scope block to view the result.
4. Deleting the Buffer1 and Unbuffer1 blocks results in the MATLAB schematic shown
in Figure 20.
The Function Block Parameters: SpectreRF Engine window looks something like this:
■ If, for testing, you need to be able to modify both the system-level Simulink design and
the analog circuit, the use mode described in Tutorial 1 is appropriate.
■ If you are an analog designer who needs to validate a circuit with system-level design
input and output, the first use mode in Tutorial 2 is a good choice.
■ If you are a system level designer, after specifying the Spectre command, you can use
the SpectreRF engine just like another block in Simulink.
Q&A
Q: Why does MATLAB sometimes coredump when I log out from MATLAB?
A: This is caused by the communication blockset in MATLAB 704. This problem is fixed
in version 2006a.
Q: How many SpectreRF Engines can I use in a Simulink design?
A: There is not limit, but if you are using more than one SpectreRF Engine block you
should fix the Spectre command for each of the blocks. Because each SpectreRF Engine
connects to an analog circuit, it would be difficult, in this situation, to launch Spectre
manually for each block in the right order.
Q: Why do I always get zero output when I use envlp for cosimulation?
A: For envlp, harmonic information is most useful. If you do not assign an output special
harmonic, the output could be 0.
Q: Why doesn’t MATLAB launch automatically when I use cosimulation and set start
MATLAB to before Simulation? Instead, I get the same result I get when I run with the
pwl source.
A: It could be that Enabled, on the bottom of the Cosimulation Options form, is not
turned on.
Q: What happens if I use the first use mode of Tutorial 2 but using a MATLAB design that
has a fixed Spectre command line?
A: MATLAB runs with the Spectre it launches, but the Spectre launched by ADE reports
an error saying that it cannot connect to the cosimulation block.