Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

LAB MANUAL

INTRODUCTION TO SYSTEM THEORY


LIST OF EXPERIMENTS

1) Command.
2) To perform the application of MATLAB for equation.
3) To perform the application of MATLAB for +, -, *, /.
4) To obtain the Fourier transform of a Signal.
5) To plot the graph of a Sine wave signal & its Power Spectrum.
6) To plot the graph of a Cosine wave signal & its Power Spectrum.
7) To plot the graph of Phase shift of Cosine wave signal & its Power Spectrum.
8) To plot the graph of Square wave signal & its Power Spectrum.
COMMANDS
General purpose commands:
Operators and special characters:
+ Plus; addition operator
_ Minus; subtraction operator
* Scalar and matrix multiplication operator
.* Array multiplication operator
^ Scalar and matrix exponentiation operator
.^ Array exponentiation operator
\ Left – division operator
/ Right- division operator
./ Array Left – division operator
.\ Array Right- division operator
: Colon; generates regularly spaced elements and
represents an entire row or column
() Parentheses ; encloses function arguments and array
indicates ; overrides precedence
[] Brackets; encloses array elements
. Decimal point
… Ellipses ; line-continuation operator
, Comma ; separate statements and element in a row
; Semi-colon ; separates columns and suppress display
% Percent sign ; designates a comment and specifies
formatting
_ Quote sign and transpose operator
._ Non – conjugated transpose operator
= Assignment (replacement) operator
Commands for managing a Session
Clc Clears command window
Clear Remove variables from memory
Exist Checks for existence of file or variable
Global Declares variable to be global
Help Search for a help topic
Look for Search help entries for a keyboard
Quit Stops MATLAB
Who Lists current variables
whos Lists current variables (long display)

Special variables and constants


Ans Most recent answer
Eps Accuracy of floating-point precision
I,j The imaginary unit-1
Int Infinity
Nan Undefined numerical result(not a number)
pi The number

System and file commands

Cd Change current directory


Date Displays current date
Delete Deletes a file
Diary Switch on/off diary file recording
Dir Lists all files in current directory
Load Load work space variable for a file
Path Display search path
Pwd Display current directory
save Saves workspace variables in a file
type Displays contents of a file
what Lists all MATLAB files in the current directory
wklread Reads.wk1 spread sheet file
Input/output Formatting commands

Input /output commands

Disp Display contents of an array or string


Fscanf Read formatted data from a file
Format Controls screen display format
Fprintf Performs formatted writes to screen of files
Input Displays prompts and waits for input
; Suppresses screen printing

Format codes for fprintf and fscanf

%s Format as a string
%d Format as an integer
%f Format as a floating point value
%e Format as a floating point value in scientific notation
%g Format in the most compact form %f or %e
\n Insert a new line in the output string
\t Insert a tab in the output string

Numeric display formats

Format short Four decimal digits(default)


Format long 16 decimal digits
Format short e Five digit plus exponent
Format long e 16 digit plus exponent
Format bank Two decimal digits
Format + Positive, negative or zero
Format rat Rational approximation
Format contact Suppresses some line feeds
Format loose Resets to less compact display mode

Vector, matrix and array commands

Array commands

Cat Concatenates arrays


Find Finds indicates of non zero elements
Length Computers number of elements
Linspace Creates regularly spaced vector
Logspace Creates logarithmically spaced vector
Max Returns largest elements
Min Returns smallest elements
Prod Product of each column
Reshape Change size
Size Computer array size
Sort Sorts each column
Sum Sums each column

Special matrices

Eye Creates an identify matrix


Ones Creates an array of ones
Zeros Creates an array of zeros
Matrix Arithmatic

Cross Computer cross product


Dot Computer dot product

Matrix commands for solving linear equations

Det Computes determinant of an array


Inv Computes inverse of a matrix
Pinv Computes pseudo inverse of a matrix
Rank Computes rank of a matrix
Rref Computes reduced row echelon form

Cell array functions

Cell Creates cell array


Celldisp Displays cell array
Celldrop Displays graphical representation of cell array
Num2cell Convert numeric array to cell array
Deal Matches input and output lists
Iscell Identifies cell array

Structure Function

Fieldnames Returns field names in a structure array


getfield Returns field contents of a structure array
Isfield Identifies a structure array field
Isstruct Identifies a structure array
Rmfield Removes a field from a structure array
Setfield Set contents of field
Struct Creates structures array

Plotting Commands

Basic XY plotting commands

Axis Sets axis limits


Fplot Intelligent plotting of functions
Grid Display gridlines
Plot Generates XY plot
Print Prints plot or saves plot to a file
Title Put text at top of plot
X label Adds text label to X-axis
Y label Adds text label to Y- axis

Plot enhanced commands

Axes Creates axes objects


Close Close the current plot
Close all Close all plots
Figure Open a new figure window
Gtext Enable label placement by mouse
Hold Freezes current plot
Legend Legend placement by mouse
Refresh Redraws current figure window
Set Specifies properties of objects such as axes
Subplot Creates plots in sub window
Text Places string in figure
Specialized plot commands

Bar Creates bar chart


Loglog Creates log-log plot
Polar Creates polar plot
Semilog X Creates semilog plot(logarithmic abscissa)
Semilog Y Creates semilog plot(logarithmic ordinates)
Stairs Creates stairs plot
Stem Creates stem plot

Colors , symbol and line types

Color Symbol Line


y- yellow . – Point <-triangle(left) --Solid
m-magenta O – Circle >-triangle(right) :-dotted
c-cyan X – X-mark p-pentagram -.-dash dotted
r-red + - plus h-hexagram --=dashed
g-green *-star
b-blue d-diamond
w-white v-triangle(down)
k-black ^-triangle(up)

Three Dimensional plotting commands

contour Creates contour plot


mesh Creates three-dimensional mesh surface plot
Mesh C Same as mesh with contour plot underneath
Mesh z Same as mesh with vertical lines underneath
Plot3 Creates three dimensional plots from lines and points
surf Creates shaded three dimensional mesh surface plot
Surf C Same as surf with contour plot underneath
meshgrid Creates rectangular grid
waterfall Same as mesh with mesh lines in one direction
Z label Adds text label to z-axis
Histogram Functions

bar Creates a bar chart


hist Aggregates the data into equally spaced bins
histc Aggregates the data into unequally spaced bins

Programming

Logical and Relational operators

== Relation operator: equal to


~= Relation operator: not equql to
< Relation operator: less than
<= Relation operator: less than or equal to
> Relation operator: greater than
>= Relation operator: greater than or equal to
& Logical operator : AND
/ Logical operator : OR
~ Logical operator :NOT
Xor Logical operator: EXCUSIVE OR

Program Flow Control

Break Terminates execution of a loop


Case Provides alternative execution paths within switch structure
Else Delineates alternative block of statements
Elseif Conditionally executes statements
End Terminates for, while, and if statements
Error Display error message
For Repeats statements a specific number of times
If Executes statements conditionally
Otherwise Default part of switch statement
Return Return to the invoking Function
Switch Directs program execution by comparing point with case
expressions
Warning Display a warning message
while Repeats statements an indefinite number of time

Logical Function

Any True if any elements are non-zero


All True if all elements are non – zero
Find Finds indicates of non-zero elements
Finite True if elements are finite
Isnan True if elements are defined
Isinf True if elements are finite
Isempty True if matrix is empty
isreal True if all elements are real

M-Files

Eval Interpret strings containing MATLAB expressions


Feval Function evalution
Function Creates a user – defined function M+file
Global Define global variables
nargin Number of function input arguments
nargout Number of function output arguments
script Script M-files

Timing

Cputime CPU time in seconds


Clock Current date and time as date vector
Tic,toc Start ,stop a stopwatch timer
Mathematical Functions

Exponential and Logarithmic Functions

Exp(x) Exponential; ex
Log(x) Natural logarithm ; ln(x)
Log10(x) Common (base 10)logarithm ; log (x)= log10 (x)
Sqrt(x) Square root ; X

Trigonometric Functions

acos(x) Inverse cosine ; arcos x = cos-1(x)


acot(x) Inverse cotagent , arcot x = cot-1(x)
acsc(x) Inverse cosecant ; arcs x= csc-1(x)
asec(x) Inverse secant; arcsec x=sec-1(x)
asin(x) Inverse sine; arcsin x=sin-1(x)
atan(x) Inverse tangent; arctan x =tan-1(x)
Atan2(x,y) Four-quadrant inverse tangent
Cos(x) Cosine ; cos (x)
Cot(x) Cotangent ; cot(x)
Csc(x) Cosecant ; csc(x)
Sec(x) Secant ; sec(x)
Sin(x) Sine ; sin (x)
Tan(x) Tangent ; tan(x)

Hyperbolic Functions

acosh(x) Inverse hyperbolic cosine ; cosh-1(x)


acoth(x) Inverse hyperbolic cotangent , coth-1(x)
acsch(x) Inverse hyperbolic cosecant ; csch-1(x)
asech(x) Inverse hyperbolic secant; sech-1(x)
asinh(x) Inverse hyperbolic sine; sinh-1(x)
atanh(x) Inverse hyperbolic tangent; tanh-1(x)
Cosh(x) hyperbolic Cosine ; cosh (x)
Coth(x) hyperbolic Cotangent ; cos(x)/sinh(x)
Csch(x) hyperbolic Cosecant ; 1/sinh(x)
Sech(x) hyperbolic Secant ;1/cosh(x)
Sinh(x) hyperbolic Sine ; sin h(x)
tanh(x) hyperbolic tangent; sinh(x)/cosh(x)

Complex Functions

abs(x) Absolute value ; ІxІ


angle(x) Angle of a complex number x
conj(x) Complex conjugate of x
imag(x) Imaginary part of a complex number x
real(x) Real part of a complex number x

Statistical Functions

erf(x) Computes the error function erf (x)


Mean Calculates the average
Median Calculate the median
std Calculate the standard deviation

Random number Functions

Rand Generates uniformly distributed random numbers between 0-1


randn Generates normally distributed random numbers

Numeric Function

ceil Rounds to the nearest integer forward □


fix Rounds to the nearest integer toward zero
floor Rounds to the nearest integer toward -□
round Rounds towards the nearest interger
sign Signum function

String Function

Findstr Finds occurrences of a string


Strcmp Compares strings
char Creates character string array

Numerical Methods

Polynomial and regression functions

Conv Computes product of two polynomials


Deconv Computes ratio of polynomials
Eig Computes the Eigen values of a matrix
Poly Computes polynomial from roots
Polyfit Fits a polynomial to data
Polyval Evalutes polynomial and generates error estimates
roots Computes polynomial roots

Interpolation Functions

Interp 1 Linear and cubic-spline interpolations of a functions of a function


of one variable
Interp 2 Linear interpolation of a function of two variables
Spline Cubic-spline interpolation
unmkpp Computes the coefficients of cubic-spline polynomials
Root Finding and Minimization

Fmin Finds minimum of single-variable function


Fmins Finds minimum of multivariable function
fzero Finds zero of single-variable function

Numerical Integration Functions

Quad Numerical integration with adaptive sympson’s rule


Quadl Numerical integration with adaptive lobatto quadrature
trapz Numerical integration with the trapezoidal rule

Numerical Differentiation Functions

Diff(x) Computes the difference between adjacent elements in the vector


x
polyder Differentiates a polynomial ,a polynomial product, or a polynomial
quotient

ODE Solvers

Ode 23 Nonstiff , low-order solver


Ode 45 Nonstiff , mediun-order solver
Ode113 Nonstiff , variable-order solver
Ode23s Stiff , low-order
Ode23t Moderately stiff, trapezoidal rule solver
Ode23b Stiff , low-order solver
Ode15s Stiff , variable-order solver
odeset Creates integrator options structure for ODE solvers
Predefined Input Functions

Gensig Generates a periodic sine,square over pulse input


Sawtooth Nonstiff , mediun-order solver
Square Nonstiff , variable-order solver
stepfun Stiff , low-order

Symbolic Math Toolbox

Functions for creating and evaluating symbolic expression

Class Returns the class of an expression


Digits Sets the number of decimal digits used to do variable precision
arithmetic
Double Converts an expression to numeric form
Ezplot Generates a plot of a symbolic expression
Findsym Find the symbolic variables in a symbolic expression
Numden Returns the numerator and denominator of an expression
Sym Creates a symbolic variables
Syms Creates one or more symbolic variables
vpa Set the number of digits used to evaluate expressions

Functions for Manipulating Symbolic Expressions

Collect Collects coefficients of like powers in an expression


Expand Expands an expression by carrying out powers
Factor Factors an expression
Poly2sym Converts a polynomial coefficient vector to a symbolic polynomial
Pretty Displays an expression in a form that resembles typeset
mathematics
Simple Searches for the shortest form of an expression
Simplify Simplifies an expression using Maple’s simplification rules
Subs Substitutes variables or expressions
Sym2poly Converts an expression to a polynomial coefficient vector

Symbolic Calculus Function

Dift Returns the derivative of an expression


dirac Dirac delta function (unit impulse)
Heaviside Heaviside function (step unit)
Int Returns the integral of an expression
Limit Returns the limit if an expression
Symsum Returns the symbolic summation of an expression
taylor Returns the taylor series of a function
EXPERIMENTS:-
EXPERIMENT NO. – 1

Aim of the experiment:- To perform the application of MATAB for an equation.

Apparatus:- MATAB Software

Theory:- MATAB is broadly use in all field of applied mathematics and non-
mathematics In research work. MATAB stands for matrix laboratory and the
software is built around a vector and matrics. MATAB has powerful graphic tool
and is also a programming language used in desktop etc, and is one of the earliest
programming languages for writing mathematical programs.

Working :- Program

X = 1, 2 ,3,4

Y = 2*x+2

Plot (X,Y)

X label (‘frequency’)

Y label (‘wavelength’)

Title (‘frequency Vs wavelength’)

Legend (‘y = 2x + 2’)

Grid on.

Result:- After giving input in the program in MATLAB Software it gives a specific
graph upon given information i.e. from above program it gives the graph of
frequency Vs wavelength.
EXPERIMENT NO. – 2

Aim:- To perform the application of MATLAB for mathematical operations like +,- ,
*, / etc.

Apparatus Required :- MATLAB Software

Theory:-MATLAB is used in all field of applied mathematics and research work.

We all know , MATLAB stads for matrix laboratory and the software is built up
around vectors and the matrices MATLAB has powerful graphic tool and is also a
programming language and is one of the earliest programming languages writing
mathematical programs.

Working:- Program

For Addition:-

X= 27

Y = 23

Z=X+ Y

=50

For Subtraction:-

X=23

Y= 13

Z= x-y

=10

For Multiplication:-

X=4

Y= 3
Z = X*Y

=12

For Division:-

X = 169

Y = 13

Z = X/Y

Z=13

Result:- After giving input in the program in MATLAB software it gives the specific
values of different operations like addition, Subtraction , Multiplication and
Division.
EXPERIMENT NO. – 3

Aim of experiment:-To obtain Fourier transform for a given signal .

Apparatus Required:- MATLAB Software

Theory:- Fourier transformation status that any waveform in the time domain can
be represented by the wetted same of sine as cosine. The same waveform can be
represented in the frequency domain as a pair of amplitude and phase values of
each component frequency . We obtain any waveform by adding sine wave each
with a particular amplitude and phase.

Working :- Program

Function [xk] = ft + self (xn,k)

Xn = [2345]

N=4

n =[0:N-1]

k =[0:N - 1]

WN = exp (-(1)*2* π/N);

nk = n’*k;

WNnk =WN^nk;

Xk = xn*WNnk

Result:- The operation of Fourier Transform of given signal is proved.

Xn = 2345

n = 0123

k = 0123
WN = 0.0000 – 1.0000i

Xk = 14.0000 – 2.0000 + 2.0000i – 2.0000 -0.0000i – 2.0000 -2.0000i

Answer = 14.0000 – 2.0000 + 2.0000i – 2.0000 -0.0000i – 2.0000 -2.0000i


EXPERIMENT NO. – 4

Aim of the experiment :- To plot graph of a sine wave signal and its power
spectrum.

Apparatus Required :- MATLAB software

Theory :- The sine wave or sinusoidal is a mathematical curve that describes a


smooth repeatative oscillation. It is named after the function sine of which it is
the graph. It occurs after in pure and applied mathematics as well as physics ,
engineering , signal processing and many other fields. Its most basic form as a
function of time (t) is

Y(t) = A sin (2 πft + φ)

= A sin (wt + φ)

Fs = 150

T = 0:1/Fs:1

F = 5;

X= sin (2* π*t*f);

Nfft = 1024;

X = x(1:nff t/2)

F = (0:nfft/2 - 1)* Fs/nfft;

Figure(1);

Plot(t,x);

Title (‘sine wave signal’);

X label (‘time(s)’);

Y label (‘amplitude’);
Figure(2);

Plot (f,mn);

X label (‘frequency’);

Title(‘power spectrum of sine wave’);

Y label(‘power’);

Waveform:-
Power Spectrum:-

Result:- The graph of sine wave signal and its power spectrum has ploted.
EXPERIMENT NO. – 5

Aim of the experiment :- To plot graph of a cosine wave signal and its power
spectrum.

Apparatus Required :- MATLAB software

Theory :- The cosine wave is a mathematical curve that describes a smooth


repeatative oscillation. It is named after the function cosine of which it is the
graph. It occurs after in pure and applied mathematics as well as physics ,
engineering , signal processing and many other fields. Its most basic form as a
function of time (t) is

Y(t) = A cos (2 πft + φ)

= A cos (wt + φ)

Fs = 150

T = 0:1/Fs:1

F = 5;

X= cosine (2* π*t*f);

xfft = 1024;

X = x(1:nff t/2)

mx=abs(x);

F = (0:nfft/2 - 1)* Fs/nfft;

Figure(1);

Plot(t,mx);

Title (‘cosine wave signal’)


X label (‘time(s)’);

Y label (‘amplitude’);

Plot(F,mx);

Figure(2);

X label (‘frequency’);

Title(‘power spectrum of cosine wave’);

Y label(‘power’);

Waveform:
Power Spectrum:-

Result:- The graph of cosine wave signal and its power spectrum has ploted.
EXPERIMENT NO. – 6

Aim of the experiment :- To plot graph of a phase shift of cosine wave and its
power spectrum.

Apparatus Required :- MATLAB software

Theory :- The phase shift is the horizontal shift between the units and sine.To
measure the horizontal shift between two wave functions by graphing them.A
shift to the right is positive phase shift and a shift to the left is negative phase
shift use the trigonometry identity cos (x)=sin(x+pi/2) to show that we can obtain
the cosine function by shifting the sine wave pi/2 to the left.The cosine function is
therefore the sine function with a phase shift of –pi/2.

Mathematically,

The graph of sine and cosine are the same when sine is shifted left by pi/2.Such a
shifting is horizontal shifting.

Sin(x+pi/2)=cos x

Working:

Fs = 150

T = 0:1/Fs:1

F = 5;

Pha=1/3*pi

X=cos (2*pi*t*f*pha);

xfft = 1024;

x=fft(x,xfft);

X = x(1:nff t/2);

mx=abs(x);
F = (0:nfft/2 - 1)* Fs/nfft;

Figure(1);

Plot(t,x);

Title (‘cosine wave signal’)

X label (‘time(s)’);

Y label (‘amplitude’);

Plot(F,mx);

Figure(2);

Plot(f,mx);

Title(‘power spectrum of cosine wave’);

X label (‘frequency’ (H3)’);

Y label(‘power’);

Waveform:
Power Spectrum:-

Result:- As a result by writing above program in MATLAB software as phase shift


and its power spectrum is shown.
EXPERIMENT NO. – 7

Aim of the experiment :- To plot graph of square wave signal and its power
spectrum.

Apparatus Required :- MATLAB software

Theory :- A square wave is a no sinusoidal periodic wave form in which the


amplitude alternates at a steady frequency between fixed minimum and
maximum values, with the same duration at minimum and maximum.

The transition between minimum to maximum is instantaneous for an ideal


square wave,this is net realizable in physical system square wave are often
encountered in electronics and signal processing its stochastic counter part is a
two state trajectory.A similar to but not necessarily symmetrical wave with are
arbitrarily duration at minimum and maximum is called a rectangular wave.

Working program:-

Fs = 150

T = 0:1/Fs:1

F = 5;

X= square (2* π*t*f);

xfft = 1024;

X = x(1:nff t);

X=x(1:xfft/2);

Mx=(0:xfft/2-1)* Fs/xfft;

Figure(1);

Plot(t,x);

Title (‘square wave signal’);


X label (‘time(s)’);

Figure(2);

Plot(t,mx);

Title(‘power spectrum of square wave’);

x label(‘freuency(Hz)’);

y label(‘power’);

Waveform:
Power Spectrum:-

Result:- As a result by performing above program in MATLAB software it gives the


graph of square wave signal is formed & power spectrum of square wave.
EXPERIMENT NO. – 8

Aim of the experiment :- To plot graph of phase shift of square wave and its
power spectrum.

Apparatus Required :- MATLAB software

Theory :- A pulse wave or a pulse trainis a kind of non sinusoidal wave form that
is similar to square wave, but does not have the symmetrical shape associated
with a perfect square wave.

Pulse wave forms look similar to square wave except that all the action takes
place above the x-axis .At the beginning of a pulse the voltage changes suddenly
form a low level close to the x-axis to a high level usually close to power supply
voltage.

Working program:-

Fs = 150;

T=-0.5;

1/fs=0.5;

W=0.2;

X=rect pulse(t,w);

Xfft=512;

X=fft(x,xfft);

X=x(1,xfft);

Mx=abs(x);

F=(0:xfft/2-1)*fs/xfft;

Figure(1);
Plot(t,x);

Title (‘square wave signal’);

X label (‘time(s)’);

Y label (‘Amplitude’);

Figure(2);

Plot(f,mx);

Title (‘power spectrum of a square pulse’);

X label (‘Frequency(Hz)’);

Y label (‘power’);

Waveform:
Power Spectrum:-

Result:- As a result by performing above programme in MATLAB software it gives


the graph of phase shift of square wave & its power spectrum.

You might also like