Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
learn:courses:real-analog-chapter-9:start [2017/01/10 23:09] – created Marthalearn:courses:real-analog-chapter-9:start [2022/10/04 11:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Real Analog: Chapter 9 ====== ====== Real Analog: Chapter 9 ======
 +[[{}/learn/courses/real-analog-chapter-8/start|Back to Chapter 8]]
 +-->Chapter 9 Materials#  
 +  * Lecture Material:
 +    * {{ :learn:courses:real-analog-chapter-9:lecture24.ppt |Lecture 24 PowerPoint Slides}}: Introduction to state-variable modeling, simulating system response using MATLAB
 +    * [[http://www.youtube.com/watch?v=2cQMO3NZz4Y&list=PLDEC730F6A8CDE318&index=27&feature=plpp_video| Lecture 24 Video]]
 +  * Chapter 9 Video:
 +    * [[http://www.youtube.com/watch?v=vl-lemzB1w8&list=PL170A01159D42313D&index=19&feature=plpp_video| Lab 9 Video 1]]: State Variable Models: The step response of the state variables of a series RLC circuit are measured. The measurements are compared to the simulated response obtained by using MATLAB.
 +  * {{ :learn:courses:real-analog-chapter-9:real-analog-chapter-9.pdf | Chapter 9 Complete PDF}}
 +    * {{ :learn:courses:real-analog-chapter-9:lab9p3p1.pdf |Lab 9.3.1}}
 +      * {{ :learn:courses:real-analog-chapter-9:lab9p3p1_worksheet.docx |Worksheet 9.3.1}}
 +    * {{ :learn:courses:real-analog-chapter-9:lab9p3p2.pdf |Lab 9.3.2}}
 +      * {{ :learn:courses:real-analog-chapter-9:lab9p3p2_worksheet.docx |Worksheet 9.3.2}}
 +  * {{ :learn:courses:real-analog-chapter-9:realanalog-exercisesolutions-chapter9.pdf |Exercise Solutions}}: Chapter 9 exercise solutions
 +  * {{ :learn:courses:real-analog-chapter-9:homework9.docx |Homework}}: Chapter 9 homework problems
 +
 +<--
 +
 ====== 9. Introduction and Chapter Objectives ====== ====== 9. Introduction and Chapter Objectives ======
 In our analysis approach of dynamic systems so far, we have defined variables which describe the energy in the circuit energy storage elements (voltages across capacitors and currents through inductors). We then used KVL and KCL to write differential equations describing the circuit, in terms of those variables. The resulting equations were then combined into a single differential equation governing the parameter in which we were interested (the //input-output equation// for the system); this equation was solved to determine the response of the circuit. This approach is useful for low-order systems, such as the first or second order systems we have examined so far, but it becomes cumbersome for higher-order systems. An alternate modeling approach, //state variable// (or //state space//) modeling, has a number of advantages over the approach we have been using to date, especially for higher-order systems. In our analysis approach of dynamic systems so far, we have defined variables which describe the energy in the circuit energy storage elements (voltages across capacitors and currents through inductors). We then used KVL and KCL to write differential equations describing the circuit, in terms of those variables. The resulting equations were then combined into a single differential equation governing the parameter in which we were interested (the //input-output equation// for the system); this equation was solved to determine the response of the circuit. This approach is useful for low-order systems, such as the first or second order systems we have examined so far, but it becomes cumbersome for higher-order systems. An alternate modeling approach, //state variable// (or //state space//) modeling, has a number of advantages over the approach we have been using to date, especially for higher-order systems.
Line 71: Line 88:
 \cdot \\ \cdot \\
  
-y_P=c_{P1}x_1+c_{P2}x_2+ \dots + C_{PN}x_N+d_Pu \\+y_P=c_{P1}x_1+c_{P2}x_2+ \dots + c_{PN}x_N+d_Pu \\
  
 (Eq. 9.5)$$ (Eq. 9.5)$$
Line 122: Line 139:
      x_2      x_2
      \end{bmatrix} + 0 \cdot u$$      \end{bmatrix} + 0 \cdot u$$
-     +  
 ---- ----
  
Line 234: Line 252:
  
 ==== Example 9.3: Step Response of Series RLC Circuit ==== ==== Example 9.3: Step Response of Series RLC Circuit ====
 +Determine and plot the response of the system of example 9.1 if 
 +$$u(t) =  \begin{cases}
 +    0V, t < 0 \\
 +    2V, t \geq 0 \\
 +  \end{cases}$$ 
 +
 +and the circuit is initially relaxed (i.e. all voltages and currents in the system are initially zero). Also plot the state trajectory for this input. The state equations for the circuit of example 9.1 were previously determined to be:
 +
 +$$\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} = \begin{bmatrix}
 +       -2  &  -2  \\
 +       2   &  0   \\
 +       \end{bmatrix}
 +       \begin{bmatrix} 
 +       x_1 \\
 +       x_2 \end{bmatrix} + \begin{bmatrix}
 +       2 \\
 +       0 \\
 +       \end{bmatrix} u(t)$$
 +
 +While the output equation is:
 +
 +$$y= \begin{bmatrix} 
 +     0  &  1
 +     \end{bmatrix}
 +     \begin{bmatrix}
 +     x_1 \\
 +     x_2 \end{bmatrix} + 0 \cdot u$$
 +     
 +Thus, the matrices describing the state space model are:
 +
 +$$A= \begin{bmatrix} 
 +     -2  &  -2 \\
 +      2  &  0 
 +     \end{bmatrix}, 
 +     \underline{b} = \begin{bmatrix}
 +     2 \\
 +     0 \end{bmatrix},  
 +     \underline{c} = \begin{bmatrix}
 +     0  &  1  \end{bmatrix}, d=0$$
 +     
 +To simulate the response of the system we first need to input the state variable model. We begin by defining the $\underline{A}$, $\underline{b}$, $\underline{c}$, and d matrices as follows: 
 +
 +$$ >> A = \begin{bmatrix}
 +-2  &  -2;  &  2  &  0 \end{bmatrix}; \\
 +>> b = \begin{bmatrix} \\
 +2;  &  0  \end{bmatrix}; \\
 +>> c = \begin{bmatrix} \\
 +0  &  1  \end{bmatrix}; \\
 +>> d = 0; $$
 +
 +The >> symbols denote the command prompt at MATLAB’s command window; they are included here to emphasize MATLAB commands. 
 +
 +It is generally desirable to create a model object in MATLAB to represent the system model((This is not entirely necessary, since the step and initial commands will accept the A, b, c, and d matrices directly as arguments. It is, however, encouraged.)). To create a state space system model, the command is **ss**. Arguments to the command are the above matrices; the output is the system model object. To create a model of our system, we type:
 +
 +$$>> \text{sys = ss(A, b, c, d)};$$
 +
 +Our workspace now contains a state space model object of our system named “sys”.
 +
 +We can simulate the response of this system to the desired input by using MATLAB’s **step** command. The step command assumes that the system is initially relaxed and the input to the system is:
 +
 +$$u(t) =  \begin{cases}
 +    0, t < 0 \\
 +    1, t \geq 0 \\
 +  \end{cases}$$ 
 +  
 +The input to our system is exactly twice this input, so we can simply scale our output by a factor of two. (This works because the system is linear – don’t try this with a nonlinear system!) The appropriate commands are (note that we have to scale both the output and the states, since we will be plotting the output response and the state trajectory):
 +
 +$$>> [y,x,t] = step(sys); \\
 +>> y = 2*y; \\
 +>> x = 2*x; \\$$
 +
 +The final step is to plot the responses. Plotting the output response can be accomplished with the following commands:
 +
 +$$>> \text{figure} \\
 +>> \text{plot}(t,y) \\
 +>> \text{title('System output vs. time')} \\
 +>> \text{xlabel('Time, sec')} \\
 +>> \text{ylabel('Response, Volts')} \\$$
 +
 +Which results in the figure below:
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9e.png |Example image 1.}}
 +
 +We can plot the state trajectory by plotting the second state vector, $x_1(t)$, vs. the first state vector, $x_2(t)$. MATLAB returns the first state vector as the first column of the x matrix, the second state vector as the second column of the x matrix, and so on. Thus, we can plot the state trajectory with the following commands:
 +
 +$$>> \text{plot}(x(:,1),x(:,2)) \\
 +>> \text{grid} \\
 +>> \text{xlabel}('X_1(t)') \\
 +>> \text{ylabel}('X_2(t)') \\
 +>> \text{title('State trajectory for Example 1')} \\$$
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9f.png |Example image 2.}}
 +
 +----
 +
 +==== Section Summary ====
 +  * If you have access to MATLAB’s control system toolbox, 
 +      * A state space model object can be created with the **ss** function. Inputs to the function are the A, b, c, and d matrices of the state space model. 
 +      * The **step** command can be used to calculate the step response of the system. 
 +      * The **initial** command can be used to calculate the natural response of the system.
 +
 +----
 +
 +==== Exercises ====
 +**1.**  Simulate the response $y(t)$ of the circuit below, if $u(t)$ is a unit step function.
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9g.png |Example image 1.}}
 +
 +**2.** Simulate the response $y(t)$ of the circuit below, if $u(t)$ is a unit step function.
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9h.png |Example image 2.}}
 +
 +
 +----
 +
 +===== 9.3: Numerical Simulation of System Responses Using Octave =====
 +This chapter provides a brief outline describing the use of some special-purpose Octave commands for simulating the response of linear, time invariant systems (these are systems which are governed by linear differential equations with constant coefficients).
 +
 +Octave is an open-source software with many of the same capabilities as MATLAB. Unlike MATLAB, however, Octave is available for free. For more information about Octave, see the web site at http://www.gnu.org/software/octave/. Octave syntax is very similar to MATLAB syntax, so the commands in this section are very similar to those provided in section 9.2.
 +
 +This section assumes some knowledge of basic Octave syntax. For those who are not familiar with Octave, a brief overview of the necessary topics is provided in Appendix A.2 of this textbook.
 +
 +==== Basic Commands for Simulation of Linear, Time-invariant Systems ====
 +Like MATLAB, Octave provides a number of special-purpose commands for simulating the response of linear, time-invariant systems. Among these commands are commands specific to determining the step response and natural response of systems; we will restrict our attention to these commands in this chapter.
 +
 +To calculate system responses (e.g. to solve the differential equations of interest), we will use only Octave’s **step** and **initial** commands in this chapter. The **step** command calculates a unit step response for the system, while the **initial** command calculates the natural response of a system to some set of initial conditions. We will also use the **ss** command to create state space model objects, to send to the **step** and **initial** commands. Basic syntax for these commands is provided below.
 +
 +**step**:
 +
 +The command **[y,t]=step(sys)** returns the step response of the state variable model described by the model object **sys**. The vector **y** contains the system output, the matrix **x** contains the states, and the vector t contains the time samples.
 +  * The command **[y]=step(sys,t)** returns the step response as above, but calculated over the specified time vector **t**. 
 +  * The command **[y,t]=step(sys)** returns the system output as above, and the times at which the response is calculated, but not the state variables **x**. 
 +  * **step(sys)** with no left-hand arguments results in a plot of the step response output.
 +
 +**initial**:
 +
 +Response of linear system to an initial condition. **[y,x,t]=initial(sys,x0)** returns the response of the system described by the state space model {A,b,c,d} to an initial condition contained in the vector x0. Variations on this command are similar to those provided above for the **step** command.
 +
 +**ss**:
 +
 +Create a state space model object. **sys = ss(A, b, c, d)** returns an object named **sys** which provides a state space model corresponding to the matrices provided in **A**, **b**, **c**, and **d**.
 +
 +
 +----
 +
 +==== Example 9.4: Step Response of Series RLC Circuit ====
 +Determine and plot the response of the system of example 9.1 if
 +
 +$$u(t) =  \begin{cases}
 +    0V, t < 0 \\
 +    2V, t \geq 0 \\
 +  \end{cases}$$ 
 +  
 +and the circuit is initially relaxed (i.e. all voltages and currents in the system are initially zero). Also plot the state trajectory for this input. The state equations for the circuit of example 9.1 were previously determined to be:
 +
 +$$\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} = \begin{bmatrix}
 +       -2  &  -2  \\
 +       2   &  0   \\
 +       \end{bmatrix}
 +       \begin{bmatrix} 
 +       x_1 \\
 +       x_2 \end{bmatrix} + \begin{bmatrix}
 +       2 \\
 +       0 \\
 +       \end{bmatrix} u(t)$$
 +       
 +While the output equation is:
 +
 +$$y= \begin{bmatrix} 
 +     0  &  1
 +     \end{bmatrix}
 +     \begin{bmatrix}
 +     x_1 \\
 +     x_2 \end{bmatrix} + 0 \cdot u$$
 +     
 +Thus, the matrices describing the state space model are:
 +
 +$$A= \begin{bmatrix} 
 +     -2  &  -2 \\
 +      2  &  0 
 +     \end{bmatrix}, 
 +     \underline{b} = \begin{bmatrix}
 +     2 \\
 +     0 \end{bmatrix},  
 +     \underline{c} = \begin{bmatrix}
 +     0  &  1  \end{bmatrix}, d=0$$
 +     
 +To simulate the response of the system we first need to input the state variable model. We begin by defining the $\underline{A}$, $\underline{b}$, $\underline{c}$, and d matrices as follows: 
 +
 +$$ > A = \begin{bmatrix}
 +-2  &  -2;  &  2  &  0 \end{bmatrix}; \\
 +> b = \begin{bmatrix} \\
 +2;  &  0  \end{bmatrix}; \\
 +> c = \begin{bmatrix} \\
 +0  &  1  \end{bmatrix}; \\
 +> d = 0; $$
 +
 +The > symbols denote the command prompt at Octave’s command window; they are included here to emphasize Octave commands.
 +
 +Unlike MATLAB, Octave __requires__ you to create a model object to represent the system model. To create a state space system model, the command is s**s**. Arguments to the command are the above matrices; the output is the system model object. To create a model of our system, we type:
 +
 +$$ > \text{sys} = ss(A, b, c, d);$$
 +
 +Our workspace now contains a state space model object of our system named “sys”.
 +
 +We can simulate the response of this system to the desired input by using Octave’s step command. The step command assumes that the system is initially relaxed and the input to the system is:
 +
 +$$u(t) =  \begin{cases}
 +    0, t < 0 \\
 +    1, t \geq 0 \\
 +  \end{cases}$$.
 +  
 +The input to our system is exactly twice this input, so we can simply scale our output by a factor of two. (This works because the system is linear – don’t try this with a nonlinear system!) The appropriate commands are (note that we have to scale both the output and the states, since we will be plotting the output response and the state trajectory):
 +
 +$$
 +> [y,t] = \text{step}(sys); \\
 +> y = 2*y; \\
 +$$
 +
 +The final step is to plot the response. Plotting the output response can be accomplished with the following commands:
 +
 +$$
 +> \text{plot}(t,y) \\
 +> \text{title('System output vs. time')} \\
 +> \text{xlabel('Time, sec')} \\
 +> \text{ylabel('Response, Volts')} \\
 +$$
 +
 +which results in the figure below:
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9i.png |Example image 1.}}
 +
 +In order to plot the state trajectory using Octave, we must modify our state space model somewhat. Unlike MATLAB, the states themselves are not returned by Octave’s **step** command. However, we can alter our c and d matrices so that the output, y, contains __both__ system states. We will set up our output equations as follows:
 +
 +$$ \begin{bmatrix} 
 +     y_1(t) \\
 +     y_2(t) = \end{bmatrix}
 +     \begin{bmatrix}
 +     1  &  0 \\
 +     0  &  1 
 +     \end{bmatrix} 
 +     \begin{bmatrix}
 +     x_1 \\
 +     x_2 \end{bmatrix} +  
 +     \begin{bmatrix}
 +     0 \\
 +     0 \\  \end{bmatrix} u$$
 +     
 +This is implemented in Octave by re-setting the c and d matrices, re-calculating the model object, and re- calculating the system response with the following commands:
 +
 +$$
 +> c = [1 0; 0 1]; \\
 +> d = [0; 0]; \\
 +> sys = ss(A,b,c,d); \\
 +> [y,t] = \text{step}(sys); \\
 +> y = 2*y;
 +$$
 +
 +Now, the output $y_1(t)$ is simply the state $x_1(t)$ and the output $y_2(t)$ is the state $x_2(t)$. Octave returns the first state vector as the first row of the y matrix, and the second state vector as the second row of the y matrix. Thus, we can plot the state trajectory with the following commands:
 +
 +$$
 +> \text{plot}(y(1,:),y(:,2)) \\
 +> \text{grid} \\
 +> \text{xlabel}('X_1(t)') \\
 +> \text{ylabel}('X_2(t)') \\
 +> \text{title('State trajectory for Example 1')}
 +$$
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9j.png |Example image 2.}}
 +
 +----
 +
 +==== Section Summary ====
 +  * Octave allows you to simulate linear, time invariant systems with the following commands: 
 +      * A state space model object can be created with the **ss** function. Inputs to the function are the A, b, c, and d matrices of the state space model. 
 +      * The **step** command can be used to calculate the step response of the system. 
 +      * The **initial** command can be used to calculate the natural response of the system.
 +
 +
 +----
 +
 +==== Exercises ====
 +**1.** Simulate the response $y(t)$ of the circuit below, if $u(t)$ is a unit step function.
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9k.png |Example image 1.}}
 +
 +**2.** Simulate the response $y(t)$ of the circuit below, if $u(t)$ is a unit step function.
 +
 +{{ :learn:courses:real-analog-chapter-9:chapter9l.png |Example image 2.}}
 +
  
 +[[{}/learn/courses/real-analog-chapter-8/start|Back to Chapter 8]]
 +[[{}/learn/courses/real-analog-chapter-10/start|Go to Chapter 10]]