U NIVERSITY of V AASA Telecommunication Engineering Group TLTE.3120 Computer Simulation in Communication and Systems (5 ECTS) Lecture Timo Mantere
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features We cannot go through all the possibilities of Matlab and Simulink in this course, so most important is to know where to get help when you start doing real things with Matlab Basically most of the things you need to know is available in Mathworks homepage Use find there with proper keywords and you probably find what you are looking for, lot of examples and example codes
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Matlab tutorial videos available Data analysis and visualization Programming and algorithm development Application development
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Simulink tutorial videos available Simulink key features Building the model Simulating the model Analyzing simulation results Managing projects Connecting to hardware Videos Examples processing-and-communications processing-and-communications
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Features important to our students Digital signal processing toolbox Control system toolbox Communications system toolbox Also: Design and simulate radio systems Radio frequency toolbox LTE toolbox
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Features important to our students Digital filter design Filterbuilder Type filterbuilder Select filter type Select features View filter response
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Filter design with Matlab, example, copy paste parts s1=[20, 30, -10, 40, 40, 30, 20] %first signal s2=[20, 30, 40, 0, -1, 0, 40, 30, 20] %second signal b1=fir1(3,0.5) %create FIR filter with fir1 [b2, a]=butter(3,0.5) %create IIR filter freqz(b2,a,100,1000) %frequency response of IIR filter %hold %freqz(b1,1,100,1000) %frequency response of FIR filter %filter 1. signal with FIR and IIR filters F1=filter(b1,1,s1) %FIR filter a=1 I1=filter(b2,a,s1) %filter 2. signal with FIR and IIR filters F2=filter(b1,1,s2) I2=filter(b2,a,s2)
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Filter design with Matlab, example 2 N=50; %fir degree %create rectangular window window=ones(N+1,1); %frequncies and responses for drawing f=[0 1]; m=[0 1]; %fir filter creation with fir1 or fir2 function b=fir2(N, f, m, window) %b=fir2(N, f, m, window); %calclate fir attenuation [h,w]=freqz(b,1,1000); %draw frequncy response, wanted and obtained plot(f,m,w/pi,abs(h)) legend('Ideal','fir2 Designed'); title('Comparison of Frequency Response Magnitudes'); %freqz(b,1,512) %attenuation
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Filter design with Matlab, example 3 % Define bandbass wn=[ ]; N=50; %FIR degree window=ones(N+1,1); b=fir1(N, wn, window) %Fir %attenuation [h,w]=freqz(b,1,512) %frequncies for calulating responses f=[ ]; m=[ ]; %draw wanted and obtained response plot(f,m,w/pi,abs(h)) legend('Ideal','fir1 Designed'); title('Comparison of Frequency Response Magnitudes'); %freqz(b,1,512)
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Also available other filter models e.g. Butterfield % Generate low pass filter eg. len=10, Fn=0.5 [b,a]=butter(len,Fn); Chebyshev Cheby1 [b,a] = cheby1(N,R,Wp) Chepy2 [b,a] = cheby2(N,R,Wst) Elliptic [b,a] = ellip(N,Rp,Rs,Wp)
U NIVERSITY of V AASA Telecommunication Engineering Group Matlab features Matlab C code generation C conversion can be done with codegen command Help codegen Examples: for-a-matlab-kalman-filtering-algorithm#1 for-a-matlab-kalman-filtering-algorithm#1 +Generation+for+a+MATLAB +Generation+for+a+MATLAB
U NIVERSITY of V AASA Telecommunication Engineering Group Simulation of communication systems Communication systems have become more and more complex over the years Systems requires more analyses during the design phase Analyses must be done fast and cost-effectively These things have lead to the computer based simulations
U NIVERSITY of V AASA Telecommunication Engineering Group Simulation of communication systems Communication systems can be analyzed and evaluated e.g. by Based on formulas and their calculations (usually simplified models) Waveform-level simulations Hardware prototyping and measurements (quite costly) Combinations of previous Usually simulation based evaluation is most flexible, one can combine mathematics with models or measured data Communication system could be whatever, satellite-based, terrestrial wireless, optic cables, Ethernet, etc.
U NIVERSITY of V AASA Telecommunication Engineering Group Simulation of communication systems Different simulation techniques are used to evaluate performance, e.g. At network level flow of packets and messages over the network is simulated, calculating throughput, packet loss, response time, resource utilization etc Communication links are measured in terms of error characteristics, bit error rate etc. Link could contain different parts that are simulated separately; modulators, encoders, filters, amplifiers, decoders, demodulators, etc. Also the hardware parts can be simulated by using hardware description language like VHDL
U NIVERSITY of V AASA Telecommunication Engineering Group Simulation of communication systems Quite often the simulation results are presented as Scope Y-T plot X-Y plot Frequency curve Frequency response curve (filter, channel) Eye diagram Error rate plot (SNR) I-Q plot (real-imaginary axis)
U NIVERSITY of V AASA Telecommunication Engineering Group A Refreshment of System Analysis
U NIVERSITY of V AASA Telecommunication Engineering Group Introduction: What is a Signal? Signals describe quantities that change. This change can be with time, frequency, location,..etc. Figure (1) in the next slide shows signal x(t) changes with time, this signal represent voice signal for word “Finland”. Figure (2) shows signal y(f) which represents certain signal in frequency domain Figure (3) shows signal z(n) which represents the grades of one of one of telecommunication courses in the University of Vaasa
U NIVERSITY of V AASA Telecommunication Engineering Group Introduction: What is a Signal? Figure (1) Figure (2) Figure (3)
U NIVERSITY of V AASA Telecommunication Engineering Group Introduction: What is a Signal? A signal is a function or sequence of values that represent information. The signals can be classified according to various criteria as shown in the table: Continuous (in time)discrete (in time) Amplitude-continuousAmplitude-discrete analoguedigital Real-valuedComplex-valued Uni-dimensionalMulti-dimensional Deterministicstochastic
U NIVERSITY of V AASA Telecommunication Engineering Group Introduction: What is a Signal? E.g. signal processing s = importdata('test.wav') % load sound sample soundsc(s.data,s.fs) % play sample plot(s.data)% plot sound sample plot(s.data(:,1))% plot first channel
U NIVERSITY of V AASA Telecommunication Engineering Group Introduction: What is a Signal? E.g. spectral density DF=fft(s.data(:,1));% Fourier transform of 1. channel N=length(s.data);% Length FF= DF.*conj(DF)/N;% spectral density f = s.fs/N*(0:(N-1)/2);% s.fs sample rate plot(f,FF(1:length(f))); See signal processing examples
U NIVERSITY of V AASA Telecommunication Engineering Group Introduction: What is a System? A system is the abstraction of a process or object that puts a number of signals into some relationship. Usually, we can classify system’s signals as input and output signals. Input signals exist independently of the system and are not affected by the system; instead the system reacts to these signals. Output signals carry information generated by the system, often as a response to input signals. System Single Input, Single Output (SISO) Multiple Input - Multiple Output (MIMO)
U NIVERSITY of V AASA Telecommunication Engineering Group Derivative Notation Following notations of derivative are equivalent: Usually the last form (x with dots) is favored in system analysis
U NIVERSITY of V AASA Telecommunication Engineering Group Example: Static and Dynamic Models A system is called dynamic, if its state is a function of its previous states. For example: The effect of external force F to object location x can be derived from the force balance equation ( m is a mass, k is a spring constant and B is a damping coefficient) A system is called static, if its current state does not depend on previous state For example: the effect of temperature T to pressure p in closed and isolated tank can be derived from the ideal gases law ( n is the molar amount, V volume and R gas constant)
U NIVERSITY of V AASA Telecommunication Engineering Group Example: Static and Dynamic Models In the simulations plotted on the right side, the external force in the mechanic system and the temperature in the gas tank model are changed step-vise In a dynamic system, the response will change long after the input has already stabilized. One can not define the respose just by knowing the input at the same time moment. In a static system the input and the response are changing only on same time monents, and the system response can be defined just by knowing the input at the same time moment Mass location External force Pressure Temperature
U NIVERSITY of V AASA Telecommunication Engineering Group Linear and Nonlinear Systems A system is linear, if it satisfies the following two conditions: 1) If input u 1 generates response y 1, then input Ku 1 generates response Ky 1 ( K is a constant). 2) If input u 1 generates response y 1 and input u 2 generates response y 2, then input (u 1 +u 2 ) generates response (y 1 +y 2 ).
U NIVERSITY of V AASA Telecommunication Engineering Group Linear and Nonlinear Systems In general, a differential equation is linear, if each term in it has a form constant (variable or variable’s derivative) For example: The real systems are usually nonlinear, but one can often approximate them by using linearization
U NIVERSITY of V AASA Telecommunication Engineering Group Continuous Time and Discrete Time Models Dynamic, continuous time models are described by using differential equations and differential equation groups For example, the damped oscillator differential equation Dynamic, discrete time models are described by using difference equations and difference equation groups For example, a rate formula:
U NIVERSITY of V AASA Telecommunication Engineering Group Time Variant and Time Invariant Systems In time variant systems the model parameters are changing as a function of time Further analysis of time variant systems is out of the scope of this course In time invariant systems the model parameters are assumed to be constants over time Most of the real-world systems are time variant (worning, dirt and dust, changing environmental conditions etc.), but in many cases the effect of time invariance is so small that it can be ignored in the model
U NIVERSITY of V AASA Telecommunication Engineering Group State-Space Representation There always exist a first order differential equation group which is equivalent to higher order differential equation The solution is not unique; usually there are several first order groups equivalent to higher order differential equation State-space representation is a compact way to present higher order differential equations System state in a certain time moment is a complete system description. If we know the initial state as well as all input values after the initial state, we can define system state and output values in every time moment. That makes state space representation well suitable for modeling. State space representation is also applied in the context of multivariable systems
U NIVERSITY of V AASA Telecommunication Engineering Group State-Space Representation In state-space representation, a higher order differential equation (or a group of higher order differential equations) is represented as a group of first order differential equations The number of first order equations will be equal to the order of the higher order differential equation There are several ways to select the state variables state-space representation is not unique
U NIVERSITY of V AASA Telecommunication Engineering Group State-Space Representation The general form of the state-space representation is x(t)=f(x(t), u(t) y(t)=g(x(t), u(t)) x(t) contains the state variables, u(t) control (input) variables and y(t) output variables These variables can be either matrices or scalars f(x(t), u(t)) is the system equation which describes the system dynamics g(x(t), u(t)) is the output equation which describes how system output depends on states and on control input If u(t) has a scaler value u(t) and y(t) has a scalar value y(t), the system is SISO. The dimension of state matrix x(t) can still be higher.
U NIVERSITY of V AASA Telecommunication Engineering Group Example: A Fluid Flow System (1/5) In a flow process a liquid one which have a chemical consentration C 1 is mixed with liquid two which have a chemical concentration C 2. We are targeting to have a production (flow F) of such a product, which concentration is C by controlling the flows F 1 and F 2. There is a free flow from the mixing tank to the air pressure the outflow is propotional to the square root of the tank surface level:
U NIVERSITY of V AASA Telecommunication Engineering Group Example: A Fluid Flow System (2/5) Form a differential equations for mass balance (will be simplified to volume balance) and for concentration balance:
U NIVERSITY of V AASA Telecommunication Engineering Group Linear State-Space Representation If the system is linear, variables and parameters can be separated. In that case the standard form of the state-space representation is A is system matrix, B control matrix, C output matrix and D direct effect matrix. It is often so that there is no direct effect. In that case D = 0 (so-called strictly proper system). X(t) Y(t)
U NIVERSITY of V AASA Telecommunication Engineering Group Linear State-Space Representation A differential equation group Can be represented as a matrix equation
U NIVERSITY of V AASA Telecommunication Engineering Group Example: a Circuit Board (1/4) A model for the circuit board illustrated on the left Input is v 0 (t), outputs are voltages v 1 (t) ja v 2 (t). Equations for the capacitors and currents are Kirchoff I Kirchoff II
U NIVERSITY of V AASA Telecommunication Engineering Group Example: a Circuit Board (2/4) Since the system input and system responses are all voltages, it is reasonable to eliminate the currents from the equations.
U NIVERSITY of V AASA Telecommunication Engineering Group Example: a Circuit Board (3/4) We got first order differential equation group Capasitor voltages are natural choise to be the state variables. Select the output to be only the voltage of the latter capasitor v 2 : v 1 (t), v 2 (t)
U NIVERSITY of V AASA Telecommunication Engineering Group Example: a Circuit Board (4/4) By applying these selections we will get and finally
U NIVERSITY of V AASA Telecommunication Engineering Group Finding the State Variables How to select the state variables? Make such a selection, which is physically reasonable (like in the previous examples) Use derivative operator p (so-called p-technique) Use chanonical forms Physically reasonable state variable selection is usually the easiest way Applying chanonical forms is just applying of a straightforward formula, but it might be difficult to see the physical meaning of the state variables
U NIVERSITY of V AASA Telecommunication Engineering Group Method 3: Use Chanonical Forms (2/2) Apply chanonical forms A result by using controllable chanonical form is similar with the one achieved by using derivative operator
U NIVERSITY of V AASA Telecommunication Engineering Group The Dimensions of the Linear State-Space Representation The system order is the same as the sum of the order of the differential equations which describe the system. It is also the dimension of the system matrix A. The number of inputs (control signals) is n u The number of outputs is n y System order is n S The dimensions of the linear state-space representation are as follows:
U NIVERSITY of V AASA Telecommunication Engineering Group Solutions in Time and Laplace Domains Laplace-domain solution Laplace-domain problem Time domain problem Time domain solution
U NIVERSITY of V AASA Telecommunication Engineering Group Laplace-transform F(s) is a Laplace transform of time domain function f(t). The Laplace- transform and its inverse transform are defined as follows: The following two theorems can be applied, if the respective limits exist: Final value theorem Initial value theorem The most usual Laplace-transforms and inverse transforms are tabulated
U NIVERSITY of V AASA Telecommunication Engineering Group Laplace-transforms (1/5)
U NIVERSITY of V AASA Telecommunication Engineering Group Laplace-transforms (2/5)
U NIVERSITY of V AASA Telecommunication Engineering Group Laplace-transforms (3/5)
U NIVERSITY of V AASA Telecommunication Engineering Group Diracin deltaImpulssi Askel Penger
U NIVERSITY of V AASA Telecommunication Engineering Group
U NIVERSITY of V AASA Telecommunication Engineering Group Deterministic Test Functions Following signals u(t) are often used as system inputs Unit impulse function (Dirac delta function) Unit step function U(t) = 0; t <0 = 1; t >0 Unit ramp function U(t) = 0; t <0 = t; t >0
U NIVERSITY of V AASA Telecommunication Engineering Group Example: Damped Oscillator The differential equation of the damped oscillator: Solve the system response (output), when K=5 B=2 M=1 In time domain the model is
U NIVERSITY of V AASA Telecommunication Engineering Group Example: Damped Oscillator Solve location X(s) from the Laplace-transformed expression: Then solve x(t) by computing the inverse Laplace transform back to the time domain:
U NIVERSITY of V AASA Telecommunication Engineering Group Zero-State and Zero-Control Responses System response can be divided to the part y 0 (t) (zero- control response) caused by system initial values and to the part y u (t) caused by the external input (zero-state response). Linear system response is a sum of these two parts: System response is equal to zero-control response y 0 (t) if the external inputs u i (t) = 0. System response is equal to zero-state response y u (t), if all system initial values y (n) (0) and u i (n) (0) are zeros. Term ”response” refers often to zero-state response, in other words system response to some external input
U NIVERSITY of V AASA Telecommunication Engineering Group Example: Damped Oscillator Zero-control response starts from the system initial state (location 1, velocity -1) Zero-state response starts from zero once the external force starts to effect System response is a sum of these two components
U NIVERSITY of V AASA Telecommunication Engineering Group Transfer Function One of the crucial topics in system analysis is to analyze that how external signals and disturbances affect the system response System transfer function is system response divided by system external input in Laplace-domain: It follows from the definition that if system initial values are zero, system output in Laplace-domain is given by InputResponse Transfer fcn
U NIVERSITY of V AASA Telecommunication Engineering Group Transfer Function A differential equation (or equation group) characterizing the system is first Laplace-transformed and then Y(s) / U(s) is solved. If we have several input and output variables (MIMO-model), we will get a transfer function matrix
U NIVERSITY of V AASA Telecommunication Engineering Group Transfer Function General form of the linear differential equation is Laplace-transform gives (initial values are assumed to be zero) Then it is easy to solve the transfer function
U NIVERSITY of V AASA Telecommunication Engineering Group Static Gain System static gain quantifies how much signal is strengthtened of faded once it goes through the system For unit step respons, the static gain describes in which level the system response will set (asymptotic stable system) For unit ramp response, the static gain gives the response angular coefficient in continuous state (asymptotic stable system) Static gain can be solved as a limit of system transfer function. It can be solved also for nonstabile systems, but in that case there is no physical connection to system response end value. System static gain is given by For stabile system
U NIVERSITY of V AASA Telecommunication Engineering Group From State-Space Representation to Transfer Function A transfer function can be counted directly from the state-space representation such that If the direct effect term D = 0, the formula is simplified to
U NIVERSITY of V AASA Telecommunication Engineering Group Example: Damped Oscillator Solve unit step response by using a transfer function The response is