0% found this document useful (0 votes)
21 views

Programming With MATLAB Lab

Uploaded by

tiwaririshi681
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
21 views

Programming With MATLAB Lab

Uploaded by

tiwaririshi681
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 34
: Page ‘Name of Experiment co | rom—to Ne ay 1 | Introduction to MATLAB: To define & use variables, vectors, Matrices & is 1s functions in MATLAB, To study various arithmetic operators and cot ‘mathematical functions in MATLAB. To create & use miles 2 _| Basic plotting of signals: To study various MATLAB commands for ereating two and three dimensional plas. Write a MATLAB program to plot the following continuous time and diserete | Con time Signals. i. Step Function i. Impulse Function ii. Exponential Function iv, Ramp Function v, Sine Function 3_| Write a MATLAB program to obtain linear convolution of the given 10 sequences. co2 4 | Write a MATLAB program to perform amplitade-scaling, time-scaling and ; 17 time-shifting on a given signal co2 5 _| Write a MATLAB program to obtain Cross correlation of sequence x(a) and 121 y(n) & autocorrelation ofa sequence x (n) of the given sequences & verify the | cow property 6 | Write a MATLAB program to generate Fourier series of a Square Wave ma cos 7 _| Write a MATLAB program to Calculate and plot using MATLAB Fourier 3 Transform and Z-Transform ofa given signa. cos # | Write a MATLAB program to find the impulse response and step response of prety a system from its difference equation, cos Compute and plo the response ofa given system to a given input 9_| Write a MATLAB program to plot magnitude and phase response ofa given 30.31 system, Gos 10 | Checking linearityinon-lincarity of a system using SIMULINK a cos Build a system that amplifies a sine wave by a factor of two. At the end of this course, the student will be able to: col co2 co3 co4 cos Understand the basies operation of MATLAB Analysis the time domain and frequency domain signals. Implement the concept of Fourier series and Fourier transforms. Find cross correlation, autocorrelation of sequence & impulse response, step response of a system, Design frequency response of the system. OBJECT: Introduction to MATLAB. (i) To define and use variables and functions in MATLAB. (ii) To define and use vectors, matrices and polynomials in MATLAB. (iii)To study various MATLAB arithmetic operators and mathematic function. (iv)To create and use m-files. SOFTWARE USED: MATLAB 7.9 THEORY: MATLAB is a programming language developed by Math Works. It started out as a matrix programming language where linear algebra programming was simple. MATLAB (matrix laboratory) is a fourth-generation high-level programming language and interactive environment for numerical computation, visualization and programming. MATLAB is developed by Math Works. It allows matrix manipulations; plotting of functions and data; implementation of algorithms; creation of user interfaces; interfacing with programs written in other languages, including C, C+, Java, and FORTRAN; analyze data; develop algorithms; and create models and applications. It has numerous built-in commands and math functions that help you in mathematical calculations, generating plots, and performing numerical methods. In MATLAB environment, every variable is an array or matrix. Variables can be defined in MATLAB in the following ways: % defining x and initializing it with a value x= sqrt(16) % defining x and initializing it with an expression The clear command deletes all (or the specified) variable(s) from the memory. clearx % it will delete x, won't display anything clear % it will delete all variables in the workspace % peacefully and unobtrusively A vector is a one-dimensional array of numbers. MATLAB allows creating two types of vectors: + Row vectors + Column vectors Row vectors are created by enclosing the set of elements in square brackets, using space or comma to delimit the elements, For example, r=[789 1011] Column vectors are created by enclosing the set of elements in square brackets, using semicolon(;) to delimit the elements, (7; 8; 9; 10; 11] Creating Matrices ‘A matrix is a two-dimensional array of numbers. In MATLAB, a matrix is created by entering each row as a sequence of space or comma separated elements, and end of a row is demarcated by a semicolon, For example a 3-by-3 matrix is created as: m=[123;45 6,789] MATLAB ENVIRONMEN mmand Window Command History Workspace Current Directory Figure Window Command Windor Whenever MATLAB is invoked, the main window called command window is activated, The command window displays the command prompt’>>" and a cursor where commands are entered and are executed instantaneously. Command History Window: Command history window consists of a list of all the commands that are entered at the command window. These commands remain in the list until they are deleted. Any command may be executed by selecting and double clicking it with the mouse. Workspace: A workspace is a collection of all the variables that have been generated so far in the current MATLAB session and shows their data type and size. All the commands executed from. Command Window and all the script files executed from the Command Window share common workspace, so they can share all the variables. Current Directory: The Current Directory window contains all the files and folders present in the Current Directory To run any file, it must either be in the Current Directory or on the search path. Edit Window: ‘An Edit Window is used to create a new program file, or to modify existing files. In this window, programs can be written, edited and saved, The programs written using the MATLAB editor are automatically assigned an extension (.m) by the editor and are known as M- files, Figure Windo A Figure Window is a separate window with default white background and is used to display MATLAB graphics. The results of all the graphic commands executed are displayed in the figure window, MATLAB allows two different types of arithmetic operations — + Matrix arithmetic operations + Array arithmetic operations Matrix arithmetic operations are same as defined in linear algebra. Array operations are executed element by element, both on one dimensional and multi-dimensional array. ‘The matrix operators and arrays operators are differentiated by the period (.) symbol. However, as the addition and subtraction operation is same for matrices and arrays, the operator is same for both cases. The following table gives brief description of the operators — Operator Description Addition or unary plus. A+B adds the values stored in variables A and B. A and B + ‘must have the same size, unless one is a scalar. A scalar can be added to a matrix of any size. Subtraction or unary minus. A-B subtracts the value of B from A. A and B must - have the same size, unless one is a scalar. A scalar can be subtracted from a matrix of any size. Matrix multiplication. C= A*B is the linear algebraic product of the matrices A and B. More precisely, C6) - LAC WBE F rt Fornon-scalar A and B, the number of columns of A must be equal to the number of rows of B. A scalar can multiply a matrix of any size. ‘ Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B must have the same size, unless one of them is a scalar. ; Slash or matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A = (A"B'Y. Array right division. A./B is the matrix with elements A(ij)/B(ij). A and B must, have the same size, unless one of them is a scalar. Backslash or matrix left division. If A is a square matrix, A\B is roughly the same as inv (A)*B, except it is computed in a different way. If A is an n-by-n matrix \ and B isa column vector with n components, or a matrix with several such columns, then X = A\B js the solution to the equation AX = B. A warning message is displayed if A is badly scaled or nearly singular. Array left division. A.\B is the matrix with elements BG,j/AGj). A and B must have the same size, unless one of them is a scalar. Matrix power. Xp is X to the power p, if p is a scalar. Ifp is an integer, the a power is computed by repeated squaring. If the integer is negative, X is inverted first. For other values of p, the calculation involves eigenvalues and cigenvectors, such that if [V,D] = eig(X), then X"p = V*D."p'V. a Array power. A. *B is the matrix with elements A (jj) to the B(ij) power. A and B must have the same size, unless one of them is a scalar. . Matrix transpose. A'is the linear algebraic transpose of A. For complex matrices, this is the complex conjugate transpose. Array transpose. A’ is the array transpose of A, For complex matrices, this does not involve conjugation. Functions for Arithmetic Operation: Apart from the above-mentioned arithmetic operators, MATLAB provides the following commands/functions used for similar purpose ~ Unary plus; increments by the amount a uplus(a) plus (a,b) Plus; returns a+b uminus(a) Unary minus; decrements by the amount a minus(a, b) Minus; retums a - b times(a, b) Array multiply; returns a.*b mtimes(a, b) Matrix multiplication; returns a* b 4 rdivide(a, b) Right array division; returns a/b Idivide(a, b) Left array division; returns a.\b mrdivide(A, B) Solve systems of linear equations x4 = B for x midivide(A, B) Solve systems of linear equations Ax = B for x power(a, b) Array power; returns a,b mpower(a, b) Matrix power; returns ab PROGRAM:- a=li b=20; c=a+b d=a-b e=atb f=alb MATLAB allows writing two kinds of program files — «Scripts — script files are program files with .m extension. In these files, you write series of commands, which you want to execute together, Scripts do not accept inputs and do not return any outputs. They operate on data in the workspat + Functions — funetions files are also program files with .m extension, Functions can accept inputs and return outputs. Internal variables are local to the function. You can use the MATLAB editor or any other text editor to create your .m files. RESULTS:- All the operations have been performed a using MATLAB and results have been seen on the command window. PRECAUTIONS:- 1D Program must be written carefully to avoid errors. 2 Programs can never be saved as standard function name. 3) Functions in MATLAB are case sensitive so commands must be written in proper format. EXPERIMENT NO. 2 OBJECT:: i) Plot the basic signals (Impulse, Step function and Ramp function) ii) To create 2-D and 3-D plots. SOFTWARE USED:- MATLAB 7.9 PROCEDURE:- © Open MATLAB © Open new M-file © Type the program © Save in current directory © Compile and Run the program «For the output see command window\ Figure window THEORY:- a) Impulse Function The impulse function is defined as SLa(oat = 1 and (t= 0 fort #0) That is the impulse function has zero amplitude everywhere expect at t = 0. a 0 t b) Step Function The unit step function is defined as U@)=1 fort>0 =0 fort>0 4 ut Program: t=(-2:0.01:10); impulse = t=0; unitstep = t=0; plot(t, impulse) plot(t, unitstep) ramp = t.*unitstep; plot(t.ramp) xlabel(’Time’) ylabel(‘Amplitude’) titleCimpulse function’) title(‘unit step function’) titleCramp function’) ©) 2D plot Define x as a vector of linearly spaced values between 0 and2™, Use an increment of m/10 between the values. Define y as sine values of x. Prograr cle clearall x=(O-pi/10:24pi) y=sin(x) plot(xy) title(2D Plot’) xlabel(’Time’) ylabel( Amplitude’) plot mensional plot may refer to a) A graph or plot embedded into a three-dimensional space b) The plot of a function of two variables, embedded into a three-dimensional space Program: cle clear all plot3(x,y,t) atid on xlabel(‘x-axis') ylabel('y-axis’) Zlabel('7-axis') title(3D Plot’) RESULTS: Results have been seen on the command window. Figure-2 Figure-3 atte PRECAUTIONS:- 1) Program must be written carefully to avoid errors. 2) Programs can never be saved as standard function name, 3) Functions in MATLAB are case sensitive so commands must be written in proper format. EXPERIMENT NO. 3 OBJECT: Write a MATLAB program to obtain linear convolution of the given sequences. SOFTWARE USED: MATLAB 7.9 PROCEDURE:- Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window Wolution is a mathematical operation used to express the relation between input and output of an LTI system. It relates input, output and impulse response of an LTI system as y(t)=x(t)*h(t) Where y (1) = output of LTI x ({) = input of LTI h (1) = impulse response of LTI There are two types of convolutio Convolution. ult) a) Continuous x(t) * h(t) = f% 2(r)h(t—7)dr b)_Diserete Convolution PROGRAM: cle; clear all; close; disp(‘enter the length of the first sequence m="); m=input("); disp(‘enter the first sequence x[m for i=I:m x(i)=input("); end disp('enter the length of the second sequence n—'); put("); disp(enter the second sequence h{n]=" forjin h@)=input("); end yrconv(x,h); figure; subplot(3,1,1); stem(x); ylabel (amplitude--—>); xlabel('n--- >" title(’x(n) Vs subplot(3,1,2); stem(h); ylabel‘amplitude —->); xlabel('n-- >"); titleCh(n) Vs-n'; subplot(3,1,3); stem(y); ylabel(‘amplitude --->'); xlabel(n-—>); title('y(n) Vs n'); disp(‘linear convolution of x[m] and h[n] is y'); ENPU’ Enter the length of the first sequence m= 6 Enter the length of first sequence x[m]= 1 2 3 6 Enter the length of the second sequence n= 6 Enter the length of second sequence h{n|= 1 2 3 4 5 6 OUTPUT: Linear convolution of x{m] and h{n] is y= 1410.20 35 56 70 76 73 60 36 RESULTS: - Thus the program for linear convolution is written using MATLAB and verified. PRECAUTIONS: 1) Program must be written carefully to avoid errors. 2) Programs can never be saved as standard funetion name. 3) Functions in MATLAB are case sensitive so commands must be written in proper format. 13 EXPERIMENT NO. 4 OBJECT:- Write a MATLAB program to perform amplitude-scaling, time-scaling and time-shifting on a given signal. SOFTWARE USED:-MATLAB 7.9 PROCEDURE: © Open MATLAB © Open new M-file © Type the program Save in current directory © Compile and Run the program ‘For the output see command window\ Figure window THEORY: Amplitude Scaling In the amplitude scaling, a signal y(t) resulting from a signal x(t), on amplitude scaling by a real value k becomes: y(t=k x) Program: cle clear all (=(-3:0.01:7) unitstep=>=0 ul=3*unitstep ramp = .tunitstep r1=2*ramp plot(t,unitstep) hold on plot(t.ramp) hold on plot(t,u!) hold on plot(t,r1) title(amplitude-scaling’) xlabel((Time’) ylabel(‘Amplitude’) Time Shifting The time shifting of the signal x(t) is done by replacing t by t-to . Thus x(t-to) represents x(t) time shifting by to. If to is positive, the shift is to the right, i.e. x({- to) represents the 4 signal x(t) delayed by to and if ty is negative, the shift is to the left, the signal x(t) advanced by to. 2, X(t to) represents plot(t,unitstep,'r’) hold on plot(t,u1,'g) hold on plot(t,u2,'m') Jegend(unitstep','u1'/u2') title(Time-Shifting’) xlabel("Time’) ylabel(’Amplitude’) Time sealing clear all; close all; cle; k2; xI=[1 2345]; jength(x!);, n-0:1:a-1 subplot(3,1,1); stem(x); xlabel('number of samples’); ylabel(amplitude’); titleCinput signal’); x2=k*x1; subplot(3,1,2); stem(x2); xlabel(‘number of samples’); ylabel‘amplitude'); titleCamplified signal’); x3xI/k; subplot(3,1,3); stem(x3); xlabel(‘number of samples’); ylabel(amplitude’); titleCattenuated signal’), display(x1); display(x2); display(x3); RESULTS:- Results have been seen on the command window. Anplude amplitude-scaling = ot 724 s 6 7 Figure-1 Figure-2 ime scaling 16 input signal I 15 z 25 3 35 4 45 5 humber of samples ‘amplified signal I 18 Zz 25 3 35 4 aS 5 number of samples attenuated signal ampliude $ $ t number of samples PRECAUTIONS: 1) Program must be written carefully to avoid errors. 2) Programs can never be saved as standard funetion name. 3) Functions in MATLAB are case sensitive so commands must be written in proper format, EXPERIMENT NO. 5 OBJECT:-Write a MATLAB program to compute autocorrelation and cross correlation of a sequence. SOFTWARE USED:-MATLAB 7.9 PROCEDURE: © Open MATLAB © Open new M-file © Type the program Save in current directory © Compile and Run the program «For the output see command window Figure window THEORY: Auto-correlation: Autocorrelation function gives the measure of similarity, match or coherence between a signal and its delayed replica. This means that autocorrelation function is a special from of a cross- correlation function. It is defined as the correlation of a signal with itself. Consider a signal x(0),Then the autocorrelation function of this signal with its delayed version will be a2 R@= lim= LC jaX(t) x(t— ade Tox The autocorrelation function is defined separately for energy signals and for power or periodic signals. Cross-Correlation: The correlation or more precisely cross-correlation between two different waveforms or two signals is the measure of match or similarity or regularity between one signal and time delayed version of the other signal. Let us consider two general complex signals x(t) and x(t) is defined as 1 pte Rial) = lim 0) xa(t— dt Tow PROGRAM: stem(xl) xlabel(Discrete time’) ylabel('Amplitude') title(Input Sequence’) subplot(2,1,2) stem(y) title(’Autocorelation of the Input Sequence’) xlabel(‘Discrete time’) xlabel(‘Discrete time’) RESULTS: Results have been seen on the command window. Input Sequence 8 ee 3 22 & 1 J ° + 1 15 2 25 3 35 4 Discrete time ‘Autocorelation of the Input Sequence 380, ° g 2 € 10] ol 2 $ 1 2 3 4 5 6 7 Discrete time Cross-correlation r=xcom(xy) r= xcorr(x) r=xeorr(__,maxlag) r= xcorr__,scaleopt) {rilags] = xeorr(__) example Cross Correlation of two vectors Create a vector x and a vector y that is equal to x shifted by 5 elements to the right. Compute and. plot the estimated cross-correlation of x and y. The largest spike oceurs at the lag value when the elements of x and y match exactly (-5). n=0: x= 0.84.%n; y = cireshift(x,5); [c.lags] = xcorr(x,y); stem(lags,c) Compute and plot the normalized cross-correlation of vectors x and y with unity peak, and specify a maximum lag of 10. 15; x=0.84.'n; y= cireshifi(x,5); {[clags] = xcom(x.y,10, normalized’); (ones PRECAUTIONS: 20 1) Program must be written carefully to avoid errors. 2) Programs can never be saved as standard function name. 3) Functions in MATLAB are case sensitive so commands must be written in proper format. 21 EXPERIMENT NO. 6 OBJECT: Write a MATLAB program to generate Fourier series of a Square Wave. SOFTWARE USED: MATLAB 7.9 Open MATLAB Open new M-file ‘Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window et’s assume we have a square wave with following characteristies: Period=2ms Peak—to—Peak Value=2 V Average Value=0 V So, we can express it as: aye 4 Sy Gay mlen V2nf) > (D and assume San = 00H z If g(t) is given by ” s=Fh Now, a Mat lab code can be written for g(t) between 0 and 4ms with an interval of 0.05 ms to demonstrate that g(t) is a decent approximation of original function x(t), in{(2n —1)2xf,f] +++ (2) PROGRAM; % Fourier Series Expansion for Square Wave %% Parameters as mentioned in text £=500; % Frequency C= 4ipi; % Constant Value dt = 5.00-05; % Interval between teo time steps tpts = (4.0e-3/5.0e-5) +1; % Total points & quot;(final point-initial point)/Interval+1% for n= 2 % Values we are considering to approximate Fourier Series instead of infinity as given in original function x(t) 2 for m= 1: tpts % Here, we'll consider all & quot;t& quot; points to cover & quot;from 0 to 4ms interval & quot; sl (n,m) = (4/pi)*(1/(2*n - 1))*sin((2*n - 1)*2*pP*tdt*(m-1); % Approximate Fourier Series g(t) end end for m= 1:tpts al =sl(:,m); % VERY IMPORTANT ! Here, we are assigning al for each single column (total 81) a2(m) = sum(al); % Here, we are summing up the whole column to one single value (adding all 12 values in one column) end % Now, we have a row vector "a2" with total values "81" fl =a2'; ‘% Here, we have final values "fl " (total 81 points) as transpose of a2 computed above t= 0.0:5.00-5:4.00-3; % it's already given in text (0 to 4ms with interval of 0.05 ms) plot(t,fl) xlabel(‘Time, s') ylabel(‘Amplitude, V') title(Fourier Series Expansion’) RESULTS: Results have been seen on the figure window, Fourier Series Expansion Amplitude, V 2 ‘0 q 2 3 Time, s ag? 2B PRECAUTIONS: 1) Program must be written carefully to avoid errors. 2) Programs can never be saved as standard function name. 3) Functions in MATLAB are case sensitive so commands must be written in proper format. 24 EXPERIMENT NO.7 OBJECT: Write a MATLAB program to Calculate and plot using MATLAB Fourier Transform and mnsform of a given signal, SOFTWARE USED: MATLAB 7.9 PROCEDURE: * Open MATLAB © Open new M-file + Type the program © Save in current directory © Compile and Run the program ‘+ For the output see command window\ Figure window THEORY; Ziransform:: The (one-sided)z-transform of a function fn) is defined as zine =F roe. Ea The notation Z{f| refers to the z-transform of fat z. Let R be a positive number so that the function g(z) is analytic on and outside the circle jz| ~ R. Then the inverse ztransform (IZT) of g at n is defined as de, n -1,2,.. ofl 1 malo fs The notation Z~*[f] means the IZT of fat n. The Symbolic Math Toolbox commands ztrans and iztrans apply the z-transform and IZT to symbolic expressions. respectively. See ztrans and 2ztrans for tables showing various mathematical representations of the z-transformand inverse z-transform and their Symbolic Math Toolbox counterparts Thez-transformis often used to solve difference equations In particular, consider the famous "Rabbit Problem.” That is, suppose that rabbits reproduce only on add birthdays (1, 3, §, 7, .). Ifp(n) is the rabbit population at year n, then p obeys the differance equation plrt2) = plot) + pln, p(0) = 4, p(t) = 2. 25 Fourier Transform: The Fourier transform of the function fis traditionally denoted by adding acircumflex: f-There are several common conventions for defining the Fourier transform of an integral function f: R —> C. Here we will use the following definition: fO= [fear for any real number é. When the independent variable x represents time (with SI unit of seconds), the transform variable ¢ represents frequency (in hertz). Under suitable conditions, fis determined by via the inverse transform: se)= [Fen ag, for any real number x. PROGRAM; Fourier transform of exp (-2*x“2) cle clear all syms x fexp(-2*x"2) Your function 2]) — %plot of our function =fourier(f) ‘Fourier transform cle clear all syms zn ztrans(1/4"n) X(2)= Inverse z transform of cle clear all syms zn 26 iztrans(2*2/(2*z-1)) (2*? x" yi exptw?t6)) 12 Jn 6 * 2 0 2 4 6 RESULTS: Z- Transform of x(n) = 2" u(n) x(z=zi(z'"*) Inverse Z- Tranforms of x(z) = 22/22! X(n) = (1/2)" PRECAUTIONS: 1) Program must be written carefully to avoid errors. 2) Programs can never be saved as standard function name. 3) Functions in MATLAB are case sensitive so commands must be written in proper format. ay EXPERIMENT NO. 8 OBJECT: Write a MATLAB program to find the impulse response and step response of a system from its difference equation. SOFTWARE USED: MATLAB 7.9 PROCEDURE::- © Open MATLAB © Open new M-file © Type the program Save in current directory © Compile and Run the program ‘For the output see command window\ Figure window IHEORY: Step Response Step Response is the output from a system excited with a step input. The output step response lasts for infinite time. Impulse Response Impulse Response is the output from a system excited with a unit impulse input. The output impulse response lasts for infinite time. PROGRAM: ‘Step Response: Determine the first 50 values of the step response of a system with a known impulse response h[n]=0.5n *u(n], cle clear all h-0.5.[0:49] x-ones(1,50) y=conv(x,h) stemn((0:49],(1:50)) Impulse Response: Determine the first 50 values of the step response of a system with a known impulse response h{n] =0.5n *u[n]. Here define delta as a vector containing 21 elements Element number 11 is one the rest are zeros.) cle clearall delta=[ zeros(1,10), 1, zeros(1,10)] h=0.5."[0:49] yeconv(delta,h) stemn({0:49],y(1:50)) 28 RESULTS: Results have been seen on the command window oe ee ea ad dO 8 Figure-1: Impulse Response oa 02 Figure-2: Step Response 1) Program must be written carefully to avoid errors. 2) Programs can never be saved as standard function name. 3) Functions in MATLAB are case sensitive so commands must be written in proper format. 29 EXPERIMENT NO. 9 OBJECT: Write a MATLAB program to plot magnitude and phase response of a given system, SOFTWARE USED: MATLAB 7.9 PROCEDURE: Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window Figure window THEORY: If X(Q) is Fourier Transform of continuous time signal x(t), then XQ) = JZa(t) eM dt for all 9 and (x(a) et dO for allt In general, X (Q) is a complex valued function of @. Therefore we can write X(jQ) as X ({) = AR GQ) + j XGQ) Where Xm GQ) is real part of XGQ) and X 1(jQ) is imaginary part of XQ) The magnitude of X(jQ)is given by X(iQ) = (SAO Oe and the phase of X(j@) is given by (2) -{tan™ ae The plot between | X (j®2) | vs Q is known as amplitude spectrum and the plot between X (jQ) vs Q is known as phase spectrum. 30 PROGRAM: cle clearall = 0:1/100:10-1/100; x= sin(2*pi* 15*t) + sin(2*pi*40*t); y= ftox); m=abs(y); p=unwrap(angle(y)); £=(O:length(y)-1)"100/length(y); subplot(2,1,1), plot(f;m) ylabel('Abs. Magnitude’) grid on hold on; subplot(2,1,2), plot(f,p*180/pi) ylabel(Phase [Degrees]') gtid on xlabel('Frequency [Hertz]') RESULTS: Results have been seen on the command window. ‘As. Magnitude Phase [Degrees] T Frequency [Herz] Figure-1 31 EXPERIMENT NO. 10 OBJECT: Checking Linearity/Non-Linearity of a system using SIMULINK. SOFTWARE USED: MATLAB 7.9 PROCEDURE: Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window THEORY: Linear and nor-linear systems ‘A system that obeys the superposition principle is said to be a linear systems Superposition principle states that the response to a weighted sum of input signals be equal to the corresponding weighted sum of the outputs of the systems to each of the individual input signals. Tf an arbitrary input x,(t) produces an output ys(t) and an arbitrary input ¥2(t) produces an output y2(t) then the system is linear if the weighted sum of inputs axa(t) + bxa(t) produces an output ayi(t)tbya(t), where a and b are constants, That is, Tlara(t) + bxa(t)] = aT[ea(t)] + BTL x2(0)] Similarly for a discrete-time linear system ‘Tlaxa(n) + bes(n)] = aT [xa(n)] + bTEeAn)] PROGRAM: cle clearall a=2 n=3 S1=@(x)a*x."n _%i/ anonymous function | describing your system xl= 14 il test input signal x2= 1114 ‘%ii test input signal, Same length rl = S1(x1)+S1(x2) 12=S1(x1+x2) S2=@x) a*x _ %i anonymous function 2 describing your system 32 rl = S2(x1)+82(x2) 12 = S2(x1¥x2) RESULTS: Results have been seen on the command window. si= @oarxn xI= 12 4 x= Hoi2 13 14 r= 2664 «3472-4448 5616 = 3456 S488 819211664 s2= @warx r= 24 28 32 36 n= 24 28 32 36 33

You might also like