11
ES442 Final Project Ver.1 1 ES442 Final Project AM & FM De/Modulation Using SIMULINK Goal: 1. Understand the basics of SIMULINK and how it works within MATLAB. 2. Be able to create, configure and run a simple model. 3. Create a subsystem. 4. Utilize variables between the MATLAB workspace and the SIMULINK model space. 5. Apply and investigate AM and FM modulation within SIMULINK. Background: SIMULINK is a model based difference or differential equation solver using simulation time/time steps as a fundamental basis for the simulation's construction and evaluation. A model consists of sources and sinks and intermediate blocks that represent basic dynamical system elements. These elements can be as basic as passive elements such as power supplies, sine waves, resistors, capacitors etc. to complex enigmatic entities like neural networks and image processing engines. Each entity within the model contains properties that control the function and the characteristics of each block. These properties need to be configured to represent the system being modeled. In addition to the model elements the equation solver that governs the simulation needs to be configured as well. SIMULINK enables quick evaluation of simple to complex systems and can shed insight into system behavior in a fraction of the time of physical prototypes. While the suggested reading and activity will only scratch the surface of SIMULINK it is intended to bring the reader up to a basic understanding of SIMULINK and its interaction within MATLAB. A typical SIMULINK work flow session will consist of the following steps 1. Type ">>simulink" at MATLAB prompt 2. Create new model from the SIMULINK library browser menu pull downs: FILE>New Model 3. Add blocks that correspond to model dynamics/functions: Sine waveforms, constants, filters, ramps, scopes, user functions etc. 4. Define the blocks; add details about sources, sinks, operators. There are many resources to construct model topologies As previously mentioned each block needs to be defined with appropriate model parameters. If it's a spring model, an appropriate "K" value needs to be defined. If it's a sine waveform: Amplitude, frequency, phase need to be defined. 5. Save the Model. 6. Set simulation Options/ Solver options: The type of solver to use ODE45, ODE3, etc. These are provided with MATLAB The time step and various differential equation boundary conditions should be defined. 7. Run the model 8. Configure the output either with outputs within SIMULINK or export data to the MATLAB workspace for more control over the plotting, or additional post processing.

ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

Embed Size (px)

Citation preview

Page 1: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         1    

ES442 Final Project AM & FM De/Modulation Using SIMULINK

Goal:    1.  Understand  the  basics  of  SIMULINK  and  how  it  works  within  MATLAB.  2.  Be  able  to  create,  configure  and  run  a  simple  model.  3.  Create  a  subsystem.  4.  Utilize  variables  between  the  MATLAB  workspace  and  the  SIMULINK  model  space.  5.  Apply  and  investigate  AM  and  FM  modulation  within  SIMULINK.    

Background:    SIMULINK  is  a  model  based  difference  or  differential  equation  solver  using  simulation  time/time  steps  as  a  fundamental  basis  for  the  simulation's  construction  and  evaluation.  A  model  consists  of  sources  and  sinks  and  intermediate  blocks  that  represent  basic  dynamical  system  elements.  These  elements  can  be  as  basic  as  passive  elements  such  as  power  supplies,  sine  waves,  resistors,  capacitors  etc.  to  complex  enigmatic  entities  like  neural  networks  and  image  processing  engines.    Each  entity  within  the  model  contains  properties  that  control  the  function  and  the  characteristics  of  each  block.  These  properties  need  to  be  configured  to  represent  the  system  being  modeled.  In  addition  to  the  model  elements  the  equation  solver  that  governs  the  simulation  needs  to  be  configured  as  well.      SIMULINK  enables  quick  evaluation  of  simple  to  complex  systems  and  can  shed  insight  into  system  behavior  in  a  fraction  of  the  time  of  physical  prototypes.  While  the  suggested  reading  and  activity  will  only  scratch  the  surface  of  SIMULINK  it  is  intended  to  bring  the  reader  up  to  a  basic  understanding  of  SIMULINK  and  its  interaction  within  MATLAB.    A  typical  SIMULINK  work  flow  session  will  consist  of  the  following  steps  

 1. Type  ">>simulink"  at  MATLAB  prompt  2. Create  new  model  from  the  SIMULINK  library  browser  menu  pull  downs:    

• FILE-­‐>New  Model  3. Add  blocks  that  correspond  to  model  dynamics/functions:    

• Sine  waveforms,  constants,  filters,  ramps,  scopes,  user  functions  etc.  4. Define  the  blocks;  add  details  about  sources,  sinks,  operators.  There  are  many  resources  to  

construct  model  topologies  • As  previously  mentioned  each  block  needs  to  be  defined  with  appropriate  model  

parameters.  If  it's  a  spring  model,  an  appropriate  "K"  value  needs  to  be  defined.  If  it's  a  sine  waveform:  Amplitude,  frequency,  phase  need  to  be  defined.  

5. Save  the  Model.    6. Set  simulation  Options/  Solver  options:  

• The  type  of  solver  to  use  ODE45,  ODE3,  etc.  These  are  provided  with  MATLAB  • The  time  step  and  various  differential  equation  boundary  conditions  should  be  defined.  

7. Run  the  model  8. Configure  the  output  either  with  outputs  within  SIMULINK  or  export  data  to  the  MATLAB  

workspace  for  more  control  over  the  plotting,  or  additional  post  processing.  

Page 2: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         2    

 Read  the  provided  handout  in  PIAZZA  for  details  on  how  to  work  with  SIMULINK  and  create  models.    The  following  link  provide  valuable  resources  for  how  to  create  basic  models  using  SIMULINK:  https://www.mathworks.com/academia/student_center/tutorials/sltutorial_launchpad.html?confirmation_page#  

Lab  Activity  It  is  important  to  go  through  the  handout.  This  project  is  based  on  the  examples  in  the  handout.    

AM  Modulation  1. Create  a  DSB-­‐SC  AM  modulator  model.  See  Pg  128  of  the  handout.  The  model  should  look  similar  to  

the  figure  below:    

 M(t)  and  Carrier  are  sine  waveforms.  The  product,  gain,  and  SCOPE  blocks  can  be  found  by  searching  "product",  "gain"  and  "SCOPE",  respectively  within  the  library  browser:    

   Note  that  the  frequency  for  the  carrier  is  set  to  10  Hz.  The  frequency  for  the  modulating  frequency  is  set  to  1  Hz.    Tips  to  construct  the  model  using  SIMULINK:  

Page 3: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         3    

• Left  click  to  pull  signals  from  output  to  input  of  blocks.  • Right  click  to  create  a  branch  from  an  existing  signal  path.  • To  create  a  SCOPE  with  more  than  one  input  modify  the  "Number  of  axes"  property  within  

the  SCOPE  properties  window  double  click  on  the  SCOPE  and  then  click  on  the  gear  to  get  to  the  SCOPE  parameters.  

 • Any  variable  defined  in  the  MATLAB  workspace  can  be  used  within  SIMULINK.  Try  typing  

  >>fc  =  10     >>fm  =  1  In  the  Main  MATLAB  window  use  fc  and  fm  instead  of  1  and  10  within  the  sine  waveform  properties.  This  will  come  in  handy  to  experiment  with  different  model  parameters  in  more  complex  models.  

 2. We  now  need  to  configure  the  solver.  See  the  following  configurations:  

   

Page 4: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         4    

   

Form  the  SIMULINK  window  run  the  simulation.  The  SCOPE  should  be  able  to  be  configured  to  show  something  similar  to  what  is  shown  below.  Double  click  on  the  SCOPE  block  after  running  the  simulation  to  view  the  SCOPE  traces.  

   

   

Page 5: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         5    

If  the  output  is  only  a  portion  of  the  recorded  waveform  the  "history"  of  samples  recorded  may  need  to  be  modified,  or  the  waveform  needs  to  be  set  to  AUTO  scale  (shown  below).    

   

 

3. Condense  the  two  blocks  in  the  AM  modulation  model  (the  gain  block  and  the  multiplier  block)  into  a  subsystem  as  shown  below.  This  can  be  done  by  selecting  the  two  blocks  and  then  right  clicking  and  selecting  "create  subsystem".  

Run  the  simulation  again  confirm  that  the  system  still  works.  Take  a  snapshot  of  the  output  of  the  SCOPE.  Answer  the  following  questions:    

a. What  happens  if  you  change  the  GAIN  value  to  unity?    b. Why  do  we  call  this  type  of  modulation  SC  (suppressed  carrier)?  

   

Page 6: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         6    

FM  Modulation  Use  a  new  file  and  create  the  FM  modulation  model  shown  below.  Read  page  130  of  the  handout  for  more  details.  The  mathematical  expression  of  the  FM  modulated  signal  will  be  

 

In  our  model  we  assume:  kf  =  5Hz/V,  fc  =  10Hz  and  modulating  waveform  is  s(t)  =  cos(2*pi*t).  

   The  VCO  block  is  actually  a  user  defined  function,  search  "Fcn."  Double  click  on  the  "Fcn"  block  and    add  desired  function  with  "U"  representing  the  input  to  the  function.    

 

 

       

   

Page 7: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         7    

Configure  the  blocks  to  suit  the  system.  The  Discrete-­‐Time  Integrator  should  have  a  sample  time  of  0.01  (the  same  as  the  simulation  sample  time,  previously  set  in  the  AM  Modulation  portion).  

Configure  the  solver.  Refer  to  the  AM  modulation  solver  configuration.  

Run  the  simulation.  The  SCOPE  should  be  able  to  be  configured  to  show  something  similar  to  what  is  shown  below:  

   If  the  output  is  only  a  portion  of  the  recorded  waveform  the  "history"  of  samples  record  may  need  to  be  modified,  or  the  waveform  needs  to  be  set  to  auto  scale.    

   

 

Page 8: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         8    

Condense  the  two  FM  modulation  blocks  into  one  FM  modulation  subsystem  as  shown  below.  

 

Run  the  simulation  again  confirm  that  the  system  still  works.  Take  a  snapshot  of  the  output  of  the  SCOPE.    

Using  MATLAB  Code  Within  SIMULINK  In  this  section  we  would  like  to  modify  the  "ADD"  block  with  a  user  provided  MATLAB  function.  

1. Copy  your  previously  created  FM  modulator  subsystem.  Enter  into  the  subsystem  and  delete  the  "ADD"  block.  

 

Search  for  "MATLAB  Function"  and  add  it  to  your  model  subsystem.  Double  click  on  the  MATLAB  Function  Block  and  enter  in  the  code  below  in  the  MATLAB  block.  Save  the  function.    

 

Page 9: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         9    

   

Add  the  block  into  the  location  where  the  ADD  block  used  to  be:  

 

Run  the  simulation,  confirm  that  the  simulation  provides  the  same  output.  Change  the  GAIN  to  15.  Take  a  snapshot  of  the  SCOPE  results.  NOTE:  If  there  is  any  problem  with  this  section  please  report  it!    

   

Page 10: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         10    

Using  SIMULINK  to  Display  Signal  Spectrum    In  this  section  you  need  to  model  a  complete  FM  modulator/demodulator  and  analyze  the  output  of  each  section.  Download  the    FM_Mod_Dem  file  and  unzip  it.  Open  the  following  file  in  the  folder  and  run  it  using  MATLAB:  Setup_FM_Mod_Dem_Partial.m  .    You  should  see  the  following:    

 

Note  that  the  FM  modulator  is  similar  to  the  modulator  you  created  in  the  previous  section.    

1. Take  snapshots  of  the  spectrum  of  the  message  signal  and  FM  signal.    Elaborate  on  the  results.  What  is  the  carrier  frequency?    What  is  the  bandwidth?    

2. Pay  attention  to  how  the  Spectrum  Analyzers  are  setup;  click  on    and  check  the  setting.    3. Click  on  different  tabs  and  observe  the  setting  for  SCOPE  Properties,  Display  Properties,  Axis  

Properties,  and  Line  Properties.    

4. Modify  the  model  (circuit)  as  shown  below  and  rename  the  mdl file.  Note  that  the      block  represents  a  LPF.  The  characteristics  of  the  filter  is  defined  as  follow:    

 This  is  specified  in  the  Setup_FM_Mod_Dem_Partial.m    file.    

Page 11: ES442 Final Project AM & FM De/Modulation Using SIMULINKsonoma.edu/users/f/farahman/sonoma/courses/es442/finalProject... · ES442 Final Project ... ES442 Final Project AM & FM De/Modulation

ES442 Final Project        

Ver.1         11    

 

5. Run  the  simulator  and  observe  the  output.  Take  a  snapshot  of  the  FOUR  signals  captured  by  the  SCOPE.    

6. Explain  briefly  how  the  demodulator  operates.