Assignment Title: Matlab/Simulink Simulations
Assignment Part 1 - Introduction to Simulink
1. Introduction
This document describes Assignment Part 1 - Introduction to Simulink. It comprises:
- A series of Simulink-based exercises
- Some calculations to complete, question to answer and invitations to comment on one, more, or all aspects of the work undertaken
2. Assessment
Your performance will be assessed from an individual report and the logbook of your work. (The logbook will only be used, as necessary, to ascertain that the work in your report is your own.) An oral examination may be required if it is needed to clarify material in the report or to establish that the learning outcomes have been achieved.)
You are required to submit two assignment parts 1, 2, plus assignment part 3 (the mini project). There is a seven-page length limit (minimum font size 10 point) for each part of the assignment.
3. Background
Simulink is a programming language that uses a graphical user interface (GUI) in place of conventional lines of code. (Conventional code lies behind the Simulink GUI.) Functional blocks representing signals and the mathematical operations implemented by subsystems are connected together to simulate an entire communications system. There are many introductions to Simulink available on the web.
4. Aims
- To introduce Simulink as a means of assessing communications systems
- To illustrate the opportunities that simulation techniques offer, in particular the ease with which BER curves for a particular system design can be predicted using Monte Carlo simulation methods.
5. Exercises
There are two exercises in Assignment part 1. The first is an introduction to the mechanics of Simulink - in effect a 'getting started' tutorial. Simulink is a flexible, extensive and sophisticated simulator. This tutorial barely scratches the surfaces of its capabilities. As you progress through the exercises you may need to learn more about Simulink than is presented here. The Simulink help facility and built in tutorials will be your primary sources of further information but much material can also be found on the Mathworks website and elsewhere on the web.
The second exercise in this assignment illustrates one of the most common uses of communications simulation software, i.e. the prediction of BER versus SNR or Eb/N0 curves. It uses a baseband CPD transmission system as a vehicle to do this.
5.1 Simulink basics
5.1.1 Starting Simulink
Open MATLAB and, at the cursor (>>) in the command window, type simulink. The window opposite (or, depending on the version of Simulink being used, a similar window) will appear. This is the Simulink Library Browser. On the left-hand side of the Library Browser is a list of different blocksets and toolboxes that are available. In this assignment only the Simulink, Communication and Signal Processing blocksets are required. Blocksets and toolboxes can be expanded to show the individual functional blocks (or group of blocks) that they contain by clicking on the plus (+) sign to their immediate left. They can be de-expanded by clicking on the corresponding minus (-) sign. Icons representing the blocks in the blockset that has been expanded are shown on right hand side of the Library Browser.
5.1.2. Creating a new simulation model
In the Browser Library menu bar select File - New - Model. A model window will open (it is often convenient to re-position and/or resize the window so you can see both the Library Browser and Model windows simultaneously). A model is created by selecting, dragging and dropping blocks from the Library Browser into the Model window. Create the simple model shown below. (The Random Integer Generator is in the Random Data Sources subset of the Comm Sources subset of the Communications blockset. The Scope is in the Sinks subset of the Simulink blockset.) Connect the Random Integer Generator to the Scope by selecting the former, holding down the control key and selecting the latter.
5.1.3 Block parameters
The parameters that define each block can be displayed, set or changed by double clicking on the block. For example, double clicking on the Random Integer Generator displays the parameter window below.
M-ary number relates to the number of integer levels generated. In the parameter window shown above there are 8 levels (i.e. 0, 1, 2, ..., 7). The Initial seed relates to the number supplied to the random number generation algorithm. Since the algorithm is deterministic then the same initial seed in two or more simulations would result in identical 'random' sequences. The sample time is the time between samples at the output of the random number generator - in this case 1.0 s. Clicking the Help box on a Block Parameters window displays a definition/description of each parameter. Change the parameter M-ary of the Random Integer Generator in your model to 2 and the sample time to 1e-3. The model then represents a binary information source that will output integer values 0 and 1 with a period of 1 ms, i.e. it generates symbols at a rate of 1 kbaud (i.e. 1000 symbol/s). The Initial seed can, for this exercise, be left at its default value (usually 37) although it is generally good practice to replace the numerical value with randseed. (randseed is a MATLAB function that generates a random seed in the range 31 to 2×1017- 1. Details can be seen by typing help randseed in the MATLAB command window.) The Frame-based outputs and Interpret vector parameters as 1-D boxes should be unchecked. The Output data type should be double (means double precision). Click OK to close the parameter window.
[Note: Sample time in the Source Block Parameters window refers to the samples at the generator output, each sample representing one (independent) symbol. It does not refer to the simulation sampling time, i.e. the interval at which the simulator will calculate the state of the system model].
5.1.4 Configuration parameters
The configuration parameters of the simulation can be viewed changed or set by selecting Simulation - Configuration parameters ... from the Model window drop down menu. These parameters control the way in which the simulation will be performed. The most obvious parameters are Start time and Stop time. Set these to 0 and 0.2 s respectively. In the Solver options Typeselect Fixed-step. The simulation will thus run with outputs being calculated at fixed time intervals. In the Solver options Solver select discrete (no continuous states). Set the Solver options Fixed-step size (fundamental sample time) to 2e-5. This is what is normally referred to as the simulation sampling time and determines the time increments at which the state of the system model will be calculated. In this example therefore, since the duration of each random binary symbol is 1 ms and the simulation sampling interval is 20μs, the number of samples per symbol is 50. Set the Periodic sample time constraint to Unconstrained and the Tasking mode for periodic sample times to Auto. The Automatically handle data transfers between tasks and Higher priority value indicates higher task priority boxes should be unchecked. Click Apply and then OK to close the configuration parameter window.
5.1.5 Saving a model
The Simulink model can be saved in the normal way using File - Save as ... in the model window drop down menu. Save your model with the file name Ex_1 to a file called EE470-970 Simulink Models and close down Simulink and MATLAB.
5.1.6 Opening a model
Launch Simulink and recover your model using the File - Open ... on the Library Browser drop down menu.
5.1.7 Running a simulation and displaying time waveforms
Run the model simulation by selecting Simulation - Start in the Model window drop down menu. Simulink will give an audible 'ping' (providing the sound is not disabled) when the simulation is complete. To see the result of the simulation double click on the Scope icon. A new window will open showing the simulated signal 'recorded' by the scope as shown below.
Right clicking on either x- or y-axes allows the axes to be scaled. The trace (shown above) can be saved by copying it to clipboard and pasting it in a word document [select the trace window - press ALT+ PrintScrn to copy it to clipboard and CTRL+V to paste it in a word document].
5.1.8 Editing a model and displaying frequency spectra
Open the previous model and replace the Random Integer Generator with a Sine Wave Generator, (from the Sources blockset of the Simulink blockset). Add a Saturation block (from the Commonly Used Blocks of the Simulink blockset) and a Spectrum Scope, the Simulink name for a spectrum analyser, from the Signal Processing Sinks blockset of the Signal Processing blockset as shown below.
To connect the Spectrum scope to move the cursor over its input port until it turns into a crosshair, hold down the left mouse key and drag the crosshair (and therefore the line) line backwards until the crosshair is over the line connecting Saturation block and Scope. Then release the left mouse key. If the crosshair was properly placed the lines will become connected as indicated by a dot at the junction.
Set the Sine Wave parameters to Sin type: Time based, Time(t): Use simulation time, Amplitude: 1, Bias: 0, Frequency (rad/s): 2*pi*1000, Phase (rad): 0, Sample time : 2e-6. (This gives 500 samples per sine wave cycle.) The Interpret vector parameter as 1-D can be checked or unchecked. Close the parameter window by clicking OK.
Set the Saturation block parameters in the Main tab to Upper limit: 1000, (Providing the input signal does not exceed 1000 V the saturation block will thus model an ideal diode or half-wave rectifier.) Set the Lower limit: 0. The Treat as gain when linearizing can be checked or unchecked. Set Sample time (-1 for inherited): -1. In the Signal Attributes tab set Output data type: Inherit Same as input and Round integer calculations toward: Nearest.
Set the Spectrum scope parameters as shown below:
[Note that 262144 = 218. FFTs are more efficient when vectors with a length that is an integer power of 2.] The boxcar window is a synonym for a rectangular window (i.e. no explicit windowing at all - the start and stop times of the rectangular window simply being the start and end of the time series. Fs/2 in frequency range [0 ... Fs/2] means that the spectrum will be plotted from 0 Hz to the half the sampling, or Nyquist, frequency. This is the highest frequency observable with a sampling rate Fs/2.
Set the configuration parameters as shown in the window below:
Run the simulation. The spectrum should display as shown below on the left. If the Frequency display limits parameter is changed to user defined with Minimum X-limit: 0, Maximum X-limit: 50 the display will be as shown below on the right.
Click on the scope to examine the time series at the output of the saturation block. It should look like the window shown below. Note that only the last few periods are shown.
5.2 Binary polar baseband transmission with CPD
Binary polar baseband signalling uses equal amplitude, opposite polarity, pulses to represent digital ones and zeros. In the simulations below the simplest possible receiver detection strategy, centre point decision (CPD), is employed.
5.2.1 Time waveforms and spectra
Obtain the system model CPD.mdl from MyPlace. This is a baseband binary CPD (centre point decision) information transmission system using rectangular polar pulses. The Simulink block diagram is shown below.
Binary polar baseband transmission using CPD receiver (File name CPD)
Run the model and save the signals recorded by each scope. In the light of the time waveforms recorded by the scopes describe the function of each block in the system model and the character of the signal at the output of each block. (It may also be helpful/necessary for your description to examine the definitions and parameters of the blocks in Simulink).
Questions/comments
1. What is the value of the normalised noise power in this simulation? (Normalised power, measured in V2, is the mean square voltage or the power dissipated in a 1Ω resistive load).
2. What noise power spectral density is being simulated?
Add two Spectrum scopes to the model using the parameters shown below. (Note in particular the FFT length must be an integer power of 2.) One of the Spectrum scopes should measure the spectrum of the transmitted (noiseless) polar signal and one should measure the received (noisy) signal spectrum. Save this model with the file name CPS_spectrum.
Run the model and save the spectra. (You can adjust the axes of the spectrum plot using the Minimum Y-limit and Maximum Y-limit parameters in the Axis Properties tab of the Spectrum scope.)
Questions/comments
1. What is the frequency resolution of this spectrum? (If you do not know how to calculate the frequency resolution, see Section 13.5.7 of Glover & Grant, [1]).
2. Experiment with the window type and to see the difference it makes to the measured spectrum. (If you are not sure what effect 'windowing' of time series data has on the calculated spectrum then see section 13.5.7 of Glover & Grant, [1]).
3. Increase the stop time (in the configuration parameters window) to 5.24288 s. What is the new few frequency resolution of the simulation? Amend the buffer size and FFT length in the parameter windows of both Spectrum scopes to 262144 (= 218) and re-run the simulation. Save the transmitted and received spectra and compare them with the earlier spectra calculated with a poorer frequency resolution.
4. What is the value of simulation bandwidth? Comment on the adequacy or otherwise of this value in the context of the simulation.
5.2.2 BER performance
Download the system model CPD_error_rate shown below.
Binary polar baseband transmission using CPD receiver (File name CPD_error_rate)
This is the model CPD with additional blocks necessary to evaluate BER and some parameter changes (for example, a stop time that results in many more bits being transmitted).
Run this model several times (around 8), each time with a different value of noise variance in the range 0 to 20 V2. Choose the variance values to give SNRs (not in dBs) that are roughly logarithmically spaced, i.e. SNRs in dB that are linearly spaced. (SNR is normalised power in the signal divided by normalised power in the noise.) Record the BER from the BER data block after each simulation run. Plot (using MATLAB) BER versus SNR data points using logarithmic axes for both BER and SNR.
[As an alternative to running the simulation manually as described above you might wish to investigate the use of MATLAB in the form of a .m script which calls the simulation with different values of noise variance, keeps a record of the computed BER values and generates a graph of BER vs. SNR.]
Questions/comments
5. Compare the curve obtained by simulation with that produced by the appropriate error function formula. Comment on the agreement between the theoretical error function curve and the simulated data points.
6. Note how many bits are transmitted in the simulation. Comment on the smallest probability of error that could be estimated by the simulation with confidence and explain why this is so.
7. What is the worst-case signal-to-distortion-ratio (SDR) of the simulation?. Explain the adequacy or otherwise of this worst case SDR in the context of the simulation.
Attachment:- Communication Systems.rar