Ministry of Higher Education and Scientific Research University of Technology Electromechanical Engineering Department Control laboratory Control laboratory rd For 3 Year Electromechanical Engineering Department Supervised by Asst. Prof. Dr. Aseel J. Mohammed Prepared by Asst. Lec. Aws F. Hassan 2020-2021 Contents Experiment No. (1) Introduction to Matlab Experiment No. (2) Expressions Experiment No. (3) Dimensional Array Experiment No. (4) Working with Matrices Experiment No. (5) Dimensional Graphics Experiment No. (6) Relation and Logical Operations Experiment No. (7) Introduction to Control Systems Analysis and Design Using Matlab and Simulink Experiment No. (8) First Order Systems Experiment No. (9) Steady State Error analysis Experiment No. (10) Second- Order Systems Experiment No. (11) Root Locus Plot Experiment No. (12) State Space Representation Experiment No. (13) Discrete –Time Systems Experiment No.(14)The Zero−Order Hold and First−Order Hold as Reconstruction Experiment No.(15)The State−Space block by using mechanical System (Mass−Spring−Dashpot) Some Basic commands: 1. 2. 3. 4. Clear Command: Removes all the variables from workspace. CLC Command: Clears the Command Window and homes the cursor. Help Command: Help <topic> displays help about that topic if it exist. Edit Command: enable you to edit (open) any M-file in editor window. This command does not open built-in function like, sqrt. 5. Look for Command: Provides help by searching through all the first lines of MATLAB help topics and returning those that contains a key word you specify. 6. help: help facility. 7. Demo: run demonstrations. 8. Who: List M – file on disk. 9. clear: clear workspace. 10.computer : type of computer. 11.C: local abort. 12.exit: exit MATLAB. 13.quit: same as exit. 14. abs: absolute value or complex magnitude. 15. angle: phase angle. 16.sqrt :square root. 17.real :real part. 18.imag: imaginary part. 19.conj :complex conjugate. 20.round: round to nearest integer. 21.fix :round toward zero . 22.floor: round toward - . 23.exp: exponential base e. University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No. (1) Introduction to MATLAB 1-1 Introduction: MATLAB is a high – performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include: 1. Math and computation. 2. Algorithm development data acquisition. 3. Modeling, simulation, and prototyping. 4. Data analysis, exploration, and visualization. 5. Scientific and engineering graphics. 6. Application development, including graphical user interface building. MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar non interactive language such as C or FORTRAN. The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix. 1-2 Starting MATLAB: On Windows platforms, start MATLAB by double-clicking the MATLAB shortcut icon on Windows desktop. On UNIX platforms, start MATLAB by typing MATLAB at the operating system prompt. When you start MATLAB, the MATLAB desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. You will know MATLAB is running when you see the special ">>" prompt in the MATLAB Command Window. 1-3 Desktop Tools: 1. Command Window: Use the Command Window to enter variables and to run functions and M-file scripts. 2. Command History: Statements you enter in the Command Window are logged in the Command History. From the Command History, you can view previously run statements, as well as copy and execute selected statements. 3. Current Directory Browser and Search Path: MATLAB file operations use the current directory and the search path as reference point. Any file you want to run must either be in the current directory or on the search path. 4. Workspace Browser and Array Editor: The MATLAB workspace consists of the set of variables (named arrays) built up during a MATLAB session and stored in memory. You add variables to the workspace by using functions, running M-files, and loading saved workspaces. 1-4 Useful Hints: Note that MATLAB doesn't care about spaces, for the most part, and that multiplication takes precedence over addition. Note also MATLAB calls the result ans (short for answer) for both computations. As an alternative, the above problem can solve by storing information in MATLAB variables: 1-5 Simple Math: Just like a calculator, MATLAB can do simple math. If you simple type a statement and press Return or Enter, MATLAB automatically displays the results on screen. If you end the line with a semicolon ( ; ) MATLAB performs the computation but does not display any output. If a statement does not fit on one line, use "…", followed by Enter to indicate that the statement continues on the next line. Use the Cursor Keys (← → ↑ ↓) to recall previous commands. For example, pressing ↑ key ones recall the most recent command to the MATLAB prompt. In a similar manner pressing the ↓ key scrolls forward through command. At any time, the ← and → keys can be used to move the cursor within the command at the MATLAB prompt. 1-6 Quitting MATLAB: To quit MATLAB at any time, do one of the following: Click the close box in the MATLAB desktop. Select Exit MATLAB from the desktop file menu. Type quit at the Command Window prompt. Procedure: Ahmad goes to the library and buys 4 erasers at 25 dinners each, 6 memo pads at 52 dinners each, and 2 rolls of tape at 99 dinners each. How many items did Ahmed buy, and how much did they cost? In MATLAB, this can be solved in a number of different ways. First the mentioned calculator approach can be taken. Discussion: 1. On the command line enter a=125, b=25, c=60,then find the following; Sum= a +b + c Av= (a +b + c)/3 2. Clear c, and then find Sum and Av. 3. Press (up arrow key), what will the MATLAB recall. 4. MATLAB has a useful help system. Try help help to see how it works. 5. Type clc on the command line, what will you see. University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(2) Expressions Theory: Like most other programming languages, MATLAB provides mathematical expression, but unlike most programming languages, these expressing involve entire matrices, the building blocks of expressions are: 1. Variables. 2. Numbers. 3. Operators. 4. Functions. 2-1 Variables: A variable name must comply with following two rules: 1. It may consist only of the letters (a to z), the digits (0 to 9), and the underscore ( _ ). 2. It must start with a letter. A variable name may as long as you like, but MATLAB only remembers the first 31 characters. Example of valid variable names: r2d2 pay_day. Example of invalid variable names: 2a pay-day name$ -2a. A variable is created simply by assigning a value to it, e.g. a= 98 If you attempt to refer to a non-existent variable you may get the error message (Undefined function or variable). Enter two correct and uncorrected variable consist 4 characters. 9-2 Numbers: Numbers can be represented in MATLAB in the usual decimal form (fixed point), with an optional decimal point, e.g. 1.2345 -165 .0001 A number may also represent in scientific notation, e.g. 1.2345 × 10^9 may be represented in MATLAB as 1.2345e9. This is called floating point notation. On computers using standard floating point arithmetic, numbers are represented to approximately 16 significant decimal digits. The relative accuracy of numbers is given by the function eps, which is defined as the distance between 1.0 and the next largest number. Enter eps to see its value on your computer. It is very easy to handle complex numbers in MATLAB. The special value I and j stands for sqrt (-1), e.g. Z=2+3i Represents the complex number 2+3i (real part 2, imaginary part 3). Some examples of legal numbers are: 3 -99 0.0001 1.60210e-20 -3.14159 2-3 Arithmetic Operators: Operator's expressions use familiar arithmetic operators and precedence rules. Table (2-1) the arithmetic operators and precedence rules + ADDITION Subtraction * Multiplication / Division \ Left division ^ Power ' Complex conjugate transpose () Specify evaluation order 2-4 Function: MATLAB provides a large number of standard elementary mathematical function, including abs, sqrt, exp, and sin. Taking the square root or logarithm of a negative number is not an error; the appropriate complex result is produced many more advanced mathematical functions including Bessel and Gamma functions. Most of these functions accept complex arguments. For a list of elementary mathematical functions, type >> help elfun For a list of more advanced mathematical and matrix functions, type >> help specfun >> help elmat Some of the functions, like sqrt and sin are built in. they are part of MATLAB core so they are very efficient, but the computational details are not readily accessible. Other functions, like gamma and sinh, are implemented in M-files. Table(2-2) Several special functions provide values of useful constants. CONSTANT DESCRIPTION esp. Floating point relative accuracy ≈ 2.2204e-016 pi 3.1415926535897…. inf Infinity, e.g. 1/0 Nan Not-a-number e.g. 0/0 i Imaginary unit j Same as i realmax Largest positive floating point number realmin Smallest positive floating point number Write this equation using Matlab. 2 3 y= x^2 – x + sin x 1- Find the value of y. 2- Find the absolute value of y. 3- Find real and imaginary value of y. If X = 0, 4, -8, 4 ,5.8 5 Discussion: 1. State, giving reasons, which of the following are not valid MATLAB variable names: (a). `a`one (b). min*2 (c). info_ (d). _x_1 (e). pay_day 2. Decide which of the following numbers are not acceptable in MATLAB and state why not: (a). 9, 87 (b). -356231 (c). 3.57e-2 (d). 3,57e-7 (e). .0 3. Translate the following expressions into MATLAB: y (a) (b) p+ (c) ( x yz w u y ) z 4. write a MATLAB program to calculate the following expression: (a) z= 5x 2 y 2 , where x=2, y=4 (b) z= 4cos(x) + j6sin(x) , where x= /4 5. write a program to calculate x, where: x= b b 2 4ac 2a University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(3) Dimensional Array 3-1 Simple Arrays: To create an array in MATLAB, all you have to do is to start with a left bracket, enter the desired values separated by spaces or commas, and then close the array with aright bracket. Arrays can be entered in several different ways: - Entered by an explicit list of elements, - Generated by built-in statements and functions, - Created in M-files, - Loaded from external data files The following session is self explanatory, study it in detail. x= [2 6 12] x= 2 6 12 y= [3 5 1] y= 351 X=x.*y ans = 6 30 12 Example(1): If y= sin(x) , 0 ≤ x ≤ pi , compute the values of sin function over one-half of its period. >> x=[0 .1*pi .2*pi .3*pi .4*pi .5*pi .6*pi .7*pi .8*pi .9*pi pi] x= Columns 1 through 10 0 0.3142 0.6283 0.9425 1.2566 1.5708 1.8850 2.5133 2.8274 Column 11 3.1416 >> y=sin(x) y= Columns 1 through 10 0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.5878 0.3090 Column 11 0.0000 2.1991 0.8090 3-2 Array addressing: In MATLAB, the elements of an array are identified by their index using subscripts, e.g., x (1) Is the first element in x, x (6) is the sixth element in x, and so on. Example(2): >> x (3) ans = 0.6283 >> x (end) ans = 3.1416 Here MATLAB, function linspace is used cerate x.This function is described by: Linspace (first value, last value, number of values). 3-3 Array Orientation: ●Row vector: An array that contains one row and multiple columns. ● Column vector: An array that contains one column and multiple rows. One way to create column vector is to specify it element by element, separating values with semicolons (;) >> c= [1; 2; 3; 4; 5] c= 1 2 3 4 5 A row vector can be converted into a column, and vice versa, by transposition. This operation is performed in MATLAB by the apostrophe (‘). >> b=c' b= 1 2 3 4 5 3-4 Scalar array mathematics: Addition, subtraction, multiplication, and division by a scalar simply apply the operation to all the elements of the array: >> p= [2 3 4 7 11 13]; >> p-2 ans = 0 1 2 5 9 11 >> 2*p-1 ans = 3 5 7 13 21 25 Table (10-1) Element by Element Array Operations ELEMENT BY ELEMENT ARRAY OPERATIONS Operation Algebraic Form MATLAB Addition ai + bi a+b Subtraction ai - bi a-b Multiplication ai* bi a. * b Right division ai/bi a./b Left division bi ai a b bi Power a a.^b 3-5 Array – Array Mathematics: When tow arrays have the same length, addition, subtraction, multiplication and division, to all the elements of the array: >> p= [2 3 5 7 11 13]; >> n= [1 2 3 4 5 6]; >> p+n ans = 3 5 8 11 16 19 > p-n ans = 1 1 2 3 6 7 For the arrays p and n used above, their array multiplication, indicated in MATLAB by (.*) > p.*n ans = 2 6 15 28 55 78 Array division, or dot division, also requires use of the dot symbol: > p./n ans = 2.0000 1.5000 1.6667 1.7500 2.2000 2.1667 Try to enter array below a described and writ some statements to find the sum, difference, product and quotient of a and b: A = 4 -6 2.6 5 B = 13 9 -4 -1.2 Discussion: 1- If a = 1:5, b = 1:2:9, create an array c composed of elements of b followed by those of a. 2. For the same values of a and b mentioned above, create an array d composed of the first, third, and fifth element of a followed by three additional elements. 3- Generate the following row vector: b = [1, 2, 3, 4, 5….9, 10], then transpose it to column vector. 4- If x= [2 3 -1], then a- Add 1 to each element of x. b- Multiply each element of x by 3. 5- Apply addition, subtraction, multiplication, and division operation on the following vectors, x = [4 8 10 12], y =[2 4 5 6]. University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(4) Working with Matrices 4-1 Entering Matrices: Matrices can be entered in several different ways: Entered by an explicit list of elements, or built from blocks. For example, A=[1 4 6; 2 1 8; -2 7 -9]; B = [A, ones (3, 2); zeros (2, 3), eye (2)]} Will build a 5-by-5 matrix. Generated by built-in statements and functions, ones(m,n) produces an m-by-n matrix of ones; if A is a matrix, then ones (A) produces a matrix of ones of the same size as A. If x is a vector, diag(x) is the diagonal matrix with x down the diagonal; if A is a square matrix, then diag(A) is a vector consisting of the diagonal of A. Created in M files. Loaded from external data files. A matrix may be thought of as a table consisting of rows and columns. You can enter a matrix just as you do a vector, except that a semi-colon is used to indicate the end of a row, e.g. >> a= [1 2; 3 4] a= 1 2 3 4 Big matrices can be constructed from smaller .e.g. >> x= [5 6]; >> a= [a; x] a= 1 2 3 4 5 6 Instead of a semi-colon, you can use a line-feed (Enter) to indicate the end of a row. 4-2 Subscripts: Individual elements of a matrix are referenced with two subscripts, the first for the row, and the second for the column, e.g. a (3, 2) for an above returns 6. Alternatively, and lees commonly, a single subscript may be used. In this case you can think of the matrix as being (unwound) column by column. So a (5) for the above example returns 4. 4-3 transpose: The statements >> a=[1:3;4:6]; >> b=a' b= 1 4 2 5 3 6 The transpose operator (‘) turns rows into columns and voice versa. 4-4 The colon operator: The colon operator is extremely powerful, and provides for very efficient ways of handling matrices, e.g. if a is the matrix >> a= [1 2 3; 4 5 6; 7 8 9] a= 1 2 3 4 5 6 7 8 9 The statement >> a (2:3,1:2) ans = 4 5 7 8 Returns second and third rows, first and second columns. The statement >> a (3,:) ans = 7 8 9 Returns third row. And the statement >> a(1:2,2:3)=ones(2) a= 1 1 1 4 1 1 7 8 9 Essentially, what is happening in the above examples is that the colon operator is being used to create vector subscripts. However a colon by itself in place of a subscript denotes all the elements of the corresponding row or column. So a (3, :) means all elements in the third row. The colon operator may be used as a single subscript, in which case it behaves differently if it is on the right- hand or left- hand side of an assignment. On the right- hand side of an assignment, a (:) gives all the element of a strung out by columns in one long column vector, e.g. if >> a= [1 2; 3 4] a= 1 2 3 4 .The statement >> a= [1 2; 3 4]; >> b=a (:) b= 1 3 2 4 However on the left- hand side of an assignment, a(:) reshapes a matrix. A must already exist. Then a(:) denotes a matrix with same dimensions (shape) as a, but with new contents taken from the right- hand side. In other words, the matrix on the right- hand side is reshaped into the shape of a on the lefthand side. If >> b= [1 2 3; 4 5 6] b= 1 2 3 4 5 6 And >> a= [0 0; 0 0; 0 0] a= 0 0 0 0 0 0 The statement >> a (:)=b a= 1 5 4 3 2 6 (The contents of b are strung out into one long column and then fed into a by columns). As another example, the statement >> a (:)=1:6 a= 1 4 2 5 3 6 (With a as above) results in Reshaping can also be done with the reshape function. 4-.5 Array operation on matrices: The array operations discussed in experiment No.3 all apply to matrices as well as vectors. For example, if a is a matrix, then a.*2 multiplies each element of a by 2 >> a= [1 2 3; 4 5 6]; >> a.*2 ans = 2 4 6 8 10 12 The statement >> a.^2 ans = 1 4 9 16 25 36 If h= [1 1 1; 2 2 2], then a.*h results >> h= [1 1 1;2 2 2]; >> a.*h ans = 1 2 3 8 10 12 The statement >> a./h ans = 1.0000 2.0000 3.0000 2.0000 2.5000 3.0000 Array multiplication and division require use of the dot symbol. Multiplication without the dot signifies matrix multiplication. 4-6 Matrix operations: We have seen that array operations are performed element by element on matrices. However, matrix operations, which are fundamental to MATLAB, are defined differently in certain cases, in the mathematical sense. Matrix addition and subtraction are defined in the same way as the equivalent array operations, i.e. element by element. Matrix multiplication is quite different. 4-6-1 Matrix multiplication: Matrix multiplication is probably the most important matrix operation. Hs used widely in such areas as network theory, solution of linear system equation. When tow matrices A and B are multiplied together in this sense, their product is a third matrix C. The operation is written as: C = AB Example(1): >> a= [1 2; 3 4]; >> b= [5 6; 0 -1]; >> c=a*b c= 5 4 15 14 Note the difference between array a.*b and the matrix operation a*b. 4-6-.2 Matrix exponentiation: The matrix operation a^2 means a*a, where a must be a square matrix. The operator ^ is used for matrix exponentiation, e.g. if >> a= [1 2; 3 4]; >> a^2 ans = 7 10 15 22 Which is the same as a*a (try it). 4-7 Linear Equations: A problem that often arises in scientific applications is the solution of a system of linear equations, e.g. 3x + 2y – z = 10 - x + 3y +2z = 5 x – y - z = -1 MATLAB was designed to solve a system like this directly and very easily as follows. If we define the matrix A as: A=[3 2 -1;-1 3 2;1-1-1], and the vectors x and b as x=[x; y; z],b= [10; 5; -1], we can write the above system of three equation in matrix from as Ax=b MATLAB solution To see how MATLAB solve the above equations >> a= [3 2 -1;-1 3 2; 1 -1 -1]; >> b= [10 5 -1]; >> x=a\b This should result in x= -2.0000 5.0000 -6.0000 In term of our notation, this means that the solution is x = -2, y = 5, z = -6. 4-8 Matrix Functions: In addition to the solution of linear sets of equations, MATLAB offers numerous matrix functions that are useful for solving numerical algebra problems. A brief description of many of the matrix functions follows. For further information, use on-line help. Table (4-1) a brief description of many of the matrix functions COMMAND DESCRIPTION max(x) >> x=[1 4 8;2 5 9]; >> max(x) ans = 2 5 9 >> max(max(x)) ans = 9 min(x) >> x=[1 4 8;2 5 9]; >> min(x) ans = 1 4 8 >> min(min(x)) ans = 1 Find the largest element in a matrix or a vector Ones (N) Ones (N, M) >> ones(3,4) ans = 1 1 1 1 1 1 1 1 1 1 1 1 Produce N by N matrix of ones Produce N by M matrix of ones diag (x) >> x=[1 4 8;2 3 9; 6 4 10]; x = [1 4 8 2 3 9 6 4 10 ] >> diag(x) ans = 1 3 10 Return the diagonal of matrix x. sum(x) >> x=[1 4 8;2 5 9]; >> sum(x) ans = 3 9 17 >> sum(sum(x)) ans = 29 The sum of the elements of x. For matrices, sum (x) is a row vector with the sum over each column. size(x) >> x=[1 4 8;2 5 9]; >> size(x) ans = 2 3 Return the size (dimensions) of matrix x. Find the smallest element in a matrix or a vector. prod(x) >> x=[1 4 8;2 5 9]; >> prod(x) ans = 2 20 72 >> prod(prod(x)) ans = 2880 Product of the elements of x. For matrices, prod(x) is a row vector with the product over each column. Zeros(N), Zeros(N,M) >> zeros(3,4) 0 0 0 0 0 0 0 0 0 0 0 0 Produce N by N matrix of zeros Produce N by M matrix of zeros inv (x) >>x=[1 3;4 2]; >> inv (x) ans= -0.2000 0.3000 Produce the inverse of matrix x. Discussion: 1- If x= [2 8 5 ; 9 7 1 ], b= [2 4 5 ], then a) Add the vector b as a third row to x. b) Find the maximum and minimum element of x. 2- Solve the following system: x + y – 2x = 3 2x +y = 7 x+y–z=4 3- If x= [1 4 ; 8 3 ], then find: a) The inverse matrix of x. b) The diagonal of x. c) The sum of x. d) The transpose of x. 4- If a= [0 0 0;0 0 0], b= [2 4 ; 8 10 ; 6 12 ], then reshape b into the shape of a. 5- If a= [-2 1 ; 3 5 ], b= [6 7; 0 -1 ], find ? a) a.*b b) a*b University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(5) Dimensional Graphics Theory: One of the major strength of MATLAB is its graphics capabilities. They are numerous, and only few will be explored at this early stage. MATLAB can produce both planar plots and 3-D mesh surface plots. To preview some of these capabilities enter the command plot demo. The plot command creates linear x-y plots; if x and y are vectors of the same length, the command plot(x,y) opens a graphics window and draws an x-y plot of the elements of x versus the elements of y. Table(5-1) 2D Graphics Commands TITLE GRAPH TITLE xlabel x-axis label ylabel y-axis label gtext interactively-positioned text text position text at specified coordinates Graphs plot linear X-Y plot loglog loglog X-Y plot semilogx semi-log X-Y plot semilogy semi-log X-Y plot polar polar plot bar bar charts stairs stairstep graph errorbar add error bars Graph Annotation title plot title xlabel x-axis label ylabel y-axis label grid draw grid lines text arbitrarily position text gtext mouse-positioned text ginput graphics input Graph Window Control axis manual axis scaling hold hold plot on screen shg show graph window clg clear graph window subplot split graph window A- Two Dimensional Graphics: 5-1 Using the plot command:The most common command for plotting tow –dimensional data is the plot command. This versatile command plots sets of data arrays on appropriate axes, and connects the points with straight lines, e.g. >> x=linspace(0,2*pi,30); >> y=sin(x); >> plot(x,y) set This example cerates 30 data points over 0< x>2pi to from the horizontal axis of the plot, and creates anther vector y containing the sine of the data points in x. The plot command opens a graphics window, called a figure window, scales the axes to fit the data, plots the points, and then graphs the data by connecting the points with straight lines. It also adds numerical scales and tick marks to the axes automatically. If a figure window already exists, plot clears the current figure window and draws a new plot. You can plot more then one of at the same time, just by giving plot anther pair of arguments, e.g. plotting a sin and cosine on the same plot. >> z=cos(x); >> plot(x,y,x,z) When the plot command is called with only one argument, e.g. plot (y), the Plot function acts differently, depending on the data contained in y. >> plot(y) 5-2 Line Style, Marker, and Colors: In the previous example, MATLAB the solid line style, and the colors blue and green for the plots. You can own colors, marks, and the line style by giving plot a third argument after each of data arrays. This additional argument is a character string consisting of one more characters from the following table (Table (5-2)): Table(5-2)the colors, marks, and the line style SYMBOL COLOR SYMBOL MARKER SYMBOL LINE STYLE b Blue . Point - Solid line g Green O Circle : Dotted line r Red X x- mark - Dash-dot line c Cyan + Plus -- Dashed line m Magenta * Star y Yellow S Square k Black D Diamond w White V Triangle down ^ Triangle up Here is an example using different line style, color, and point mark: 5-3 Plot Grids, Axes Box, and Labels The grid on command ( ) adds grid lines to the current plot at tick mark. The grid off command ( ) removes the grid. Grid with no arguments alternately turns them on and off, i.e. toggles them. Normally two dimensional axes are enclosed by solid lines, called an axes box. This box can be turned off, with box on restore the axes box. The box command toggles the state of the axes box. x label command ----- labels the x- axis. y label command----- labels the y- axis . The title command --- adds a line of text at the top of the plot. Example: >> x=linspace(0,2*pi,30); >> y=sin(x); >> z=cos(x); >> plot(x,y,x,z) >> box off >> label('independent variable') >> ylabel('dependent variables y and z') >> title('sin and cosine carve') Now remove the axes box, and add a plot title axis labels: The text command ---- adds a label or any text to any specific on your plot. The format is text (x,y,’string’),to add a label identifying the sin curve at the location (2.5, 0.7): > grid on, box on >> text (2.5,.7,'sin(x)') 5-4 Adding plot to an existing graph : The hold command ----enables you to add an existing graph. When you type hold on MATLAB dose not replace exiting graph when you issue anther plotting command, it adds the new data to the current graph, rescaling the axes if necessary. >> x1=0:pi/100:2*pi; >> x2=0:pi/10:2*pi; >> plot(x1,sin(x1),'r:') >> hold on >> plot(x2,cos(x2),'r+') 5-5 Multiple plots in one figure: The subplot command---- enables you to display plot in the same window or print them on the same piece of paper. Typing Subplot (m,n,p) subdivide the current window into an m- by – n matrix of plotting areas, and choose the path area to be active. The subplots are numbered left to right along the top row, then the second row, and so on. For example > x=linspace(0,2*pi,30); >> y=sin(x); >> z=cos(x); >> a=2*sin(x).*cos(x); >> b=sin(x)./cos(x); >> subplot(2,2,1);plot(y) >> subplot(2,2,2);plot(z) >> subplot(2,2,3);plot(a) >> subplot(2,2,4);plot(b) B- Three Dimensional Graphics: 5-6 Line plots: The plot command for the tow – dimensional world can be extended three dimensions with plot3. The format is the same as in the tow dimensional plot, except the data are in triples rather then in pairs. The generalized format of plot3 is: Plot3(x1,y1,s1,z1,x2,y2,s2,….) Where x,y, and z are vectors or matrices, and s is optional character strings specifying color, marker symbol, or line style. An example of a three – dimensional helix: >> t=linspace(0,10*pi); >> plot3(sin(t),cos(t),t); >> title('helix'),xlabel('sin(t)'),ylabel('cos(t)'),zlabel('t') 5-7 Mesh and surface plots: >> y=x; >> [x y]=meshgrid(x,y); >> z=x.^2-y.^2; >> mesh(z) MATLAB defines a mesh surface by the z-coordinates of points above a rectangular grid in the x-y plan. It forms a plot by joining adjacent lines. Mesh plots are very useful for visualizing large matrices or for plotting functions of tow variables. The first step in generating the mesh plot of a function of two variable=f(x,y), is to generator x and y matrices consisting of repeated rows and columns, respectively, over some range of variables x and y .MATLAB provides the function (mesh grid)for this purpose. [x,y] = meshgrid (x,y) creates a matrix X whose rows are copies of the vector x, and a matrix Y whose columns are copies of vector y. This pair of matrices may then be used to evaluate functions of tow variables using MATLAB array mathematics features. Here is an example: >> x=0:5; >> y=x; >> [x y]=meshgrid(x,y); >> z=x.^2-y.^2; >> mesh(z) Another example, drawing the Mexican hat: >> [x y]=meshgrid(-7.5:.5:7.5,-7.5:.5:7.5); >> r=sqrt(x.^2+y.^2)+eps; >> z=sin(r)./r; >> mesh(z) Discussion: 1. If 0 ≤ x ≥ 2Π, y=sin(x), z=2cos(x), n=y+z, then a) plot(x,y,x,z) using different line style, colors and point mark. b) Add n to the current graph. c) plot grids, axes box and labels to the total graph. 2. For the same data given in(1) use the plot command for three dimensions (y,z,n),and repeat step (c). 3. If t = 0:pi/10:2*pi, x = sin(t) , y = 2 cos(t) z = 2y – 3x , v=5+z Then writ a program that displays these four plots in the same window. 4. If x = 0:6, y = x, z= x² + y² write a program to generator the mesh plot of (z). University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment NO.(6) Relation and Logical Operations Theory: MATLAB supports relational and logical operations. The purpose of this operations and functions is to provide answers to True-False questions. One important use of this capability is to control the flow or order of execution of a series of MATLAB commands (usually in an M–file) based on the results of true/ false questions. As inputs to all relational and logical expressions, MATLAB considers any nonzero number to be true, and zero to be false. The output of all relational and logical expressions produces one for True and zero for false, and the array is flagged as logical. That is, the result contains numerical values 1 and 0 that can be used in mathematical statement, but also allow logical array addressing. 6-1 Relational Operations: Table(6-1) the relational operations OPERATION OPERATION == ~= < > <= >= Equal Not equal Less than Greater than Less than or equal Greater than or equal Example(1): Find the values greater || than 4, and print b? If a=1 to 9, b= 9-a a=1:9; b=9-a; >> t=a>4 t= 0 0 0 0 1 1 >> b=9-a b= 8 7 6 5 4 3 6-2 Logical Operation: 1 1 1 2 1 0 Table(6-2) the logical operations OPERATION & | ~ Xor (a,b) OPERATION Logical AND Logical OR Logical NOT Logical EXCLUSIVE OR Example(2): If x= [2 -3 5; 0 11 0], then: a) Find elements in x that are greater than 2. b) Find elements in x that are greater than or equal 11. Solution: a) >> x= [2 -3 5; 0 11 0]; >> x>2 ans = 0 0 1 0 1 0 b) >> x>= 11 ans = 0 0 0 0 1 0 Procedure: Write a program to then compute: a) b² < 4ac. b) X ≥ 0 . c) b² = 4+ac-5a. d) b² - 4ac = o and ≠ 0. e) U = not z and y. f) V =( x )and not (y )or not (x )and y) Discussion: 1a) b) c) If q= [ 1 5 6 8 3 2 4 5 9 10 1 ], x= [3 5 7 8 3 1 2 4 11 5 9 ], then: Find elements of q that are greater than 4. Find elements of q that are equal to those in x. Find elements of x that are less than or equal to 7. 2- If x= [10 3; 9 15], y= [10 0; 9 3], z= [-1 0;-3 2], what is the output of the following statements: a) v= x >y b) w= z >= y c) u= ~z & y d) t= x & y < z 3- Write a program to read three bits x, y, z, then compute: a) v= (x AND y) OR z. b) w= NOT (x OR y) AND z. c) u= (x AND NOT (y)) OR (NOT (x) AND y). University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(7) Introduction to Control Systems Analysis and Design Using Matlab and Simulink 7-1 Introduction: Matlab is powerful computing system for handling the calculations involved in scientific and engineering problems. The name Mat lab stands for Matrix Laboratory, because the system as designed to make matrix computations particularly easy. In this experiment the simulation program SIMULINK will be introduced as well, it is an extension to Mat lab that enables the user to simulate dynamic systems quickly and effectively. Using block diagram windows, you can create and edit models manipulating (principally with mouse driven commands) models components. Such as scopes and signal generators, and helps to develop our intention. 7-2 control Systems Analysis Using Mat lab Work Space: Matlab provides many useful facilities theory applications. Both time response and frequency can be demonstrated using package for (continues and discrete) – time systems resonated by transfer function, state- space or pole/zero configuration. A transfer function can be written by entering the numerator and denominator coefficients in descending order. Example(1): the following transfer will be written as: G(s)= s 1 s 3s 2 2 >> n=[1 1]; >> d=[1 3 2]; >> sys=tf(n, d) Example (2): 20( s 3) G(s)= ( s 2)(s 5) >> Sys=zpk([-3],[-2 5],[20]) Zero/pole/gain: 20( s 3) ( s 2)(s 5) 7-3 Time Response a- Root locus: 1- The root locus will be calculated by: >> R = rlocus(num,den, k) , where k is a vector that contains the range of gain specified by the user. 2- To plot the root locus >> plot (R, "x"). Where the closed loop roots are indicated by the symbol " x". b- Step response: 1- the step response will be calculated by: >> y = step(num,den,t). Where t is a vector contains regularly spaced instants. 2-plot(Y) Example(3): plot the root locus and step response for the : G(s) = s 1 s 2s 2 2 3 sol: >> n = [1 1]; >> d = [1 2 0 2]; >> sys= tf (n,d) >> rlocus(sys) >> impulse(sys) >> bode(sys) >> nyquist(sys) Discussion: Plot the root locus, response and bode for the following: 1. G ( s ) 4( s 1) s3 2s 2 2 2. G( s) 2 ( s 2)(s 2) 3. G ( s ) ( s 1)(4 s ) 2s 3 2s 2 University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(8) First- order systems Theory: Consider the first-order system shown in Fig (8-1) this system may represent an RC circuit, thermal system, or the like. A simplified block diagram is shown in Fig (8-2). The input-output relationship is given by Eq. (1): C ( s) 1 R( s) TS 1 .............(1) Fig(8-1) Fig (8-2) In the following, we shall analyze the system responses to such input as the unit-step, unit-ramp, and impulse function. This initial condition is assumed to be zero. Unit-step response of first – order systems: Since the Laplace transform of the unit-step function is 1/ S, substituting R(s) = 1 S ……………….(2) Into Eq. (1), we obtain C(S) = 1 1 * TS 1 S ……………. .(3) Taking the inverse Laplace transforms Eq. (3), we obtain C(t) = (1- e ( t / T ) ) , for t >0 ………………… (4) Eq. (3) states that initially output C (t) is zero finally it become unity. One important characteristic of such expontial curve C (t) is that at t = T the value of is 0.632, or the response C (t) has reached 63.2 ٪of its total change. Unit- ramp response of first order systems: Since the Laplace transform of the unit- ramp function is output of Fig (8-1) as: 1 , we obtain of S2 C(s) = 1 1 * 2 TS 1 S ........ .….… (5) Taking the inverse Laplace transform of Eq. (5) we obtain ( t / T ) C (t) = t –T+T * e , for t ≥ 0 ..............(6) The error signal e (t) is then e (t) = r (t) – c (t) ( t / T ) = T (1- e ) ..........(7) Unit – impulse response of first – order systems: For the unit – impulse input, R(s) = 1 and the output of the system of (8-1) can be obtained as: C(s) = 1 TS 1 or C (t ) 1 ( t / T ) e , T Fig for t ≥ 0 ................(8) Procedure: 1. Build the system as shown below in Fig (8-3) with k=(1,2,0.5). 2. For a step input having step time (1), initial value (0), final value (1), obtain the system response and plot it. 3. Repeat step 1 for a unit – ramp input. 4. Repeat step 1 for a unit impulse of period 3 sec, pulse width 0.01٪ and an amplitude of 10. 5. Repeat step1 in case the system close loop. Fig (8-3) Discussion: 1. For the unit step response curve in step (3) in procedure, explain the important characteristic of such an exponential curve? 2. From step (3) determine the value of e (t) when (t) approaches infinity? 3. what is the effect of the given variable value of the gain on the response and stability of the system? University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment NO.(9) Steady State Error Analysis Theory: The Steady – State error in controlled system indicates the goodness of the controller Fig (9-1) shows the block diagram for closed loop control system. Fig (9-1) Block diagram for closed loop control system. If the closed loop control system output signal C(s) dose not follow the changes of input reference R(s) the error signal E (s) is indicated. E(s) = R(s) – B(s) ……… B(s) = C(s) H(s) ……… (1) (2) Substituting for B(s) in (1) from (2) then E(s) = R(s)- C(s) H(s)……… (3) C(s) = E(s) G(s) ……… (4) Where From (3) and (4) the transfer function becomes C(s) G(s) ─── = ─────── …. (5) R(s) 1 + G(s) H(s) Then we can find that E(s) 1 ─── = ──────── …. (6) R(s) 1+ G(s) H(s) Table (9-1) shows the steady state error in terms of gain K. INPUT Type of Sys. Type 0 system Type 1 system Type 2 system STEP INPUT R(T) = 1 RAMP INPUT R(T)= T ACCELERATION INPUT R(T)= T^2 1/(1+Kp) 0 0 Infinity 1 /Kv 0 Infinity Infinity 1/Ka Where: The error coefficient Kp, Kv, Ka describes the ability of system to reduce or eliminate the Steady – State error. Therefore they are indicative of steady state performance. By using Matlab and Simulink the transfer function can performed to represent the system response to step input in personal computer as shown in Fig(9 - 2)for type zero, Fig(9-3)for type one and Fig(9-4) for type tow. Fig (9-2) Matlab and Simulink representation for type zero. Fig (9-3) Matlab and Simulink representation for type one. Fig (9-4) Matlab and Simulink representation for type tow. Procedure 1- For the block diagram of Fig (9-2), (9-3) and (9-4) show the output response y (t) for a unit step input on personal computer Matlab and Simulink. 2- Repeat step 1 for a ramp input. Discussion 1- Derive the transfer function of Fig (9-2), (9-3) and (9-4). 2- Find the steady state error for fig(9-2), (9-3) and (9-4) a unit step, ramp input. 3- Compare the results obtained with the Theatrical results. University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(10) SECOND – ORDER SYSTEMS Theory: The closed – loop transfer function C(s) / R(s) can be written C ( s) Wn 2 R( s) S 2WnS Wn2 The dynamic behavior of second – order systems can then be described in term of two parameters zeta and . If 0 < zeta< 1, the closed – loop poles are complex conjugate and lie in the left – half s plane. The system is then called under damped, and the transient response is oscillatory. If zeta = 1, the system is called critically damped. Over damped systems Corresponds to zeta > 1. The transient responses of critically damped and over damped systems do not oscillate. If zeta = 0, the transient response dose not die out. 1. The under damped (0< ξ < 1). 2. Critically damped (ξ = 1). 3. Overdamed (ξ> 0). Type, order of any control system: Fig (10-1) This sys. Type = 0, 1st order. Fig (10-2) This sys. Type = 1,2nd order. Fig (10-3) This sys. Type = 3 rd order. Procedure: 1. Build the sys. As shown Fig(10-4) below for the values of A=1 A=4 A=5 Fig (10-4) G(s) = 2 2 S AS 2 H(s) = 1 a. find the response of the sys. When the input unit Step &commend on the response of the system for different value of ξ ? b. find the steady state error (ess)? ess= Lim e(t) = Lim SE(s) , t s0 E ( s) R( s ) 1 G( s) H ( s) Discussion: 1. Find the output response for the sys. Fig (10-5)? Fig (10-5) If R(s) = unit impulse K= 10 K= 5 2-Built the system as shown in figure below if the input is a unit ramp as a function of time. & find (Ess) Fig (10-6) University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No. (11) Root locus plot Theory: A root locus plot is simply a plot of the zero values and the poles on a graph with real and imaginary coordinates. The root locus is a curve of the location of the poles of a transfer function as some parameter is varied. Such a plot shows clearly the contribution of each open loop pole or zero to the locations of the closed loop poles. This method is very powerful graphical technique for investigating the effects of the variation of a system parameter on the locations of the closed loop poles. The close loop poles are the roots of the characteristic equation of the system while the locus of the roots as the gain varies from zero to infinity. From the design viewpoint, in some systems simple adjustment can move the closed loop poles to the desired locations. Root locus are completed to select the best parameter value for stability. A normal interpretation of improving stability when the real part of a pole is further left the imaginary axis. A control system is often developed into an equation as shown below Y ( s) N ( s) F ( s ) ………….. U ( s) D( s) K .( s z1)(s z 2)....( s z m) F ( s) ( s p )(s p )(s p ).......( s 1 2 3 (1) p) …………. (2) n N(s=(s- z1 )(s- z2 )…..(s- zm )……………(3) D(s)=(s- p1 )(s- p 2 )(s- p 3 )…….(s- p n )………. F(s) = 0 when s = z1 , z2 …… zm F(s = when s = p1 , p2 , p3 ....... pn (4) , where n > m A typical feedback system is shown in Fig (11– 1). Fig (11-1) block diagram of feedback control system The open – loop transfer function between the input R(s) and the measured output Y(s) is: T(s) = K. G(s) H(s)…………. (5) The closed – loop transfer function is: C ( s) K .G ( s ) ……………………… R( s ) 1 K .G ( s ) H ( s ) If C (s) then R(s) K (6) K.G(s) H(s) = -1 1 ......................................... G ( s) H ( s) (7) It can be written as: 0 KG ( s ) H ( s ) Odd multiples of 180 …… (8) Example (1): For a closed loop system 1 G(s) = ——— H(s) =1 S(s + 2) The root locus plot can be obtained equation: s² + 2s + k = 0 The root of the characteristic equation: S = -1 1 k when k = 0 the poles at when k = 1 the poles at when k = ∞ from the closed loop characteristic s = 0 , s = -2 s = -1 s = -1 ± j∞ The relevant root locus is as shown in Fig (11-2) Fig (11 - 2) The relevant root locus. The system is stable for all values of k. Example(2): For a closed loop system G(s) = 2S s 2 H(s) = 1 1 The root locus plot can be obtained from the characteristic equation: s 2 2Ks 1 0 The root of the characteristic equation: s K k 2 1 when k = 0 when k = 1 when k = ∞ the poles at the poles at s= - ∞ s = + j , s = -j s = -1 s=0 The relevant root locus is as shown in Fig (11-3). Fig (11- 3) The relevant root locus. The system has stability point at k = -1, at values below this root loci moves towards the instability boundary. Procedure: Using Matlab and simulation to draw the root locus for the following transfer function: K (s+ 2) G(s) H(s) = ——————— (s+ 1.5)(s + 2) Use the instruction: num = [1 2]; den = conv [1 1.5] , [1 2] ; rlocus (num, den) Discussion: 1. What is the type and order of the system? 2. From the simulated obtained is the system stable. 3. Draw the theoretical (asymptotic only) polar plot of the open loop system and compare it with simulated result. 4. What are the advantages of polar plot method? University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(12) State space Representation Theory: In conventional control theory, only the input, output and error signals are considered important. The analysis and design of control system are carried out using transfer function, together with a variety of graphical techniques such as root Locus plot and Nyquist plots. The unique characteristic of conventional control theory is that it is based on the inputoutput relation of the system, or the transfer function .The main disadvantage of conventional control theory is that it is applicable only to linear time invariant systems having. A single input and a single output. It is powerless for time – varying systems, nonlinear systems (except simple ones), and multiple – input –multiple – output systems. Thus conventional techniques (the root Locus and frequency – response methods) do not apply to design of optimal and adoptive control systems, which are mostly time – varying and / or nonlinear. The modern trend in engineering systems is toward greater complexity, due mainly to requirements of complex tasks and good accuracy. Complex systems may have multiple input and multiple outputs and may be time – varying, because of the necessity of meeting increasingly stringent requirements on the performance of control systems, the increase in system complexity, and easy access to large – scale computers, modern control theory, which is a new approach to the analysis and design of complex control systems. This new approach is based on the concept of state. So we must define stats variables, state vectors and state space. State Variable: The state variable of a dynamic system are the smallest set of variables which determine the state of the dynamic system. If at least n variable X 1(t), X2(t)…….., Xn (t) are need to completely describe the behavior of a dynamic system (such that once the input is for t>>t o and the initial at t = to is specified, the future state of the system is completely determined), then such n variable X1(t), X2(t),…..Xn (t) are a set of state variables. State: The state of dynamic system is the smallest set of variables (called state variables) such that the knowledge of these variables at t=t o, together with input for t>=to, completely determines the behavior of the system for any time t>= to. Thus, the state of a dynamic system at time t is uniquely determined by the state at time to and the input for t>= to and it is independent of the state and input before (to). Notice that, in dealing with linear – invariant systems, we usually choose the reference time (to) to be zero. State Vector If n- state variables are needed to completely describe the behavior of a given system, then these n- state variables can be considered to be n components of a vector X (t). Such a vector is called a state vector. A state vector is thus a vector which determines uniquely the system stet X(t) for t>= to: once the input u (t) for t>= to is specified. State Space: The n- dimensional space whose coordinate axes consist of the axis X1 axis, X2 axis, …Xn axis is called a state space. Any state can be represented by a point in the state space. Example: Consider the system defined by y’’’+ 6y’’+11y’+6y=6u where (y) is the output and (u) is the input of the system. Obtain a state space representation of the system? Solution: Let use choose the state variable as Then we obtain By using vector – matrix notation, we get …………………(1) And ………………….(2) Equation (1) & (2) can be put in standard from as Where Fig.(12-1) Shows the diagram representation of the present state equation and output equation. Fig.(12-1) Block diagram representation of the system described by equation (1) and (2) Procedure: 1- Build the circuit of Fig (12-1). 2- Sketch the response of the circuit of Fig (12-1) for a unit step input. Discussion: Find the output y(t) for the system represented by the differential equation (y’’’+6y’’+6y=6u) , analytically . Assume that all initial conditions are zero . University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No. (13) Discrete – Time Systems-@the Z- Transform Technique Theory: Discrete-time systems, or Sampled-data system, are dynamic-systems in which one or more variable can change only at discrete instants of time, which we shall denote by KT or k (k=0, 1, 2…), may specify the time at which some physical measurement is performed or the time which the memory of a digital computer is real out. Discrete- time system differ from continuous – time ones in that the signals for a discrete – time system are in sampled- data form. Discrete – time systems arise in practice whenever the measurements necessary for control are obtained in an inter fashion, or a large scale controller or computer is time- shared by several plants so that a control signal is sent out to each plant only periodically or whenever a digital is perform .Computations necessary for control many modern industrial control systems are discrete – time systems since they invariably include some elements whose inputs and/or outputs are discrete in time. Fig (13-1) The Z- Transformation The z – transform method for treating discrete – time function. Since discrete - -time function arise when continuous signal are sampled, X * (t ) x( KT )(t KT ) ............... (1) K 0 Now we shall define the z – transform .Taking the Laplace transform of Eq (1). We obtain. X (s) = £[ x*(t)] = ( KT )e K 0 KTs …….(2) Define Z=e Since: Ts …… (3) S: is a complex variable. T: time 1 S ln Z .............. (4) T 1 X(Z) = X*(S) =X* ( )= T ln Z X (KT )Z K K 0 …..(5) Example: Find the Z Transforms of the unit – step by using Eq (5). Solution: Z[1(t)] = X ( KT )Z K K 0 -1 -2 = 1 + Z + Z + ….. = Z Z 1 Procedure: Build the model as shown Fig (13 - 2) Fig (13 - 2) For the block diagram of Fig (13 - 2) show the output response C (z) and C(s) for a unit step input on personal computer Mat lab Simulink. Compare between the C (z) and C (s). Build the model as shown Fig (13 - 3) and find response for a unit step input. Fig (13-3) Compare between steps (1) & step (3). Discussion: 1- Solve the following difference equation by using the z- transform method. x (k+2) +3x (k+1)+2x (k) = 0 x (0 ) = 0 , x (1) = 1 2- Explain the difference between continues and discrete systems. University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(14) The Zero−Order Hold and First−Order Hold as Reconstruction Theory: In some cases you need to find a discrete-time z-transfer function from a given continuous-time s transfer function: In accurate model based design of a discrete controller for a process originally in the form of a continuous-time s transfer function, Hp(s). The latter should be discretized to get a discrete-time process model before the design is started. Implementation of continuous-time control and filtering functions in a computer program. The methods can be categorized as follows and the described in the following sections; Discretization based on having a zero order hold element on the input of the system. This method should be used in controller design of a process which has a sample and hold element on its input, as when a physical process is controlled by a computer via a D/A converter (digital to analog). Zero order hold means that the input signal is held constant during the time-step or sampling interval. Figure (14-1) shows a block diagram of a continuous-time process with transfer function model G(s) having a zero order hold element on its input. Fig (14-1) Block diagram of a process having a zero order hold element on its input. uh is the piecewise constant (held) input signal. The discretization can be realized in several ways: (a) By calculating the z-transfer function for G(s) with a zero order hold element on its input. (b) By first deriving a canonical continuous-time state space model corresponding to G(s), and then discretizing this state space model assuming a hold element on its input. 14-1 The Zero−Order Hold: The zero-order hold (ZOH) is a mathematical model of the practical signal reconstruction done by a conventional digital-to-analog converter (DAC). That is, it describes the effect of converting a discrete-time signal to a continuous-time signal by holding each sample value for one sample interval. It has several applications in electrical communication. Block samples and holds its input for the specified sample period. The block accepts one input and generates one output, both of which can be scalar or vector. If the input is a vector, all elements of the vector are held for the same sample period Figure (14-2) show us model for a Zero-Order Hold. Fig (14-2) Model for a Zero-Order Hold 14-2 The First-Order Hold: Block implements a first−order sample−and−hold that operates at the specified sampling interval. In some signal processing applications it is necessary to retain (hold) the value that a signal has at a specified instant of time Figure (14-3) show us model for a First-Order Hold. Fig (14-3) Model for a First-Order Hold 14-3 Analog−to−Digital Conversion: One of the recently added Simulink blocks is the Idealized ADC Quantizer. Figure(14-4)shows how this block can be used to discretize a continuous−time signal such as a clock. The Function Block Parameters dialog box provides a detailed description for this block. Fig (14-4) Model for Model for Analog−to−Digital conversion Procedure: 1- Create a model using a First−Order Hold block with sample time 0.5 sec where the input is a sine wave with amplitude(1), and frequency 1HZ. The model is shown in Figure (14-3). 2- Create a model using a Zero−Order Hold block with sample time 0.5s and input a random waveform with amplitude (1) and frequency 1HZ. The model is shown in Figure (14-2). 3- The settings(4-bit converter,vmin:0,vmax:15) specified for the Idealized ADC Quantizer are noted in Figure (14-4). 4- A comparison of the outputs produced by a Zero-Order Hold block and a First-Order Hold block with the same input, is shown in the model of Figure (14-5). Fig (14-5) Model for comparison of a Zero-Order Hold and a First-Order Hold blocks with same input. Discussion: 1-By Using a First−Order Hold block where the input is (unit ramp, unit step, plus generator) Sketch the waveform for this system. 2- By using a zero−Order Hold block where the input is (unit ramp, repeating sequence, plus generator) Sketch the waveform for this system. University of Technology Electromechanical Engineering Department Electromechanical Systems Engineering Branch Control Laboratory 3rd year Experiment No.(15) The State−Space block by using Mechanical System (Mass−Spring−Dashpot) Theory: The Figure (15-1) show us the system that consisting of a block mass, a dashpot, and a spring. It is shown in feedback and control systems textbooks that this system is described by the second-order differential equation. …………………… (1) Where m represents the mass of the block is a positive constant of proportionality of the force that the dashpot exerts on the block, and k is also a positive constant of proportionality of the force that the spring exerts on the block, known as Hooke’s law. Figure 19.25. Mechanical system with a block, spring and d Fig (15-1) Mechanical system with a block mass, spring and dashpot The mass of the dashpot and the mass of the spring are small and are neglected. Friction is also neglected. For the system of Figure (1), the input is the applied force (F) and the output is the change in distance x . Procedure: Express the differential equation of (1) with numerical coefficients as …………….. (2) Where uo (t) is the unit step function, and the initial conditions are x (0) =4, and dx/dt=0. For the solution of (1) we will use the State−Space block found in the Continuous Library, And thus our model is as shown in Figure (15-2). Fig (15-2) Model for mechanical system with a block, spring and dashpot The state equations are defined as …………….. (3) And = ……………. (4) Then, = = …..………….(5) From (2), (4), and (5) we obtain the system of state equations ……………… (6) And in matrix form, …………………... (7) The output state equation is The coefficients A, B, C, and D are …………… (8) The values in (7) and (8) are entered in the Block parameters dialog box for the State- Space block, and after the simulation command is issued, the Scope block displays the waveform. Discussion: By using the second-order differential equation eq (1) .when m=1, p=4, k=3 and applied force =sin(t) Sketch the waveform for this system when use the State−Space block found in the Continuous Library, and the model is as shown in Figure (2) the initial conditions are x (0) =6, and dx/dt=0.