Académique Documents
Professionnel Documents
Culture Documents
Submitted to: Engr.Abbas Abbasi Submitted by: Eamad Ud Deen Tauseef Roll No. 10ES236 Section: D
PAGE OF CONTENTS
Names
Page.No
Introduction to MATLAB Plotting of signals in MATLAB Multi-plotting of exponential signals Sub-plotting of exponential signals Unit step signal in MATLAB Impulse signal in MATLAB Ramp signal in MATLAB Plotting of time shifted signal Compressed & expand signals using time scaling property Time inverted signals using time scaling property Introduction to SIMULINK Time response of LTI electrical system Time response of LTI mechanical system Implementation of LTI system Study of Gibbs phenomena in MATLAB Fourier series analysis
2 9 11 13 15 18 21 24 28 31 34 42 49 55 60 63
LAB#01 Student Name: . Instructions Print this grading sheet, write your name and roll number at the top, and give it to the Instuctor/lab Engineer during your lab check off. Include this as the cover page to your lab report. Instructor/Lab Engineer Grading Section Check Off During your in-lab check off, be prepared to show the instructor/lab Engineer the following: Initialization and simple algebraic operations on variables Matrix generation and operations Introduction to trigonometric and other elementary functions Roll No: ..
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB# 1
INTRODUCTION TO MATLAB OBJECTIVE: The objectives of this lab session are to: (i) Become familiar with MATLAB environment (ii) Become familiar with Basic MATLAB commands (iii) Write small programs using MATLAB INTRODUCTION TO MATLAB: MATLAB is a high level computer language used for the programming of complex engineering problems. MATLAB stands for MATrix LABoratory. As the name suggests, MATLAB a plethora of functions used for different operations on matrices, where a matrix can be scalar (single element), a vector (one dimensional) or an n x m Matrix (two dimensional). In MATLAB we have many tool boxes each containing functions related to specific operations, just as we have libraries in JAVA or C language. Communications, Control System, Image processing and Image acquisition are some of the most commonly used tool boxes. MATLAB has extensive capabilities of two and three dimensional plotting. In MATLAB, there are two modes of executing a program; the first one is command line execution and the second one is M-File or DOT M (.m) file execution. For command line execution commands are entered in the command window where (.m) file, complete program is first written in a file and saved with DOT M (.m) extension. The complete program is then RUN like any other programming language. INITIALIZATION AND SIMPLE ALGEBRAIC OPERATIONS ON VARIABLES: Variables can be introduced in matlab and simple arithmetic operations can also be performed on these variables. >> a=1 a= 1 >> b=5 b= 5 >> c=a+b c= 6
>> d=a-b d= -4 >> e=a*b e= 5 >> f=a/b f= 0.2000 MATRIX GENERATION AND OPERATONS: >> a=[2,3,4;5,6,7;8,9,10] a= 2 5 8 3 6 9 4 7 10
>> p=a+a p=
4 10 16
6 12 18
8 14 20
>> b=2.*a b= 4 10 16 6 12 18 8 14 20
ans =
0.4121 -0.5440
2 3 4
5 6 7
8 9 10
SPECIAL MATRICES: MATLAB provides a number of useful built-in matrices of any desired size. To introduce identity matrix, we use eye.
Another useful operator is the colon. You can use the colon to specify a range of numbers. Typing: >> x=2:6 x=
32 128
-1
10
TRIGONOMETRIC FUNCTIONS: Those known to MATLAB are sin ,cos ,tan. >> x=3*cos (pi/3) x=
2.9995
0.0366 d denotes the degree ,if we use d the result of trigonometric function will be in degrees. OTHER ELEMENTARY FUNCTIONS: These include sqrt ,exp ,log ,log10 >> sqrt (25) ans =
>> log10 (10) ans = 1 Log10 ( ) indicates the log with base 10. >> exp (2) ans = 7.3891 SCALAR PRODUCT: The scalar produce is defined by multiplying the corresponding elements together and adding the results to give a single number. Suppose we have the following vectors: u= [8 -11 10] v= [10 ; -21 ; -52]
10
w= [2 1 3] The command for scalar produce is "*". However the vector (or matrix) dimensions must agree, i.e. 1xn vector can be multiplied with nx1 vector. >> u*v ans =
-209 >> u*w ??? Error using ==> mtimes Inner matrix dimensions must agree. >> u*w' ans = 35 >> u*u' ans = 285 SIZE OF A MATRIX: We can find out the size of a matrix by command size. >> A=[1 2 3;4 5 6;8 9 10] A= 1 4 8 2 5 9 3 6 10
11
Flip: This command is used to flip array left or right. >>a= 2 4 6 8 10; >>fliplr(a) ans 10 8 6 4 2 Ones: (mn) matrix gives an identity matrix with n rows and m coloums. >> P=ones(2,3) P= 1 1 1 1 1 1
Zeros: (mn) matrix gives zero matrix with all elements equal to zero. >> Z=zeros(2,3)
EXTRACTING BITS OF MATRICES: Following commands are used to extract bits of a matrix. >> A=[1 2 3;4 5 6;8 9 10] A=
1 4 8
2 5 9
3 6 10
12
POLYNOMIAL OPERATIONS: Vectors are used to represent polynomials. If you want to represent an Nth-order polynomial, you use a length N+1 vector where the elements are the coefficients of the polynomial arranged in descending order of exponent. So, to define a polynomial (y = x2 -5x + 6) you would type: >> y = [1 -5 6] ; The MATLAB roots function will calculate the roots of a polynomial for you. Execute the following command >> roots(y) Will return ans = 3.0000 2.0000 Sequence: The sequence may be Arithmatic or it may be Geomatric sequence. If the sequence is arithmetic we find the common difference and then set it as the step size. Syntax: Initial value : step size : final value But in geometric sequence we find the common ratio and find the sequence by making it base and set its power limit. Syntax: R ^ (Initial value : step size : final value) where R = common ratio Note: Random sequences are written directly because these can not be generated.
13
14
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
15
LAB# 2: PLOTTING OF SIGNALS IN MATLAB OBJECTIVE: (i) Become familiar with STEM and PLOT command, (ii) Become familiar with Subplot command. Subplot: Subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane contains an axes object which you can manipulate using Axes Properties. Subsequent plots are output to the current pane. h = subplot(m,n,p) or subplot(mnp) breaks the figure window into an m-by-n matrix of small axes, selects the pth axes object for the current plot, and returns the axes handle. The axes are counted along the top row of the figure window, then the second row, etc. PLOTTING OF DISTCRETE AND CONTINUOUS SIGNALS: Discrete signals plotting Stem: This is used to plot discrete sequence data. n=-10:10; x=cos(0.1*pi*n); stem(n,x) grid on
16
Plotting of continuous signals Plot: This is used to plot the continuous data. t=0:0.0001:2 y=exp(2*t) plot(t,y) grid on;title('graph of a continuous signal)
17
18
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
19
LAB# 3: MULTI-PLOTTING OF EXPONENTIAL SIGNALS OBJECTIVE: To learn how multi-plot of exponential signals can be plotted in MATLAB. THEORY: Multi-plotting: It is the plotting of two or more signals on a single graph. An exponential signal is an energy signal. The base of natural logarithm is the irrational number called e and it is equal to 2.718281.., and an exponential signal occurs repeatedly in electrical engineering. Mathematically,real exponential signal is written as: x(t) = Ceat where , C and a are reals. The case a > 0 represents exponential growth. Some signals in unstable systems exhibit exponential growth.
Fig 3-1Case c > 0 & a > 0 The case a < 0 represents exponential decay. Some signals in stable systems exhibit exponential decay.
20
Complex Exponentials: Its general continuous form is written as: x(t) = Aest Where s=+t, is a complex number in terms of , the attenuation constant, and the angular frequency. PROGRAM: Plot the x(t)=AeBt in the time interval having range (-4 4). t=-4:1/8000:4; A1=2; B1=1; A2=-2; B2=1; A3=2; B3=-1; A4=-2; B4=-1; x1=A1*exp(B1*t); x2=A2*exp(B2*t); x3=A3*exp(B3*t); x4=A4*exp(B4*t); plot(t,x1,t,x2,t,x3,t,x4) Graph: % define function x1(t) % define range of t
21
From the graph in Fig 2(a)-3 we can see the plotting of four signals. Hence using MATLAB we can plot different signals in a single graph.
22
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
23
LAB#04 : SUB-PLOTTING OF EXPONENTIAL SIGNALS. OBJECTIVE: We learn sub-plotting of exponential functions. THEORY: Subplot: Subplot divides the current figure into rectangular panes that are numbered rowwise. Each pane contains an axes object which you can manipulate using Axes Properties. Subsequent plots are output to the current pane. h = subplot(m,n,p) or subplot(mnp) breaks the figure window into an m-by-n matrix of small axes, selects the pth axes object for the current plot, and returns the axes handle. The axes are counted along the top row of the figure window, then the second row, etc. PROGRAM: Plot the real and imaginary part of the exponential function using subplot command. % Plot real and imaginary part t=0.5:0.001:5; A=4; B=0.5j; xt=A*exp(B*t); xt_r=real(xt); xt_i=imag(xt); subplot(211) plot(t,xt_r,'g-'); title('Real Part'); subplot(212) plot(t,xt_i,'b--'); title('Imaginary Part') grid on % Define the real part % Define imaginary part
24
Graph:
Fig 4-1 Plot of real and imaginary part of exponential siganl CONCLUSION: The first graph shows the Neper frequency of the given signal. The second graph shows the cyclic behaviour of the signal.
25
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
26
LAB# 05: UNIT STEP SIGNAL IN MATLAB OBJECTIVE: In this lab well learn the plotting of unit step signal either continuous or discrete signal. THEORY: Continuous time signal: Such a signal in which the independent variable t is continuous. Unit step signal [u(t)] Such a signal which is zero for t<0 and 1 for t>0. For continuous time it s denoted by u(t) and mathematically represented as: u(t)= 0 =1 Discrete time signal: Such a signal which is continuous on the discrete values of independent variable n. A discrete time unit signal is denoted by u[n]. Its value is unity for all positive values of n. That means its value is one for n=0. While for other Unit step signal in discrete is called unit step sequence. u[n]= 0 =1 for n<0 for n0 for t<0 for t0
PROGRAM: Plot the unit step signal both in continuous and discrete time. % Lab 5 % Ploting basic signals in Matlab % Date: 11th oct 2012 CT Unit Step Signal t1=-10:0.1:0-0.1; t2=0:0.1:10; t=[t1 t2]; %define range of time t1 %define range of time t2 %define array of time t
27
u=[zeros(1,length(t1)) ones(1,length(t2))]; plot(t,u,'r') grid on title('Unit step Signal') xlabel('Samples');ylabel('Amplitude') axis([-10 10 -1 2])
Fig 5-a Plot of unit step signal Unit sequence Signal n1=-10:-1; n2=0:10; n=[n1 n2]; un=[zeros(1,length(n1)) ones(1,length(n2))]; stem(n,un,'m') grid on title('Unit sequence Signal') %define range of index n1 %define range of index n2 %define array of index n
28
Fig 5-b Plot of unit sequence signal CONCLUSION: The graph in Fig 3-a verify the definition of unit signal in continuous time. The graph in Fig 3-b verify the definition of unit signal in discrete time.
29
LAB#06 Student Name: . Instructions Print this grading sheet, write your name and roll number at the top, and give it to the Instuctor/lab Engineer during your lab check off. Include this as the cover page to your lab report. Instructor/Lab Engineer Grading Section Check Off During your in-lab check off, be prepared to show the instructor/lab Engineer the following: Plotting of impulse signal Plotting of unit sample. Roll No: ..
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
30
OBJECTIVE: In this lab well learn the plotting of impulse signal either continuous or discrete signal. THEORY: Impulse signal: An ideal impulse signal is such a signal that is zero every where but at origin, where it is infinitly high. It is denoted by (t) and mathematically represesnted as: (t)= 1 =0 for t=0 everywhere
In discrete time it is denoted by [n], where for discrete time it is called impulse sequence and denoted by [n], where n is no.of samples. Mathematically represented as; [n]= 1 =0 for n=0 everywhere
PROGRAM: Plotting of impulse signal in MATLAB. % Lab 6 % Ploting basic signals in Matlab % Date: 18th oct 2012 %=========================================================== CONTINUOUS IMPULSE SIGNAL t1=-10:0.1:0-0.1; t2=0+0.1:0.1:10; t=[t1 0 t2]; x=[zeros(1,length(t1)) 1 zeros(1,length(t2))]; plot(t,x, r) grid on title(Impulse Signal) xlabel(Time);ylabel(Amplitude) %define range of time t1 %define range of time t2 %define array of time t
31
Fig 6-1 Plot of impulse signal DT impulse signal n1=-10:-1; n2=1:10; n=[n1 0 n2]; x=[zeros(1,length(n1)) 1 zeros(1,length(n2))]; stem(n,x, 'k') grid on title('Impulse Signal') xlabel('Samples');ylabel('Amplitude') %DT shows discrete time %define range of index n1 %define range of index n2 %define array of index n
32
Fig 6-2 Plot of unit sample CONCLUSION: The graph in Fig 4-a verify the definition of impulse signal in continuous time. The graph in Fig 4-b verify the definition of impulse signal in discrete time.
33
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
34
OBJECTIVE: In this lab well learn the plotting of ramp signal either continuous or discrete signal. THEORY: Ramp signal: Such a signal which gives the slope of t for t0 and 0 for t<0. It is denoted by r(t) and mathematically represesnted as: x(t)= t =0 for t0 for t<0
Whereas for discrete time it is named as unit ramp signal and denoted by x[n]. It is mathematically represented as: x[n]= n =0 PROGRAM: Plot ramp signal for both continuous and discrete time. % Lab 07 % Ploting basic signals in Matlab % Date: 18th oct 2012 %=========================================================== CT Ramp signal t1=-10:0.1:0-0.1; t2=0:0.1:10; t=[t1 t2]; r=[zeros(1,length(t1)) t2]; plot(t,r,'mh') grid on %define range of time t1 %define range of time t2 %define array of time %define function ramp signal for n0 for n<0
35
Fig 7-a Plot of ramp signal in continuous time Discrete Ramp Signal n1=-10:-1; n2=0:10; n=[n1 n2]; rn=[zeros(1,length(n1)) n2]; stem(n,rn,b) grid on title(Discrete ramp Signal) xlabel(Samples);ylabel(Amplitude) axis([-10 10 -1 12]) %define range of index
36
The graph in Fig 7-a verify the definition of ramp signal in continuous time. The graph in Fig 7-b verify the definition of ramp signal in discrete time.
37
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB# 08:
38
Learn how to transform the signals in MATLAB using shifting property. And also learn to create one or more cells in m-file.
THEORY: In order to make new cells in MATLAB double percentage sign %% with space after them is used. The advantage of new cell is that we can divide a long program into more than one portions, which help to see the graphical behavior of each portion separately. When any program is RUN only the graph of active portion will be displayed. The transformation of independent variable involves the three basic transformations: Time shifting either delay or advance, Time scaling either expansion or compression, Time inversion or reversal of time.
Time shifting: Let suppose we have a signal x(t), if t0 is the shifting factor then;
x(t+t0) will shift x(t) in backward direction for negative value of t0 and this property is called advancement. x(t+ t0) will shift x(t) in forward direction for positive value of t0 and tis property is called delay.
PROGRAM:
CT Unit Step Signal...........................................................................................26 Unit sequence Signal........................................................................................27 CONTINUOUS IMPULSE SIGNAL.........................................................................30 DT impulse signal %DT shows discrete time......................................31 CT Ramp signal................................................................................................34 Discrete Ramp Signal.......................................................................................35 %%Plot the shifted signals %% is used to define new cell.................................................................................................40 ........................................................................40 %%Plot the compressed & expand signals.......................................................44 ........................................................................46
39 %%Plot the inverted signals.............................................................................49 When values of R varies...................................................................................65 When values of L varies...................................................................................66 When values of C varies...................................................................................67 When all parameters are same........................................................................72 When k varies...................................................................................................73 When m varies.................................................................................................74 When B varies..................................................................................................75
% define range of t1 % define range of t2 % define range of t3 % define range of t4 % define range of t5 % define range of t6 % define array of time
x1=linspace(0,0,length(t1));
40
xt=[x1,x2,x3,x4,x5,x6];
%%Plot the shifted signals cell %Plot the signal x(t) subplot(311); plot(t,xt,'k'); title('x(t)') xlabel('time t'); ylabel('Amplitude'); axis([-10 10 -1 3]); grid on
%Plot the signal x(t-1)(delay signal) subplot(312); title('x(t-1)') plot(t+1,xt,'m'); xlabel('t'); ylabel('Amplitude'); axis([-9 11 -1 3]); grid on; % define the range of axis on the graph
%Plot the signal x(t+1) (advance signal) subplot(313); title('x(t+1)') plot(t-1,xt,'g'); xlabel('t'); ylabel('Amplitude'); axis([-11 9 -1 3]); grid on;
41
42
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB# 09:
43
COMPRESSED & EXPAND SIGNALS USING TIME SCALING PROPERTY IN MATLAB. OBJECTIVE:
Learn how to plot compressed and expand signals in MATLAB using time scaling property. And also learn to create one or more cells in m-file.
THEORY: Time scaling: When the independent variable t is multiplied by any factor a, of the function then such a property is called time scaling property.
When a=k, where k is any positive integer and multiplied with t, then the plotted signal will be compressed by factor a. When a=1/k for positive k then the resulting signal will be expand by factor a.
PROGRAM:
CT Unit Step Signal...........................................................................................26 Unit sequence Signal........................................................................................27 CONTINUOUS IMPULSE SIGNAL.........................................................................30 DT impulse signal %DT shows discrete time......................................31 CT Ramp signal................................................................................................34 Discrete Ramp Signal.......................................................................................35 %%Plot the shifted signals %% is used to define new cell.................................................................................................40 ........................................................................40 %%Plot the compressed & expand signals.......................................................44 ........................................................................46 %%Plot the inverted signals.............................................................................49 When values of R varies...................................................................................65 When values of L varies...................................................................................66 When values of C varies...................................................................................67 When all parameters are same........................................................................72 When k varies...................................................................................................73 When m varies.................................................................................................74
44 When B varies..................................................................................................75
% LAB 09 % Plot the compressed and expand signals using time scaling property in MATLAB % Dated:1st Nov,2012 %=========================================================== t1=-10:0.1:-2-0.1; t2=-2:0.01:-1-0.01; t3=-1:0.01:0-0.01; t4=0:0.01:1-0.01; t5=1:0.01:2-0.01; t6=2:0.01:10; t=[t1,t2,t3,t4,t5,t6]; x1=linspace(0,0,length(t1)); % define range of t1 % define range of t2 % define range of t3 % define range of t4 % define range of t5 % define range of t6 % define array of time % define the division of line b/w two points i.e 0 0 x2=linspace(0,1,length(t2)); x3=linspace(1,1,length(t3)); x4=linspace(1,2,length(t4)); x5=linspace(2,0,length(t5)); x6=linspace(0,0,length(t6)); xt=[x1,x2,x3,x4,x5,x6]; %%Plot the compressed & expand signals % Plot the signal x(2t)(compressed signal) subplot(211); plot(t/2,xt,'b'); title('x(2t)') xlabel('time t'); ylabel('Amplitude');
45
% Plot the signal x(t/2)(expand signal) subplot(212); plot(2*t,xt,'r'); title('x(t/2)') xlabel('time t'); ylabel('Amplitude'); axis([-5 5 -1 3]); grid on
46
Fig 9-b Compressed & expand signal CONCLUSION: Fig 9-b shows the compressed and expand signals of the original signal x(t).
47
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB# 10: COMPRESSED & EXPAND SIGNALS USING REFLECTION PROPERTY. OBJECTIVE: Learn how to plot compressed and expand signals in MATLAB using time scaling property. And also learn to create one or more cells in m-file.
48
When the independent variable t is multiplied by any factor a where a is negative, then the original signal will be inverted and such a property is called inverting property. It is the third kind of the time scaling property. PROGRAM:
CT Unit Step Signal...........................................................................................26 Unit sequence Signal........................................................................................27 CONTINUOUS IMPULSE SIGNAL.........................................................................30 DT impulse signal %DT shows discrete time......................................31 CT Ramp signal................................................................................................34 Discrete Ramp Signal.......................................................................................35 %%Plot the shifted signals %% is used to define new cell.................................................................................................40 ........................................................................40 %%Plot the compressed & expand signals.......................................................44 ........................................................................46 %%Plot the inverted signals.............................................................................49 When values of R varies...................................................................................65 When values of L varies...................................................................................66 When values of C varies...................................................................................67 When all parameters are same........................................................................72 When k varies...................................................................................................73 When m varies.................................................................................................74 When B varies..................................................................................................75
% LAB 10 % Plot the time inverted signals using time scaling property % Dated:15th Nov,2012 %=========================================================== t1=-10:0.1:-2-0.1; t2=-2:0.01:-1-0.01; t3=-1:0.01:0-0.01; t4=0:0.01:1-0.01; % define range of t1 % define range of t2 % define range of t3 % define range of t4
49
x1=linspace(0,0,length(t1));
x2=linspace(0,1,length(t2)); x3=linspace(1,1,length(t3)); x4=linspace(1,2,length(t4)); x5=linspace(2,0,length(t5)); x6=linspace(0,0,length(t6)); xt=[x1,x2,x3,x4,x5,x6]; %%Plot the inverted signals %Plot the signal x(-t) subplot(311); plot(-1*t,xt,'g'); title('x(-t)') xlabel('time t'); ylabel('Amplitude'); axis([-5 5 -1 3]); grid on % Plot the signal x(-2t+1) subplot(312); title('x(-2t+1)') plot((t-1)/-2,xt,'b'); xlabel('time t'); ylabel('Amplitude'); axis([-4 4 -1 3]); grid on
50
% Plot the signal x(-t/2-1) subplot(313); plot(-2*(t+1),xt,'k'); title('x(-t/2-1)') xlabel('time t'); ylabel('Amplitude'); axis([-8 4 -1 3]); grid on
Fig 10-1
51
CONCLUSION: Fig 8-b shows the inverted signal of the original signals.
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures
52
LAB# 11: INTRODUCTION TO SIMULINK OBJECTIVE: Objective of this lab is to familiar with the SIMULINK. THEORY: Simulink: Simulink software models, simulates, and analyzes dynamic systems. It enables you to pose a question about a system, model the system, and see what happens. With Simulink, you can easily build models from scratch, or modify existing models to meet your needs. Simulink supports linear and nonlinear systems, modeled in continuous time, sampled time, or a hybrid of the two. Systems can also be multirate having different parts that are sampled or updated at different rates. Thousands of scientists and engineers around the world use Simulink to model and solve real problems in a variety of industries, including:
Aerospace and Defense Automotive Communications Electronics and Signal Processing Medical Instrumentation
After you define a model, you can simulate it, using a choice of mathematical integration methods, either from the Simulink menus or by entering commands in the MATLAB Command Window. The menus are convenient for interactive work, while the command line is useful for running a batch of simulations (for example, if you are doing Monte Carlo simulations or want to apply a parameter across a range of values). Using scopes and other display blocks, you can see the simulation results while the simulation runs. You can then change many parameters and see what happens for "what if" exploration. The simulation results can be put in the MATLAB workspace for postprocessing and visualization.
53
How Simulink Software Interacts with the MATLAB Environment Simulink software is tightly integrated with the MATLAB environment. It requires MATLAB to run, depending on it to define and evaluate model and block parameters. Simulink can also utilize many MATLAB features. For example, Simulink can use the MATLAB environment to:
Define model inputs. Store model outputs for analysis and visualization. Perform functions within a model, through integrated calls to MATLAB operators and functions.
Model-Based Design Model-Based Design is a process that enables faster, more cost-effective development of dynamic systems, including control systems, signal processing, and communications systems. In Model-Based Design, a system model is at the center of the development process, from requirements development, through design, implementation, and testing. The model is an executable specification that is continually refined throughout the development process. After model development, simulation shows whether the model works correctly. Modeling Process There are six steps to modeling any system: 1. 2. 3. 4. 5. 6. Defining the System Identifying System Components Modeling the System with Equations Building the Simulink Block Diagram Running the Simulation Validating the Simulation Results
1.Defining the System: The first step in modeling a dynamic system is to fully define the system. If you are modeling a large system that can be broken into parts, you should model each subcomponent on its own. Then, after building each component, you can integrate them into a complete model of the system. For example, the demo model used later in this guide models the heating system of a house. This system can be broken down into three main parts:
The most effective way to build a model of this system is to consider each of these subsystems independently.
54
2.Identifying System Components: The second step in the modeling process is to identify the system components. Three types of components define a system:
Parameters System values that remain constant unless you change them States Variables in the system that change over time Signals Input and output values that change dynamically during the simulation
In Simulink, parameters and states are represented by blocks, while signals are represented by the lines that connect blocks. 3.Modeling the System with Equations: The third step in modeling a system is to formulate the mathematical equations that describe the system. For each subsystem, use the list of system components you identified to describe the system mathematically. Your model may include:
Algebraic equations Logical equations Differential equations, for continuous systems Difference equations, for discrete systems
You use these equations to create the block diagram in Simulink. 4.Building the Simulink Block Diagram: After you have defined the mathematical equations that describe each subsystem, you can begin building a block diagram of your model in Simulink. Build the block diagram for each of your subcomponents separately. After you have modeled each subcomponent, you can then integrate them into a complete model of the system. Running the Simulation After you build the Simulink block diagram, you can simulate the model and analyze the results. Simulink allows you to interactively define system inputs, simulate the model, and observe changes in behavior. This allows you to quickly evaluate your model. 5.Validating the Simulation Results: Finally, you must validate that the model accurately represents the physical characteristics of the system.
55
You can use the linearization and trimming tools available from the MATLAB command line, plus the many tools in MATLAB and its application toolboxes to analyze and validate your model.
Fig 11-b If the simulation run time is changed to 5 rather than10,then we have smooth signal.
Fig 11-c
56
SQUARE WAVEFORM:
Fig 8-e
57
Fig 8-f
Fig 8-h
58
Fig 8-i
INTEGRAL BLOCK:
Fig 8-j
Fig 8-k
59
Fig 8-l
Fig 8-m
SUBSYSTEM:
60
You can create a subsystem within a system, by selecting all the components which have to be placed in subsystem and the selecting the option create subsystem.
Fig 8-n
SOUND CAMMAND: Sound Convert matrix of signal data to sound. Syntax: sound(y,Fs) DESCRIPTION: sound(y,Fs) sends audio signal y to the speaker at sample rate Fs. If you do not specify a sample rate, sound plays at 8192 Hz. For single-channel (mono) audio, y is an mby-1 column vector, where m is the number of audio samples. If your system supports stereo playback, y can be an m-by-2 matrix, where the first column corresponds to the left channel, and the second column corresponds to the right channel. The sound function assumes that y contains floating-point numbers between -1 and 1, and clips values outside that range.
61
62
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB# 12: TIME RESPONSE OF RLC SERIES LTI SYSTEM OBJECTIVE: After completion of this lab we will be able to learn how the time response of LTI systems can be plotted in MATLAB.
THEORY: LTI systems are those systems , which hold the superposition law and homogeneity property. In this lab session we will consider the two LTI systems.These two systems are basically harmonic oscillators, which are explained in the below section: RLC Series circuit Mass spring system
63
Fig 12-1 RLC series circuit An RLC series circuit is an electrical circuit consisting of a resistor, an inductor, and a capacitor, connected in series. The RLC part of the name is due to those letters being the usual electrical symbols for resistance, inductance and capacitance respectively. The circuit forms a harmonic oscillator for current and will resonate in a similar way as an LC circuit will. The main difference that the presence of the resistor makes is that any oscillation induced in the circuit will die away over time if it is not kept going by a source. This effect of the resistor is called damping. The presence of the resistance also reduces the peak resonant frequency somewhat. Now apply the KVL in the above Fig 9(a)-1: x= iR+Li+y .(i) As i=Cy so, Eq(i)=> x(t)= RCy+LCy+y(ii) X(s)= RCsY(s)+LCs2Y(s)+Y(s)
Y(s)/X(s)= 1/(sRC+s2LC+1) =(1/LC)/(s2+(R/L)s+1/LC) In the above equation Y(s)/X(s)=H(s), which is called time function. Basically it is the Laplace of the Impulse response. The driven frequency may be called the undamped resonance frequency or undamped natural frequency and the peak frequency may be called the damped resonance frequency or the damped natural frequency. The driven resonance frequency in a series or parallel resonant circuit has the value.
64
Now we will check the time response of this RLC series circuit on MATLAB by changing the different values if R,L and C. PROGRAM: % LAB# 12 % TIME RESPONSE OF RLC SERIES LTI SYSTEM % Created:29th Nov,2012 %======================================================== R=1;L=1;C=1; num=[1/(L*C)]; den=[1 R/L 1/(L*C)]; H=tf(num,den); % This command is used to define transfer function
Now run this programe by usinf F5 or RUN button. After that call this function in command prompt as follows: >> H Transfer function: 1 ----------s^2 + s + 1 >> step(H) Graph:
65
Fig 12-2 When values of R varies R1=3; R2=2; R3=0.5; L=1;C=1; num=[1/(L*C)]; den1=[1 R1/L 1/(L*C)]; den2=[1 R2/L 1/(L*C)]; den3=[1 R3/L 1/(L*C)]; H1=tf(num,den1); H2=tf(num,den2); H3=tf(num,den3); Now call this function in cammand prompt after RUN as follows: >> H Transfer function: 1 ----------s^2 + s + 1
66
>> ltiview(H1,H2,H3)
% used to veiw the graph of LTI systems or you can use the command of STEP(H1,H2,H3)
Graph:
Fig 12-3 When values of L varies L1=10; L2=5; L3=0.5; R=1;C=1; num1=[1/(L1*C)]; num2=[1/(L2*C)]; num3=[1/(L3*C)]; den1=[1 R/L1 1/(L1*C)]; den2=[1 R/L2 1/(L2*C)]; den3=[1 R/L3 1/(L3*C)]; Ha=tf(num1,den1); Hb=tf(num2,den2); Hc=tf(num3,den3); Now call this function in cammand prompt after RUN as follows:
67
68
num3=[1/(L*C3)]; den1=[1 R/L 1/(L*C1)]; den2=[1 R/L 1/(L*C2)]; den3=[1 R/L 1/(L*C3)]; H1=tf(num1,den1); H2=tf(num2,den2); H3=tf(num3,den3);
Now call this function in cammand prompt after RUN as follows: >> H Transfer function: 1 ----------s^2 + s + 1 >> ltiview(H1,H2,H3)
Graph:
69
Fig 12-5
CONCLUSION:
From above graphs we conclude that the behavior of the RLC series circuit is the same both for resistor and capacitor, whereas for inductor its behavior is inverse of both of them. When the values of resistor and capacitor increases then oscillations in the signal decreases as their values increases, means greater energy is dissipated and stored across resistor and capacitor respectively, and vice-versa. Whereas in case of inductor, greater its inductance greater no.of oscillations in the signal. The dots in each graph show the settling time of each signal. As we can see that the inductors and capacitors having greater values required larger settling time as compared to the resistor.
70
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
71
OBJECTIVE: After completion of this lab we will be able to learn how the time response of LTI systems can be plotted in MATLAB.
THEORY: LTI systems are those systems , which hold the superposition law and homogeneity property. In this lab session we will consider the two LTI systems.These two systems are basically harmonic oscillators, which are explained in the below section: RLC Series circuit Mass spring system
Fig 13-1 Mechanical system A simple harmonic oscillator is an oscillator that is neither driven nor damped. It consists of a mass m, which experiences a single force, F, which pulls the mass in the direction of the point x=0 and depends only on the mass's position x and a constant k. Balance of forces (Newton's second law) for the system is
In real oscillators, friction, or damping, slows the motion of the system. Due to frictional force, the velocity decreases proportional to the acting frictional force. Whereas Simple harmonic motion oscillates with only the restoring force acting on the system, Damped Harmonic motion experiences friction. Mathematically it can be written as: F= kx+mx+Bx(iii) Where B is the viscous damping coefficient. Now taking the Laplace of eq(iii), we get F(s)= kX(s)+ms2X(s)+BsX(s)..(iv)
72
=>F(s)/X(s)= s2m+sB+k.(v) Where F(s)/X(s)= H(s) Eq(v)=> H= (1/m)/(s2+(B/m)s+k/m)........(vi) Where resonance frequency is o o= k/m Now we will see the graphical behavior of the mass spring system by changing the values of k, m and B. PROGRAM: % LAB# 13 % TIME RESPONSE OF MASS SPRING LTI SYSTEM % Created:6th dec,2012 %========================================================== When all parameters are same m=1; B=1; k=1; num=[1/m]; den=[1 B/m k/m]; H=tf(num,den); Now call this function in cammand prompt after RUN as follows: >> H Transfer function: 1 ----------s^2 + s + 1 >> ltiview(H) % used to veiw the graph of LTI systems or you can use the command of STEP(H1,H2,H3) Graph:
73
Fig 13-2 Step response of mechanical LTI system When k varies m=1; B=1; k1=10; k2=5; k3=1.5; num=[1/m]; den1=[1 B/m k1/m]; den2=[1 B/m k2/m]; den3=[1 B/m k3/m]; H1=tf(num,den1); H2=tf(num,den2); H3=tf(num,den3);
Now call this function in cammand prompt after RUN as follows: >> H Transfer function: 1 -----------
74
Fig 13-3 When m varies m1=20; m2=10; m3=5; B=1; k=1; num1=[1/m1]; num2=[1/m2]; num3=[1/m3]; den1=[1 B/m1 k/m1]; den2=[1 B/m2 k/m2]; den3=[1 B/m3 k/m3]; Ha=tf(num1,den1); Hb=tf(num2,den2); Hc=tf(num3,den3); Now call this function in cammand prompt after RUN as follows:
75
Fig 13-4 When B varies m=1; k=1; B1=5; B2=3; B3=1.5; num=[1/m]; den1=[1 B1/m k/m]; den2=[1 B2/m k/m]; den3=[1 B3/m k/m]; Hx=tf(num,den1);
76
From above graphs we conclude that the behavior of the mass spring system is same for both restoring constant(k) and mass(m), whereas for viscous damping factor(B) its behavior is inverse of both of them. When the values of k and m increases then oscillations in the signal decreases as their values increases and vice-versa. Whereas in case of B, greater this factor greater no.of oscillations in the signal. The dots in each graph show the settling time of each signal. As we can see that the B and m having greater values required larger settling time as compared to the k.
77
Print this grading sheet, write your name and roll number at the top, and give it to the Instuctor/lab Engineer during your lab check off. Include this as the cover page to your lab report. Instructor/Lab Engineer Grading Section Check Off During your in-lab check off, be prepared to show the instructor/lab Engineer the following: Implementation of LTI system in Simulink To observe the graphical behavior of LTI system.
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
LAB# 14: IMPLEMENTATION OF LTI SYSTEM PURPOSE: To learn how LTI system can be implemented in Simulink. And to see the graphical behavior of the LTI system.
78
CIRCUIT DIAGRAM:
Consider the Fig 10-1, we will derive the expression of this LTI system using KVL, in order to draw its block diagram in Simulink. x(t ) = + y iR i =Cy ' x(t ) = CRy + y ' 1 1 y'= y+ ' x RC RC when R =and C = 1, get 1 we y ' =x y...............................(i ) X (s ) = CRsY (s ) Y (s ) + 1 Y (s ) RC H (s ) = = 1 X (s ) s+ RC when R =and C = 1, get 1 we 1 H (s ) = ..........................( ) ii s +1 In above eq(i) let y is the signal which is provided to integrating circuit to gain y and then multiply it with -1 gain and add with x as shown in block diagram given below:
79
Fig 14-3(a)
Fig 14-3(b) Both the diagrams show the same graphical behavior because second one is the transfer function of the first one as shown below:
Fig 14-4 Now consider the Fig 10-2 to calculate its equation and also the transfer function and use these relations to draw the block diagram in Simulink.
80
x(t ) = iR + Li '+ y x(t ) = CRy '+ LCy ''+ y LCy " = RCy ' y + x R 1 1 y" = y ' y+ x L LC LC Now putR = 1, C = 1 and L = 1 in above eq y " = y ' y + x ..........................................(iii ) R 1 1 s 2Y ( s ) = sY ( s ) Y (s) + X (s) L LC LC R 1 1 s 2Y = sY Y+ X L LC LC Y 1 H (s) = = X LC ( s 2 + R s + 1 ) L LC Now put againR = 1, C = 1 and L = 1 1 H (s) = 2 ........................................(iv) ( s + s + 1) Now using above eqs (iii) and (iv) we will draw the model of RLC series circuit as shown below:
Fig 14-5 Similarly in this case the graphs of both the blocks are same as given below:
81
The graph in Fig 14-4 verifies the behavior of the behavior of RC series circuit. Similarly the graph in Fig 14-6 verifies the behavior of RLC series circuit. In the same procedure we can see their behavior by varying the values of R,C and L.
82
LAB#15 Student Name: . Instructions Print this grading sheet, write your name and roll number at the top, and give it to the Instuctor/lab Engineer during your lab check off. Include this as the cover page to your lab report. Instructor/Lab Engineer Grading Section Check Off During your in-lab check off, be prepared to show the instructor/lab Engineer the following:
To study the graphical behavior of Gibbs phenomenon in MATLAB.
Roll No: ..
Date
Score
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
83
PURPOSE: The study of Gibbs phenomena in Matlab. THEORY: The Gibbs phenomenon, discovered by Henry Wilbraham (1848) and rediscovered by J. Willard Gibbs (1899), is the peculiar manner in which the Fourier series of a piecewise continuously differentiable periodic function behaves at a jump discontinuity: the nth partial sum of the Fourier series has large oscillations near the jump, which might increase the maximum of the partial sum above that of the function itself. The overshoot does not die out as the frequency increases, but approaches a finite limit. These are one cause of ringing artifacts in signal processing.
A Fourier Series represents a periodic function through a sum of sines or cosines. Each term in the summation has a frequency n. The first term has the same frequency as the periodic function, the second term has twice the frequency of the periodic function, and so on. The more functions added, the more the summation resembles the step function.
84
Fig 15-a PROGRAM: % LAB# 15 % GIBB'S PHENOMENA % DATE: 13TH DEC,2012 %define parameters A=2; T=2; T1=0.5;w0=(2*pi)/T; t=-6:0.001:6; c0=(2*A*T1)/T; s1=0; s2=0; n=4; %define Fourier coefficients %series s1 from -4 to -1 for k1=-n:-1 ck1=(A*sin(w0*k1*T1))/(pi*k1); x1=ck1*exp(1j*w0*k1.*t); s1=x1+s1; end % series s2 from 1 to 4 for k2=1:n ck2=(A*sin(w0*k2*T1))/(pi*k2); x2=ck2*exp(1j*w0*k2.*t); s2=x2+s2; % define time scale % dc component of signal % initializing sum of series 1 and series 2 as 0 % define whole limits of signal from -n to n i.e k
85
end % define signal x(t) with Fourier coefficients xt=s1+c0+s2; plot(t,xt,'r'); grid on;
86
87
Fig 15-g CONCLUSION: By increasing n spikes increases. In signal processing, the Gibbs phenomenon is undesirable because it causes artifacts, namely clipping from the overshoot and undershoot, and ringing artifacts from the oscillations. In the case of low-pass filtering, these can be reduced or eliminated by using different low-pass filters.
88
LAB#16 Student Name: . Instructions Print this grading sheet, write your name and roll number at the top, and give it to the Instuctor/lab Engineer during your lab check off. Include this as the cover page to your lab report. Instructor/Lab Engineer Grading Section Check Off During your in-lab check off, be prepared to show the instructor/lab Engineer the following: To observe the graphical behavior of Fourier series. Date Instructor/Lab Engineer Engr. Abbas Abbasi Score Roll No: ..
Reminder: This lab requires a Full Report Worksheet Score Instructor Report Score(0-15) Total Score(0-20)
Instructor/Lab Engineer comments -------(of 5) Organization & Quality -------(of 5) Completeness & Correctness of Figures -------(of 5) Discussion Topics/ Q&A
89
OBJECTIVE: The purpose of this lab is to view the graphical behavior of fourier series. THEORY: Fourier series: A Fourier series is a mathematical tool that takes a periodic function and turns it into a sum of simple oscillating functions (i.e. sines and cosines). A Fourier series represents a periodic function through a sum of sines or cosines. Each term in the summation has a frequency n. The first term has the same frequency as the periodic function, the second term has twice the frequency of the periodic function, and so on. The more functions added, the more the summation resembles the step function. These series were discovered by Joseph Fourier to solve a heat equation in a metal plate. PROGRAM: % lab 16 % date: 20th,dec,2012 % Fourier series analysis %================================================================ %define parameters A=2; T=2; T1=0.5;w0=(2*pi)/T; t=-6:0.001:6; c0=0; s1=0; s2=0; n=3; %define Fourier coefficients %series s1 from -3 to -1 for k1=-n:-1 ck1=(1j*cos(pi*k1))/(pi*k1); x1=ck1*exp(1j*w0*k1.*t); s1=x1+s1; end %series s1 from 1 to 3 for k2=1:n ck2=(1j*cos(pi*k2))/(pi*k2); x2=ck2*exp(1j*w0*k2.*t); s2=x2+s2; end % define signal x(t) with Fourier coefficients % define time scale % dc component of signal is zero % initializing sum of series 1 and series 2 as 0 % define whole limits of signal from -3 to 3 i.e k
90
Fig 16-a We will plot some other periodic functions which are given below: Example no.1: %define parameters A=2; T=2; T1=0.5;w0=(2*pi)/T; t=-6:0.001:6; c0=0; s1=0; s2=0; n=15; %define Fourier coefficients %series s1 from -3 to -1 for k1=-n:-1 ck1=((1/2)-cos(k2*pi)); x1=ck1*exp(1j*w0*k1.*t); s1=x1+s1; end % define time scale % dc component of signal is zero % initializing sum of series 1 and series 2 as 0 % define whole limits of signal from -3 to 3 i.e k
91
%series s1 from 1 to 3 for k2=1:n ck2=((1/2)-cos(k2*pi)); x2=ck2*exp(1j*w0*k2.*t); s2=x2+s2; end % define signal x(t) with Fourier coefficients xt=s1+c0+s2; plot(t,xt,'r'); grid on;
Fig 16-b Example no.2: %define parameters A=2; T=6; T1=0.5;w0=(2*pi)/T; t=-6:0.001:6; % define time scale
92
c0=1/2; s1=0; s2=0; n=300; %define fourier coefficients %series s1 from -300 to -1
% dc component of signal is zero % initializing sum of series 1 and series 2 as 0 % define whole limits of signal from -300 to 300 i.e k
for k1=-n:-1 ck1=((6/(k1^2)*(pi^2))*(sin((k1*pi)/2)*sin((k1*pi)/6))); x1=ck1*exp(1j*w0*k1.*t); s1=x1+s1; end %series s1 from 1 to 3 for k2=1:n ck2=((6/(k2^2)*(pi^2))*(sin((k2*pi)/2)*sin((k2*pi)/6))); x2=ck2*exp(1j*w0*k2.*t); s2=x2+s2; end % define signal x(t) with Fourier coefficients xt=s1+c0+s2; plot(t,xt,'r'); grid on;
93
Fig 16-c CONCLUSION: We can easily understand the fourier series of all the above mention examples by inspecting their graphs.