0% found this document useful (0 votes)
126 views18 pages

PLL Implementation With Simlink and Matlab: Project 2 ECE283 Fall 2004

This document discusses using Simulink to implement a phase-locked loop (PLL) circuit. It provides an overview of Simulink's graphical user interface and libraries. It then describes how to build models using blocks, run simulations, view outputs, and create subsystems. The document explains using S-functions to implement user-defined blocks and provides an example S-function code. Finally, it outlines considerations for simulating a PLL circuit in Simulink.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views18 pages

PLL Implementation With Simlink and Matlab: Project 2 ECE283 Fall 2004

This document discusses using Simulink to implement a phase-locked loop (PLL) circuit. It provides an overview of Simulink's graphical user interface and libraries. It then describes how to build models using blocks, run simulations, view outputs, and create subsystems. The document explains using S-functions to implement user-defined blocks and provides an example S-function code. Finally, it outlines considerations for simulating a PLL circuit in Simulink.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

PLL Implementation with

Simlink and Matlab


Project 2
ECE283
Fall 2004
Simulink in MATLAB
• Graphic user interface
• Continuous, discrete, and
mixed mode
• Integration with MATLAB
• Fast prototyping
• User-defined functions
• How to run it
– >>simulink
Simulink main screen – Or click simulink icon
Graphic User Interface
• Make a new model window
• Expand library
• Drag and drop
• Connect blocks
• Simulate
• Visualize
• Tuning

Simulink built-in library


Make a model
• New model
• Open library
• Drag blocks
• Connect
• Source and sink
• Example:AmModEx.mdl

Amplitude modulation
Simulation
• Tune
– Simulation time
– Relative tolerance
– Refine factor
– Etc
• Simulate
• Example:AmModEx.mdl

Simulation parameters
Visualization
• Double click scope
• Options on signal source
and sink
– External files
– Workspace variables
• Example:AmModEx.mdl

Simulation output scope


Subsystem
• Subsystem for modular
programming
• How to make it
– Subsystem library
– Subsystem conversion
Ports and subsystem library • Example:AmModEx.mdl

Triggered subsystem
Getting Help
• Need help?
– MATLAB and Simulink help
– Mathworks user community
– Mathwork technical support

Simulink help screen


PLL Implementation
• Sampler
• Voltage controlled clock
• Voltage controlled
oscillator
• Feedback loop

Decision-directed phase-locked loop


Sampler
• Options
– Triggered subsystem
– User-defined function
– Others
• Latched and unlatched
Latched and unlatched trigger example – Matters with discrete-time signals
– Almost same with continuous-time
signals except for feedback
• Example:TriggerEx1.mdl
• Subsystem examples
Integration
• Initiailization
– Matched filter
– Correlator
• External triggering
• Example:IntegratorE
x.mdl

Integration block parameters


S-function
• User-defined function
written in MATLAB, etc.
• One input and one output
– scalar, vector, matrix, etc.
• Static parameters
• R14 provides more options
for user-defined function

User-defined functions library


S-function Operation
• Initialization
• Calculate outputs
• Update discrete states
• Calculate derivatives
• Integration
– Calculate outputs
– Calculate derivatives
• MATLAB example code
sfuntmpl.m is in
matlabroot/toolbox/si
mulink/blocks

S-function operation diagram


Example Code
• Flag 0: Initialization function [sys,x0,str,ts] =
VCO(t,x,u,flag,FreqCntr)
• Flag 1: Calculation of %VCO
switch flag,
derivatives case 0,% Initialization
[sys,x0,str,ts]=VCOInit;
• Flag 2: Update of discrete case 1,% Derivatives
states sys=VCODeriv(t,x,u);
case 2,% Update
• Flag 3: Calculation of sys=VCOUpdate(t,x,u);
output case 3,% Outputs
sys=VCOOutput(t,x,u,FreqCntr);
• Flag 4: Calculation of next case 4,% GetTimeOfNextVarHit
sample hit sys=VCPNextHit(t,x,u);
case 9,% Terminate
• Flag 9: End of simulation sys=VCOExit(t,x,u);
otherwise % Unexpected flags
tasks End
S-function Initialization
function [sys,x0,str,ts]=VCOInit
sizes = simsizes; • Define necessary
sizes.NumContStates = ; – Internal states (continuous
sizes.NumDiscStates = ;
sizes.NumOutputs = ; and discrete-time)
sizes.NumInputs = ; – Number of inputs
sizes.DirFeedthrough = ;
sizes.NumSampleTimes = ; – Number of outputs
% at least one sample time is
needed – Initial conditions
sys = simsizes(sizes);
x0 = [];
% initialize the initial conditions
str = [];
% str is always an empty matrix
ts = [0 0];
% initialize the array of sample
times
S-function Output
function [sys,x0,str,ts] =
VCO(t,x,u,flag,FreqCntr,Phase • T: time
,Gain)
switch flag,
• X: state
…………… • U: input
case 3,% Outputs
…………… • Flag: computation mode
sys=VCOOutput(t,x,u,FreqCntr,
Phase,Gain); • Static parameters
End

……………
function
sys=VCOOutput(t,x,u,FreqCntr,
Phase,Gain)
sys =
Gain*cos(2*pi*(FreqCntr+u)*t+
Phase);
S-function Instantiation
• Drag and drop S-function
system block to a model
• Double click the block to
specify the script name and
static parameters
S-function instance • Example:
VCOSfuncEx.mdl

S-function block parameters


Discussions on PLL
• Modulation frequency
• Number of waves per symbol
• Low-pass filter
• Simulation length
• Symbol feedback delay
• Evaluation
• Timing error
• Capture range
• Loop lock range
• Effect of symbol error
Decision-directed PLL diagram • Effect of signal noise

You might also like