Sei sulla pagina 1di 12

PRACTICE TO SIMULINK

Introduction
Simulink (Simulation and Link) is an extension of MATLAB by Mathworks Inc. It works
with MATLAB to offer modeling, simulating, and analyzing of dynamical systems under a
graphical user interface (GUI) environment.

Getting Started
Execute MATLAB and type “simulink” in the command window, or click the icon in the
tool bar.

The “Simulink Library Browser” window will pop up.


Create a new model

For searching blockset group / block

Descriptions for the selected

Library

Blockset groups (grey) / blocks (white)

Click the “+” to see content of


the blockset group
Start your own model
Click the “new file icon” in the toolbar or press CTRL+N to start a model. A new window
will appear and you can drag the blocks from the library into this window. The
constructed model will be simulated.

Example 1:
Simulate the equation A(t)sin(2πfc t), for 0 < t < 10, unit: second
where A(t) = t for t > 0, fc = 50Hz

Step 1: Find the suitable sources and tune the parameters:

a) Source 1:
(i) Descriptions:
Sine Wave: Output a sine wave where the sine type determines the computational
technique used. The parameters in the two types are related through:
Samples per period = 2*pi / (Frequency * Sample time)
Number of offset samples = Phase * Samples per period / (2*pi)
Use the sample-based sine type if numerical problems due to running for large
times (e.g. overflow in absolute time) occur.

(ii) Where to get it?


a) Simulink  Sources Sine Wave
b) 
O r type “
sine”in the search window to search the suitable block

Drag this icon into a model to insert


the ‘Sine Wave’ block
(iii) T
une the parameters in the block:
a) Drag the block “Sine Wave” from the library to the model window
b) 
Double click the block and “ Block Parameters: Sine Wave”will pop up,
click “help” for detailed descriptions.
c) 
If you wish to simulate a continuous time signal (analog), choose “ Time based” ,
otherwise, choose “Sample based”.
d) 
The output signal will be
output(t) = 
Amplitude x sin(radian_frequency x t+ Phase)
e) 
Now use amplitude = 1, radian frequency = 50 , phase shift = 0, sample time = 0

Output waveform:


(b) Source 2: function A(t) = t
 Use the function “ramp”
 Where to get it?
 Simulink Sources  Ramp
 The output signal will be
Output(t)=initial_output + slope x (t-start_time)
 Parameters:
  Slope of the function = 1
  Start time = 0 sec
  Initial output = 0

Step 2: Multiply the output from the two sources

(i) 
Multiplication: can use either “
dot product”or “
product” .
  Where to get it?
 Simulink Math Operations  product / dot product
 Differences: “product” allow more than 2 inputs

 
Connect the source blocks and the block “ dot product” :
 Drag the “dot product” to the model
 Move the mouse near the output port of the source,
and mouse becomes “+”
 Click at the output port and release until the mouse
is near the input port
 If the blocks are not connected, release until the mouse
is near the input port

Step 3: View the final output

Use “scope” to view the final output signal


  Where to get it?
 Simulink Sinks Scope
 Click the icon “Parameters” to change settings of
the scope
 Number of axes: number of signals can be plotted
  Sampling: sampling rate, choose “ sample time”
and set it to a very small number
e.g. 1e-5 (10-5second) for higher resolution
nclick “Limit data points to last” such
 U
that the whole signal will be plotted

Step 4: Start the simulation

 Change the parameters for Simulation by


choosing “Simulation”  “Simulation
parameters” from the menu bar, of press
CTRL+E
 
Change the simulation time according to the
specification
 
press CTRL+T to start the simulation, or click it
from the tool bar / menu bar.
 
When simulation starts, the
progress will be shown at the
bottom of the window.
 
Simulation output:
 The first graph shows the signal A(t)=t
  The second graph shows sin(2πx 50t)
 The third graph shows t sin(2πx 50t )
 
To zoom the scale of x-axis y-axis,
right click on the graph.

Right click

Advanced Examples

Example 1: Integrator;

(a) Calculate the average value of the signal within specified period.
(b) Set the parameter value for each blocks refer the output graph.

2 sin(pi t)

Pulse, amp=1, T=1

Integration Result (Rise when pulse is rising)


Example 2;

Sample and hold, zero-order hold: convert continuous time signal into discrete time. Set
the parameter value for each blocks refer the output graph and explain briefly different
output between scope and scope 1

2 sin(0.25pi t) Result Sample and hold (Rise edge triggering, T=02.5)

Pulse, amp=1, T=0.25 Result of zero order hold (T= 0.25)

Single after sample and hold (Rise edge triggering) 2 sin (pi/4 0.25n).[Discrete sine wave, sampling period=0.25second]
Example 3;

Design the 3 Bit PCM System above with the parameter given by instructor.

Pulse-code modulation (PCM) is a digital representation of an analog signal where the


magnitude of the signal is sampled regularly at uniform intervals, then quantized to a
series of symbols in a numeric (usually binary) code.

(i) SCALAR QUANTIZER

The Scalar Quantizer Encoder block maps each input value to a quantization region by
comparing the input value to the quantizer boundary points defined in the Boundary
points parameter. The block outputs then zero-based index of the associated region.
You can select how you want to enter the Boundary points using the Source of quantizer
parameters. When you select Specify via dialog, type the boundary points into the block
parameters dialog box. When you select Input port, port B appears on the block. The
block uses the input to port B as the Boundary points parameter. Use the Boundary
points parameter to specify the boundary points for your quantizer. These values are
used to break up the set of input numbers into regions. Each region is specified by an
index number. Let N be the number of quantization regions. When the codebook is
defined as [c1 c2 c3 ... cN], and the Boundary points parameter is defined as [p0 p1 p2
p3 ... pN], then p0<c1<p1<c2 ... p(N-1)<cN<pN for a regular quantizer. When your
quantizer is bounded, from the Partitioning list, select Bounded. You need to specify N+1
boundary points, or [p0 p1 p2 p3 ... pN]. When your quantizer is unbounded, from the
Partitioning list, select Unbounded. You need to specify N-1 boundary points, or[p1 p2
p3 ... p(N-1)]; the block sets p0 equal to -inf and pN equal to inf. The block uses the
Partitioning parameter to interpret the boundary points you enter. For instance, to
create a bounded quantizer, from the Partitioning list, select Bounded and enter the
following boundary points:[0 0.5 3.7 5.8 6.0 11] The block assigns any input values
between 0 and 0.5 to index 0, input values between 0.5 and 3.7 to index 1, and so on.
The block assigns any values that are less than 0 to index 0, the lowest index value. The
block assigns any values that are greater than 11 to index 4, the highest index value. To
create an unbounded quantizer, from the Partitioning list, select Unbounded and enter
the following boundary points:[0 0.5 3.7 5.8 6.0 11] The block assigns any input values
between 0 and 0.5 to index 1, input values between 0.5 and 3.7 to index 2, and so on.
The block assigns any input values less than 0 to index 0 and any values greater than
11 to index 6. (For details go to MATLAB HELP)

(ii) Integer to Bit Converter

The Integer to Bit Converter block maps each integer in the input vector to a group of
bits in the output vector. If M is the Number of bits per integer parameter, then the input
integers must be between 0 and 2M-1. The block maps each integer to a group of M bits,
using the first bit as the most significant bit. As a result, the output vector length is M
times the input vector length. (See MATLAB Help for details)

(iii) Bit to Integer Converter

The Bit to Integer Converter block maps groups of bits in the input vector to integers in
the output vector. If M is the Number of bits per integer parameter, then the block maps
each group of M bits to an integer between 0 and 2M-1. As a result, the output vector
length is 1/M times the input vector length.If the input is sample-based input, then it must
be a vector whose length equals the Number of bits per integer parameter. If the input is
frame-based, then it must be a column vector whose length is an integer multiple of
number of bits per integer. The block interprets the first bit in each group as the most
significant bit. (See MATLAB Help for details)
Output result ;

From “Scope” shown that a PULSE-CODE MODULATION (pcm) a process in which


analog signals is converted to digital form. The analog signal is represented by a series
of pulses and non-pulses (1 or 0 respectively). It’s refers to a system in which the
standard values of a QUANTIZED WAVE are indicated by a series of coded pulses.
When these pulses are decoded, they indicate the standard values of the original
quantized wave. These codes may be binary, in which the symbol for each quantized
element will consist of pulses and spaces: ternary, where the code for each element
consists of any one of three distinct kinds of values (such as positive pulses, negative
pulses, and spaces); or n-ary, in which the code for each element consists of nay
number (n) of distinct values.
PRACTICE EXERCISE
Exercise 1

The signals we use in the real world, such as our voices, are called "analog" signals. To
process these signals in computers, we need to convert the signals to "digital" form.
While an analog signal is continuous in both time and amplitude, a digital signal is
discrete in both time and amplitude. To convert a signal from continuous time to discrete
time, a process called sampling is used. The value of the signal is measured at certain
intervals in time. Each measurement is referred to as a sample.

Design the sampling prosess above with the parameter given by instructor. Set the
parameter value for each blocks and explain briefly the output waveform scope and
scope 1.
Exercise 2

1) Design a 50% Natural Sampling of a Sinusoid system where the signal


generator generate the sinewave and multiplication with the 125Hz pulse
generator at 50% duty cycle. Drag the “Scope” block to view the output
waveform.
2) Design a flattop system, where the simulation uses a 100 Hz sampling rate and
an input sinusoid of increasing frequency (a chirp sinusoid). The frequency
increases linearly from 0 Hz to 200 Hz. The scope image is a snap-shot at a 5
Hz sinusoid. The upsample block can change the duty cycle of the samples,
thus changing the spectral shaping. Try increasing the upsample value (from 1 to
2 and then 4) to see the effect. What do you observe on the SCOPE when the
upsampling factor is 4? Explain briefly the output waveform

Exercise 3

1) Design “DQPSK Signal Constellation Points and Transition”


 To build the model, gather and configure these blocks:
a) Random Integer Generator, in Data Sources sublibrary of the
Communication Sources Library.
 Set M-ary number to 4.
 Set Initial seed to any positive integer scalar, preferable the
output of the randseed function.
 Set Sample time to .01
b) DQPSK Modulator Baseband, in the PM sublibrary of the Digital
Baseband sublibrary of Modulation
c) Complex to Real-Imag, in the Simulink Math Operations Library.
d) XY Graph, in the Simulink Sinks Library.
 Connnect all the blocks and running the model.
 Then, the result illustrate as π/4-DQPSK modulation.
 Next, change the parameter in the DQPSK Modulator Baseband Block to
π/8. Run the model again and sketch how the plot changes between π/4
and π/8.

Potrebbero piacerti anche