You are on page 1of 34

Co-Simulation with SpectreRF MATLAB/

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

November 2006 3 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

November 2006 4 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

Cosimulation with SpectreRF MATLAB®/


Simulink Tutorial

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

Cosimulation using SpectreRF and MATLAB/Simulink combines the best of system-level


simulation with lower-level analog and RF simulation. Simulink provides large libraries of DSP
algorithms for generating complicated signals and post processing while SpectreRF supports
transient and envelope analysis of common RF and communication circuits, such as mixers,
oscillators, sample and holds, and switched capacitor filters at both the transistor and
behavioral levels.

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.

November 2006 5 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-1 End-To-End System-Level Simulation with Simulink

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.

The steps are described in detail in the following sections.

Preparing the Environment


1. Copy the file
`cds_root spectre`/tools/spectre/examples/SpectreRF_workshop/
SpectreRF_simulink_example.tar.Z

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.

November 2006 6 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

2. Unpack the file with


zcat SpectreRF_simulink_example.tar.Z | tar xvf -

3. In the working directory of the cosimulation package, type


cd SpectreRF_simulink_example

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}

Validating the Simulink Design


1. Start MATLAB, by typing
matlab &

The spectrerf_demo library opens.

Figure 1-2 Simulink Library for cosimulation


2. This library contains the SpectreRF engine block module for this tutorial (distinguished
by the Cadence logo and labeled SpectreRF Engine). You can insert the coupler module
in any Simulink design by dragging and dropping it from this library.
3. Double-click the first green box labeled LAN 802.11 Tutorial1.

November 2006 7 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

The tutorial1 library opens.

Figure 1-3 Library Including Modified and Unmodified Models


4. Double-click the unmodified block.
The end-to-end design for a wireless LAN transmission system opens (see Figure 1-1
on page 6). This design contains the main DSP algorithms of a wireless LAN 802.11a
physical layer for the transmitter and the receiver chains. It generates a standard-
compliant 802.11a signal and implements the related post-processing algorithms.
5. In the window displaying the LAN transmission system schematic of Figure 1-1 on
page 6, click Simulation — Start.
A spectrum scope and a scatter diagram come up. The minor deviations in the scatter
diagram originate from the noisy channel. Look at the bit error rate (BER) display. The
BER is zero.
6. (Optional) Double-click the AWGN block and increase the noise by changing the
parameter signal to noise ratio SNR (dB) to 13. Click Simulation — Start to start the

November 2006 8 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-4 Result from Unmodified Testbench

November 2006 9 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

Modifying the Design and Setting Up the cosimulation


The following steps set up the cosimulation. There is a complete setup in Tutorial demo that
can be used as a reference.
1. Drag and drop the SpectreRF Engine block (the block that contains the Cadence logo,
located on top of the green boxes) into the testbench and place the block at the top right
corner.
This step inserts the analog transmitter RF-front end within the system testbench
between the OFDM Transmitter and AWGN channel.
2. Double-click the SpectreRF Engine block.
The Function Block Parameters window opens.

Figure 1-5 Function Block Parameters Window


The fields have the following meanings:

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.

November 2006 10 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

3. Set the Frame mode field to -1 to use an inherited frame size.


This Simulink testbench uses framed signals.
4. Set the parameter Socket port to any value from 1024 to 65535.
5. Click OK.
The form closes and the SpectreRF Engine block is updated with the correct number of
pins.

November 2006 11 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

6. In the testbench window, select Format — Port/Signal Displays — Signal


Dimensions.
The signal dimension display is switched on so you can see details of the framed signals
used. In this case the frame size between OFDM Transmitter with oversampling
and AWGN is 320.
7. Select View — Simulink library to display the library browser. Double-click Math
Operations.
The library appears. The tutorial uses complex valued signals. Before the signal is
transmitted to SpectreRF the complex signals must be split into their real and imaginary
parts. Simulink provides a converter for this purpose. The desired converters are located
at the bottom right corner in this library.
8. Drag and drop the Complex to Real-Imag block before the SpectreRF Engine
block and drag and drop the Real-Imag to Complex block after the SpectreRF
Engine block in the schematic.
9. Insert an ideal gain block at the output of the coupler block. The gain block is in the Math
Operations library.
Because the analog/RF subsystem changes the signal level, the gain block is required
to adapt the signal level to the properties of the digital base-band receiver.
10. Double-click the placed Gain block and set the Gain to 0.04.
11. Delete the wire between the OFDM Transmitter and the AWGN channel, by right clicking
on the wire and choosing cut.
12. Connect the signals as shown in Figure 1-6 on page 13.

November 2006 12 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-6 Testbench with Additional Modules for cosimulation


The Simulink model is ready for cosimulation. All other information about frame size and
sampling time is detected automatically within the Simulink model.
13. Choose Simulation — Configuration Parameters.
The Configuration Parameters form opens.
14. In the Stop time field, set the stop time of the Simulink simulation to 1000e-6.

November 2006 13 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

The Configuration Parameters form looks like this:

Figure 1-7 Simulink Simulation Settings


15. Click OK.
16. Save the modified design by choosing file — save as.

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.

November 2006 14 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

For ADE Users


This section describes how to set up a cosimulation using the Analog Design Environment
(ADE). If you are using the standalone version of SpectreRF, skip this section and go on to
“For Users of Standalone SpectreRF” on page 17.

Figure 1-8 Baseband Model for RF Front-End Transmitter

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 &

The version of icms must be release IC5.1.4.1 USR4 ISR62 or later.


2. Open the schematic view of the cell COSIM/tutorial1.
3. Open the Virtuoso Analog Design Environment from the schematic editor by choosing
Tools — Analog Environment.
4. Choose Setup — Matlab/Simulink — Setting.
The Cosimulation Options form appears.

November 2006 15 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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:

Figure 1-9 Cosimulation Options Form for Tutorial 1


7. Ensure that the value of Cosimulation socket port is the same as the port value of the
SpectreRF Engine block defined in the previous section.
8. In the Cosimulation Options form, turn on Enabled. Make sure that Start MATLAB is
set to no. (The usage of the ADDITIONAL SETTING values is described in the next
section of the tutorial.)
9. Click OK to close the form.

November 2006 16 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

10. Use the Choosing Analyses form to set up a tran analysis.


The Stop Time can be any value. The SpectreRF simulator synchronizes the stop time
with Simulink.
The Choosing Analyses window looks like this:

Figure 1-10 Setup for the tran Analysis


11. Create a netlist and make sure the simulinkCosim cosim statement appears in it.

For Users of Standalone SpectreRF


If you already generated a netlist using ADE, skip this section and go on to “Cosimulation with
SpectreRF” on page 19.

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]

November 2006 17 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

The parameters for the cosim statement are described below:

Table 1-1 Parameters of the cosim Statement

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.

November 2006 18 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

Table 1-1 Parameters of the cosim Statement, continued


silent Tells MATLAB whether to open the window during simulation. If
silent=yes, the testbench window is opened.
timeout The period of time MATLAB spends waiting for a response from the
Spectre simulator.
timeout=60
stops MATLAB if it does not receive any response.

After the above steps, the netlist is ready for simulation.

Cosimulation with SpectreRF


1. Open the testbench.
You can use the one you just saved or the modified one that is provided in the tutorial1
library.
2. In the MATLAB design window, click Simulation, click Start.
The MATLAB desktop issues the following message.
block 'modified/SpectreRF Engine': (COSIM_OK) Waiting for incoming connection
on port 38520, timeout: 60 sec ...

Then quickly do step 3.


Note: The time interval between step 2 and step 3 must be within the Simulation
response timeout defined as Function Block Parameters of the SpectreRF Engine
(by double-clicking the SpectreRF Engine).
3. In the ADE window, click Netlist and Run or enter the command
spectre tutorial1/tutorial1.scs

The cosimulation begins. The MATLAB desktop issues a message similar to the following
when simulation ends.
block 'modified/SpectreRF Engine': (COSIM_OK) Simulation finished

November 2006 19 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

The result plots are generated.

Figure 1-11 Simulation Results as Spectral Plots


4. After the cosimulation finishes, review the MATLAB/Simulink output (see Figure 1-11 on
page 20 and Figure 1-12 on page 21).

November 2006 20 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-12 Constellation Diagram PA_CP = 24


5. Close the MATLAB desktop and exit from MATLAB.
Tutorial 1 shows the basic steps involved in setting up and running a SpectreRF, MATLAB
cosimulation. In this tutorial, you start two applications separately and use a tran
analyses to solve the circuit. The next tutorial illustrates additional use modes and shows
how to use an envlp analysis.

November 2006 21 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-13 Testbench Used for Envlp in cosimulation

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.

November 2006 22 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

In this tutorial, the SpectreRF Engine performs the mixing function. Its schematic is shown
in Figure 1-14 on page 23.

Figure 1-14 Mixing Circuit for Modulating Signal

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.

Tutorial 2 illustrates the following use mode:

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.

Each of these modes is described in more detail in the following sections.

November 2006 23 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

First Use Mode (for Users of ADE)


If you are using SpectreRF standalone, skip this section and go to “Second Use Mode (for
ADE and Standalone Users)” on page 31.
1. Open a new ADE session from the CIW by choosing Tools — Analog Environment —
Simulations.
2. In the new ADE window, choose Setup — Design, choose Library Name COSIM, Cell
Name tutorial2, open mode edit, and then click OK.
3. Choose Setup — Matlab/Simulink — Setting to bring up the Cosimulation Options
form.
4. Examine the possible values for the Start MATLAB field.

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.

November 2006 24 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-15 Setup of Cosimulation Options in Tutorial 2


7. Click the Start button beside now. A new MATLAB application starts and helps you open
design env_d, as shown in Figure 1-13 on page 22.
8. Click Buffer.
You see that the frame size is 50.
9. Click Sine Wave.
You see the period is 1000 and Sample time is 0.5e-5.
10. Double-click the SpectreRF Engine and set the parameters as shown in Figure 1-16
on page 26.

November 2006 25 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-16 Setup of SpectreRF Engine in tutorial 2


14. Choose File — Save to save the env_d design. Then exit from the MATLAB that was
opened by ADE.
15. In the Cosimulation Options form, set Start MATLAB to before Simulation.

Viewing the Netlist


1. In the Cosimulation Options form, click the Select beside Cosimulation inputs.
The env schematic opens.
2. On the schematic, select vsource Vi, then press the Esc key to finish.

November 2006 26 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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.

Figure 1-17 Fit Expression for envlp analysis output


7. Click Change, then click OK to close the form.
8. In the Cosimulation Options form, turn on Enabled, make sure the other settings are the
same as those in Figure 1-15 on page 25, then click OK to close the form.
9. In the Schematic Editor window, set the frequency of the vsource Vii to 1M, then choose
Design — Check and Save.
10. In the Analog Design Environment window, use the Choosing Analyses form to add an
envlp analysis. To match the fast frequency of 1MHz set for Vii in the schematic, set
Fund Frequency to 1M. Set the Number of harmonics to 5. That value should be
larger then 1 because the 1st harmonic is used in the cosimulation.

November 2006 27 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

After these steps, the Choosing Analyses form looks like this.

Figure 1-18 envlp Analysis Setting in the Choosing Analyses Form


11. Click OK to close the Choosing Analyses form, then generate a netlist for checking.

Running the Example


1. In the Analog Design Environment window, click Netlist and Run.
In an earlier step, you set start MATLAB to before Simulation, so the following
information appears in the CIW.
Virtuoso® Analog Design Environment: Opening MATLAB® (this may take a while -
please be patient)...

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.

November 2006 28 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

2. When the simulation ends, click the Scope block to view the result.

Figure 1-19 Result of Harmonic 1 at out


The red curve is the reference and the yellow curve is from the SpectreRF Engine. The
yellow curve is always greater than zero because it is amplitude output. This can be
clearly seen when the buffers are not used in the bottom, reference chain.
3. Use the Direct Plot form to check the harmonic time output of node OUT. You find that the
waveform of the first harmonic output is the same as the one displayed by the MATLAB
scope.

November 2006 29 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

4. Deleting the Buffer1 and Unbuffer1 blocks results in the MATLAB schematic shown
in Figure 20.

Figure 1-20 Figure 20 Schematic without Buffer1 and Unbuffer1


This simplified circuit produces the plots shown in Figure 16. Note that Buffer and
Unbuffer introduce delay in the circuit. The wavescan plot conforms to the MATLAB
plot, as shown in the two screen captures included in Figure 1-21 on page 31. (The first
plot is from MATLAB; the second plot is from wavescan.)

November 2006 30 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

Figure 1-21 Result of Harmonic 1 at out without Delay in Reference Chain

Second Use Mode (for ADE and Standalone Users)


1. If you are using ADE, continue with the previous ADE session, choose Simulation —
Netlist — Display, save the current netlist with the name tutorial2.scs, then exit
from icms.
If you are using standalone SpectreRF, edit the file tutorial2/tutorial2.scs
under the SpectreRF_simulink_example directory to make sure the matlab
cosim statement includes the parameters:
server="localhost" port=38525 inputs=["vi:wave" ] outputs=["harmonic(out, 1)"]

The outputs=["harmonic(out, 1)"] parameter means the output is the 1st


harmonic of the out voltage.
2. Start MATLAB with the command matlab & under the
SpectreRF_simulink_example directory.
3. Open design env_d by double-clicking the green box labeled Tutorial2 in the
spectrerf_demo library. (That is the design used in the first use mode.)
4. Double-click SpectreRF Engine.

November 2006 31 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

The Function Block Parameters: SpectreRF Engine form appears.


5. Type the following into the Spectre Command field.
spectre tutorial2.scs =log spectre.out

Or, if you are using standalone SpectreRF, type


spectre tutorial2/tutorial2.scs =log spectre.out

The Function Block Parameters: SpectreRF Engine window looks something like this:

Figure 1-22 SpectreRF Engine parameters in second use mode.


6. Click OK to close the Function Block Parameters: SpectreRF Engine form.
7. Choose Simulation — Start.
The following information appears.
block 'env_d/SpectreRF Engine': (COSIM_OK) Waiting for incoming connection on
port 38525, timeout: 60 sec ...
block 'env_d/SpectreRF Engine': (COSIM_OK) Launch Spectre with commad 'spectre
tutorial2.scs =log spectre.out'”

The simulation runs to completion.


8. The scope output is the same as that produced by the first use mode.

These tutorials together illustrate three use modes.

November 2006 32 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

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

November 2006 33 Product Version 6.1.1


Co-Simulation with SpectreRF MATLAB/Simulink Tutorial

November 2006 34 Product Version 6.1.1

You might also like