Professional Documents
Culture Documents
Simulink Lab1
Simulink Lab1
Objectives
After completing this lab, you will be able to:
Use the Simulink tool to create a simple design
Create a subsystem and simulate
Describe the effect of the sampling period
Procedure
NOTE: Toolwire is the default platform for running labs. Use R:\ for all directory
references.
This lab comprises four primary steps. In Step 1, you are introduced to the Simulink environment.
In Step 2, you will analyze the effect of the sampling period. In Step 3, you will create a simple
filter design using a Simulink blockset. Finally, in Step 4, you will create a subsystem of the
design and perform simulation.
For each procedure within a primary step, there are general instructions (indicated by the
symbol). These general instructions only provide a broad outline for performing the procedure.
Below these general instructions, you will find accompanying step-by-step directions and
illustrated figures that provide more detail for performing the procedure. If you feel confident
about completing a procedure, you can skip the step-by-step directions and move on to the next
general instruction.
Note: When you are not using Toolwire to perform this lab, all software programs, files, and
projects will be located on the C:\ drive instead of R:\.
www.xilinx.com
1-877-XLX-CLAS
4b-3
Note: If you are unable to complete the lab at this time, you can download the original lab files for
this module from the Xilinx FTP site at
ftp://ftp.xilinx.com/pub/documentation/education/dsp11000-82-rev1-xlnx_lab_files.zip. These are
the original lab files and do not contain any work you may have previously completed.
Introduction to Simulink
Step 1
For each procedure within a primary step, there are general instructions (indicated by
the
symbol). These general instructions only provide a broad outline for
performing the procedure. Below these general instructions, you will find
accompanying step-by-step directions and illustrated figures that provide more detail
for performing the procedure. If you feel confident about completing a procedure,
you can skip the step-by-step directions and move on to the next general instruction.
General Flow for this Lab:
Step 1:
Introduction
to
Simulink
Step 2:
Analyzing
Sampling
Period Effect
Step 3:
Creating a
Simple Filter
Design
Step 4:
Creating a
Subsystem
Become familiar with the MATLAB and Simulink environments (software tools
from The MathWorks suite). Create a blank worksheet, add a Sine Wave source
element, add a Scope sink element, and wire the two, as shown in Figure 4b-1.
www.xilinx.com
1-877-XLX-CLAS
4b-4
Select Start Programs MATLAB 7.1 MATLAB 7.1 or double-click the MATLAB
shortcut on the desktop if available (Figure 4b-2)
DSP Blockset
Xilinx Blockset
www.xilinx.com
1-877-XLX-CLAS
4b-5
www.xilinx.com
1-877-XLX-CLAS
4b-6
From the Simulink Browser, select Simulink Sinks, add the Scope block, and draw a wire
from the Sine Wave to the Scope block. An automatic block connection tip appears (Figure
4b-7)
If you are performing this task for the first time, select the Do not show this message again
option and click Close
Note: To draw a wire, move the cursor to the source output port (the cursor will become a
cross-hair). Click and drag your mouse to an input port of destination. Alternatively, you can
select a source block by clicking once on that block, moving the cursor over to the destination
block, pressing Ctrl, and clicking on the destination port. With this method, the first available
www.xilinx.com
1-877-XLX-CLAS
4b-7
output port of the source block will be connected to the first available input port of the
destination block.
Assign a 2*pi*(1/150) frequency to the Sine Wave element and show port data
types. Change the stop time of the simulation to 150 and set the Solver options as
shown in Figure 4b-8.
www.xilinx.com
1-877-XLX-CLAS
4b-8
Type: Fixed-step
Setting these parameters allows your simulation to run for 150 time units.
www.xilinx.com
1-877-XLX-CLAS
4b-9
www.xilinx.com
1-877-XLX-CLAS
4b-10
Step 2
Step 2:
Analyzing
Sampling
Period Effect
Step 3:
Creating a
Simple Filter
Design
Step 4:
Creating a
Subsystem
Run the simulation at a slower sampling period (sample period of 5) of the sine
wave source and analyze the sampling period effect. Then change the stop time to
500, run the simulation, and observe the output. Change the stop time back to 150.
Double-click the Sine Wave block to open its parameter form
Change the sample period of the Sine Wave source to 5, click OK, and run the simulation
Note: As the sample period is increased (fewer times sampled), the quantization error is
increased (Figure 4b-15).
www.xilinx.com
1-877-XLX-CLAS
4b-11
Type 500 in the project sheet toolbar window and press Enter to change the simulation stop
time (Figure 4b-16)
Step 3
Step 2:
Analyzing
Sampling
Period Effect
Step 3:
Creating a
Simple Filter
Design
Step 4:
Creating a
Subsystem
www.xilinx.com
1-877-XLX-CLAS
4b-12
www.xilinx.com
1-877-XLX-CLAS
4b-13
Creating a Subsystem
Step 4
Step 2:
Analyzing
Sampling
Period Effect
Step 3:
Creating a
Simple Filter
Design
Step 4:
Creating a
Subsystem
Select all the blocks between the source and the sink and create a subsystem.
Name the subsystem Filter. Run the simulation and verify that the output is still
same. Save the model as lab1.mdl in the current working directory
(R:\training\dsp_sysgen\labs\lab1). Exit MATLAB.
Click in a white space and create a rectangle enclosing all relevant blocks and connections to
select all the blocks between the source and sink
www.xilinx.com
1-877-XLX-CLAS
4b-14
www.xilinx.com
1-877-XLX-CLAS
4b-15
Conclusion
In this lab, you learned the basic design flow involved in Simulink using Simulink blockset. You
observed the effect of a sampling period. You simulated the design using the Simulink simulator
and observed the output using the Scope block. Finally, you also created a subsystem.
www.xilinx.com
1-877-XLX-CLAS
4b-16