You are on page 1of 25

INTRODUCTION TO MATLAB

The name MATLAB stands for MATrix LABoratory. MATLAB was written originally to provide
easy access to matrix software developed by the LINPACK (linear system package) and EISPACK
(Eigen system package) projects. MATLAB handles simple numerical expressions and
mathematical formulas.

MATLAB is a high-performance language for technical computing. It integrates computation,


visualization, and programming environment.

Furthermore, MATLAB is a modern programming language environment: it has sophisticated data


structures, contains built-in editing and debugging tools, and supports object-oriented
programming. These factors make MATLAB an excellent tool for teaching and research.

MATLAB has many advantages compared to conventional computer languages (e.g., C,


FORTRAN) for solving technical problems.

MATLAB is an interactive system whose basic data element is an array that does not require
dimensioning. It has powerful built-in routines that enable a very wide variety of computations. It
also has easy to use graphics commands that make the visualization of results immediately
available.

Specific applications are collected in packages referred to as toolbox. There are toolboxes for signal
processing, symbolic computation, control theory, simulation, optimization, and several other fields
of applied science and engineering.

1
AIM :- To visualize the complex exponential signal and real sinusoids.

Sinusoidal Function & Exponential function

INTRODUCTION

In physics and mathematics, we often come across with waves. Waves are functions that oscillate.
A wave is usually a periodic function which repeats all its values after a certain period. Sinusoidal
functions play a vital role in mathematics. Sinusoidal function or sinusoid function is generally the
sine wave function which is related to the oscillations. 

A sinusoidal function is a repetition of oscillations. It is a curve similar to the sine wave but with a
shift in phase or amplitude.The general representation of a sinusoid is given by Y(t) = Ao Sin( t
+ φ), Where "t" is the varying parameter and phase shift is given by φ. A0 gives the amplitude of
the sine wave. The value of "w" is 2πf where f is the frequency of oscillations.

Hence a cos function is represented by Y(t) = Ao Sin(wt +90)

The shift of curve depends on the value of φ, If its -ve, then curve shifts right and if its +ve it curve
shifts left.

Exponential functions look somewhat similar to functions you have seen before, in that they
involve exponents, but there is a big difference, in that the variable is now the power, rather than
the base. functions asf(x) = x2, where the variable x  was the base and the number 2 was the power.

In the case of exponentials, however, you will be dealing with functions such as g(x) = 2x, where the
base is the fixed number, and the power is the variable.

2
PROGRAM – 1
AIM :- To visualize the complex exponential signal and real sinusoids
%To plot sinusoidal and exponential functions

clc
clear all
t=-2*pi:0.5*pi/4:2*pi;
y1=exp(-0.1*t);
y2=exp(0.1*t);
y3=sin(t);
y4=cos(t);
subplot(2,2,1)
plot(t,y1)
title('Exponential')
xlabel('time')
ylabel('amplitude')
legend('Negative exponential')
subplot(2,2,2)
plot(t,y2)
title('Exponential')
xlabel('time')
ylabel('amplitude')
legend('positive exponential')
subplot(2,2,3)
plot(t,y3)
title('Sine')
xlabel('time')
ylabel('amplitude')
legend('sine')
subplot(2,2,4)
plot(t,y4)
title('Cos')
xlabel('time')
yl'amplitude')
legend('cos')

3
AIM:- To explore the various types of singularity functions.
Singularity Functions
INTRODUCTION
Singularity functions are discontinuous functions or their derivatives are discontinuous. A
singularity is a point at which a function does not possess a derivative. In other words, a singularity
function is discontinuous at its singular points. Hence a function that is described by polynomial in
t is thus a singularity function. The commonly used singularity functions are:

 UNIT-STEP FUNCTION

The continuous-time unit-step function is defined as:

Above equation defines what a unit-step function. The value of a unit-step function is one, for
values of t > 0, and it is zero, for values of t < 0. It is undefined at t = 0. The unit-step function has a
value between 0 and 1, at t = 0. The value of the unit-step function changes suddenly, at t = 0.
Because of the step change in unit-step function at t= 0, the value of derivative of unit-step function
is infinite at t = 0. In other words, the unit-step function is discontinuous at t = 0. It can be seen that
the derivative of unit-step function is zero at all instants, except t = 0.

4
The unit step function u(t) is represented as shown in Fig. 1. The unit step function is used widely
in network theory and control theory. It can be seen that the unit step function has a discontinuity at
t = 0 and is continuous for all other values of t .

 RAMP FUNCTION

The ramp function is illustrated in Fig. 7. It can be defined as follows:

The ramp function has zero value in the range defined by t < 0. When t > 0, the ramp function
increases linearly with time. The unit-step function and the ramp function are related. We can
define the unit-step function, as the derivative of the ramp function,. Alternatively, we can state that
the ramp function is the integral of the unit-step function.

 IMPULSE FUNCTION

The unit impulse function, designated δ(t), is also called the Dirac delta function. Its use in network
theory, control theory and signal theory is widespread and it is important because of its properties
and the insight it offers about the network to which it is applied.

The impulse function is displayed, as shown in Fig. 11. The impulse function is related to the unit-
step function. It is the integral of the impulse function.

5
6
PROGRAM – 2
AIM:- To explore the various types of singularity functions.
% To Plot Singular Function
clc
clear all
t=-10:0.5:10;
n=-20:1:20;
%unit impulse function
imp=[zeros(1,20),1,zeros(1,20)]
subplot(4,2,1)
plot(t,imp)
xlabel('time')
ylabel('imp(t)')
title('continuous impulse function' )
subplot(4,2,2)
stem(n,imp)
xlabel('intervals')
ylabel('imp[n]')
title('discrete imp function' )
% unit step function
stp=[zeros(1,20),ones(1,21)]
subplot(4,2,3)
plot(t,stp)
xlabel('time')
ylabel('u(t)')
title('continuous unit step function' )
subplot(4,2,4)
stem(n,stp)
xlabel('intervals')
ylabel('u[n]')
title('discrete unit step function' )

7
% ramp function
rmp=t.*stp;
subplot(4,2,5)
plot(t,rmp)
xlabel('time')
ylabel('ramp(t)')
title('continuous ramp function' )
subplot(4,2,6)
stem(n,rmp)
xlabel('intervals')
ylabel('ramp[n]')
title('discrete ramp function' )
% signum function
sgn=-1+2*stp
subplot(4,2,7)
plot(t,sgn)
xlabel('time')
ylabel('sgn(t)')
title('continuous signum function' )
subplot(4,2,8)
stem(n,sgn)
xlabel('intervals')
ylabel('sgn[n]')
title('discrete sgn function' )

8
AIM:- To demonstrate even and odd signal.

Even And Odd Signals

INTRODUCTION

One of characteristics of signal is symmetry that may be useful for signal analysis. Even signals are
symmetric around vertical axis, and Odd signals are symmetric about origin. 

Even Signal: 
A signal is referred to as an even if it is identical to its time-reversed counterparts; x(t) = x(-t). 

Odd Signal: 
A signal is odd if x(t) = -x(-t). 
An odd signal must be 0 at t=0, in other words, odd signal passes the origin. 

Using the definition of even and odd signal, any signal may be decomposed into a sum of its even
part, xe(t), and its odd part, xo(t), as follows: 

 
It is an important fact because it is relative concept of Fourier series. In Fourier series, a periodic
signal can be broken into a sum of sine and cosine signals. Notice that sine function is odd signal
and cosine function is even signal.

9
PROGRAM – 3
AIM:- To demonstrate even and odd signal.

% To determine even and odd part of signal


clc
clear all;
t=-10:1:10;
x=input('enter x')
xeven=0.5*(x+fliplr(x))
xodd=0.5*(x-fliplr(x))
subplot(3,1,1)
plot(t,x)
xlabel('time')
ylabel('x(t)')
title('original signal' )
subplot(3,1,2)
plot(t,xeven)
xlabel('time')
ylabel('xeven')
title('even part of signal' )
subplot(3,1,3)
plot(t,xodd)
xlabel('time')
ylabel('xodd')
title('odd patt of signal' )

10
AIM:- To explore the effect of transformation of signal parameters (time-revarsal, time-scaling
and time-shifting.

Transformation of independent variable

INTRODUCTION

Transformation  of discrete signals: The transformations of a discrete signal’s amplitudes is the


same as that of a continuous one. The time translation of a discrete signal: The expansion and
compression for continuous signals are replaced by up-sampling and down-sampling

 Time Shifting

Time shifting is a very basic operation that you never stop to come across if you are handling a
signals and systems problem. We seek to settle all doubts regarding it for one last time.

Consider that we are given a signal x(t) then how do you implement time shifting and scaling to
obtain the signal x(–αt – β), x(–αt + β), x(αt – β) or x(αt + β), where α and β are both positive
quantities. The first thing we would want to clear forever is that a negative time shift implies a
right shift and a positive time shift implies a left shift.

Remember it by the thinking of creating an arrow out of negative sign, – to → which implies right
shift for negative time shift. The other (+ time shift) would obviously mean a left shift.

Returning to our original agenda, the next thing to know is that time shifting and scaling can be
implemented, starting from both the left and right side. Since we are discussing time shifting, we
set α = 1 which is responsible for scaling.

 Time Scaling

Expansion or compression of a signal with respect to time is known as time scaling. Let x(t) be a
continuous time signal, and then x(5t) will be the compressed version of x(t) by a factor of 5 in
time. And x(t/5) will be the expanded version of x(t) by a factor of 5 in time.In general, if we

11
consider x(at) then for a > 1, the signal will be compressed by the factor ‘a’ and for a < 1, the signal
will be expanded by the factor (1/a).

 Time Inversion / Time Reversal

Time inverted signal is denoted by x(–t) which is achieved by replacing the independent variable
time t by its negative counterpart i.e. –t. So, time inverted signal of x(t) is x(–t). This can also be
considered as a special case of time scaling with a = –1.

Time inverted signal can also be achieved by taking the reflection/mirror image about the vertical
axis.

Note:

When a combination of time shifting and time scaling has to be performed on a signal x(t) then to
realize an expression of the form x(at-b), the natural order is time shifting followed by time
scaling. However, time-shifting can also be performed after time scaling with a precaution of
dividing the visible shift amount by the scaling factor.

12
PROGRAM-4
AIM:- To explore the effect of transformation of signal parameters (time-revarsal, time-scaling
and time-shifting).

%Explore the effect of Transformation of independent variable

clc

clear all

t=-10:1:10;

x=input('enter input signal x....')

subplot(4,2,1)

plot(t,x)

xlabel('time')

ylabel('x(t)')

title('orignal signal')

%time scaling by factor a

a=input('enter value of a')

subplot(4,2,2)

plot(t/a,x) %compression

xlabel('time')

ylabel('x(a*t)')

13
title('compressed signal')

subplot(4,2,3)

plot(a*t,x) %expansion

xlabel('time')

ylabel('x(t/a)')

title('expanded signal')

%time shiftinf by factor b

b=input('enter value of b')

subplot(4,2,4)

plot(t+b,x) %right shift

xlabel('time')

ylabel('x(t-b)')

title('right shifted signal')

subplot(4,2,5)

plot(t-b,x) %left shift

xlabel('time')

ylabel('x(t+b)')

title('left shifted signal')

%time reversal

y=fliplr(x)

subplot(4,2,6)

plot(t,y)

14
xlabel('time')

ylabel('x(-t)')

title('inverted signal')

%shifting and scaling

subplot(4,2,7)

plot((t-b)/a,x)

xlabel('time')

ylabel('x(at+b)')

title('shifted and scaled signal')

subplot(4,2,8)

plot(a*(t+b),x)

xlabel('time')

ylabel('x(t/a-b)')

title('shifted and scaled signal')

15
AIM:- To identify a given system linear or non-linear.

Linear and Non Linear systems


INTRODUCTION
A system is said to be linear if it follows both the Homogenity and superposition principles.

Homogenity: If the input is multiplied by a constant, the output shall also be multiplied by the
same.

Superposition: It states that response resulting from several input signals can be computed as the
sum of responses resulting from each input signal acting alone.

Non-linear system refers to the type of system where the output from the system does not vary
directly with respect to input to the system. The non-linear systems do not accompany the static
linearity and they are provided with threshold. Also, the fundamental of homogeneity is not
accepted in non-linear systems.

The difference between non-linear system and linear system is that the superposition principle is
not applied in the non-linear system.

Show the examples of non-linear and linear systems as

We can check for linearity by making X(n) equal to zero and see whether Y(n) becomes the same.
If not, we can conclude it to be linear. But if it is zero, we need to further test the difference
equation for superposition and then if the difference equation satisfies it, then the system is
acknowledged as linear. We can sum that, any system with a non zero initial condition is a non
linear system. A charged capacitor and an inductor with initial flux are all non linear.

16
PROGRAM-5
AIM:- To identify a given system as linear or non-linear.
%to check linearity of a system
clc
clear all
t=0:0.1:5;
x1=input('enter input x1' )
x2=input('enter input x2' )
a1=input('enter a1')
a2=input('enter a2')
x3=a1*x1+a2*x2;
sys_b=@(x)(5*x);
y1=sys_b(x1);
y2=sys_b(x2);
y31=a1*y1+a2*y2;
y3=sys_b(x3);
subplot(2,1,1)
plot(t,y31)
xlabel('time')
ylabel('y31')
title(' sum of weighted inputs' )
subplot(2,1,2)
plot(t,y3)
xlabel('time')
ylabel('y3')
title('output of sum of weighted inputs' )
%if(y3==y31)
if(y3-y31<1.0e-10)
disp ('linear system' )
else
disp('non linear system' )
end

17
AIM:- To explore the time variance and time invariance property of a given system.
Time Variant or Time Invariant Systems

INTRODUCTION
A system is said to be Time Invariant if its input output characteristics do not change with time.
Otherwise it is said to be Time Variant system.

As already mentioned time invariant systems are those systems whose input output
characteristics do not change with time shifting. Let us consider x(n) be the input to the system
which produces output y(n) as shown in figure below. Now delay input by k samples, it means our
new input will become x(n-k). Now apply this delayed input x(n-k) to the same system as shown in
figure below. Now if the output of this system also delayed by k samples (i.e. if output is equal to
y(n-k)) then this system is said to be Time invariant (or shift invariant) system.

If we observe carefully, x(n) is the initial input to the system which gives output y(n), if we delayed
input by k samples output is also delayed by same (k) samples. Thus we can say that input output
characteristics of the system do not change with time. Hence it is Time invariant system.

Theorem: A system is Time Invariant if and only if

Similarly a continuous time system is Time Invariant if and only if

To determine whether the given system is Time Invariant or Time Variant, we have to follow the
following steps:

Step 1: Delay the input x(n) by k samples i.e. x(n-k). Denote the corresponding output by y(n,k).

That means x(n-k)  ? y(n,k)

18
Step 2: In the given equation of system y(n) replace ‘n’ by ‘n-k’ throughout. Thus the output is y(n-
k).

Step 3: If y(n,k) = y(n-k) then the system is time invariant (TIV) and if y(n,k) ? y(n-k) then system is
time variant (TV).

PROGRAM 6
AIM:- To explore the time variance and time invariance property of a given system.

%time invariance
clc;
clear all;
t=[0:1:10]
x=@(t)(t.^2) %input signal
sys1=@(x)(x+5);
y1=sys1(x(t))
y2=sys1(x(t-2)) %response to delayed input
clf
axis([0 12 0 150])
subplot(2,1,1)
plot(t,y2);
xlabel('time')
ylabel('response')
title('respose to delayed input' )
axis([0 12 0 150])
subplot(2,1,2)
plot(t+2,y1);
xlabel('time')
ylabel('response')
title(' delayed response' )

19
AIM:- To demonstrate the convolution and correlation of two discrete-time signals.
Convolution And Cross-Correlation
INTRODUCTION
Convolution shows up in many aspects of astronomy, most notably in the point-source response
of an imaging system and in interpolation.  Convolution, which we will represent by   (the
symbol   is also frequently used for convolution),  multiplies one function f  by the time-reversed
function g, shifts g by some amount x, and integrates from −  to + .  The convolution h(x) of
the functions f and g is a linear functional of f(x) and g(x) defined by:  

h(x)=f g ∫ f (u) g (x−u) du)


−∞

Notice how the delta-function like part of the top function produces an image of the convolution
kernel in the result. For a time series, that kernel image defines the impulse response of the
system. For an antenna or imaging system that would be the point-source response. A very nice
applet showing how convolution works can be found here (there is also a discrete one).  And here
is a different one.

The convolution theorem is extremely powerful and states that the Fourier transform of the
convolution of two functions is the product of their individual Fourier transforms: 

f g FG

Cross-correlation is a very similar operation to convolution, except that the "kernel" is not time-
reversed during the operation. Cross-correlation is used extensively in interferometry and
aperture synthesis imaging, and is also used to perform optimal "matched-filtering" of data to find
and identify weak signals. Cross-correlation is represented by the pentagram symbol   and
defined by:  

f g ∫ f (u) g (u−x ) du
−∞

In this case, unlike for convolution, f(x) g(x) =g(x) f(x).

20
Very much related to the convolution theorem, the cross-correlation theorem states that the
Fourier transform of the cross-correlation of two functions is equal to the product of the individual
Fourier transforms, where one of them has been complex conjugated:  
f g FG

PROGRAM 7
AIM:- To demonstrate the convolution and correlation of two discrete-time signals.

%To demonstrate the convolution sum of two discrete time signal


clc;
clear all;
x=input('enter input siganl x' )
h=input('impulse response h' )
n1=input('enter lower limit x' )
n2=input('enter upper limit x' )
fprintf('instances of x' )
xlim=n1:n2
subplot(3,1,1)
stem(xlim,x)
xlabel('interval')
ylabel('x')
title('input signal' )
m1=input('enter lower limit h' )
m2=input('enter upper limit h' )
fprintf('instances of h' )
hlim=m1:m2
subplot(3,1,2)
stem(hlim,h)
xlabel('interval')
ylabel('h')
title('impulse response' )
k1=n1+m1
k2=n2+m2
fprintf('instances of convolved signal z' )
zlim=k1:k2
fprintf('values of convolved signal' )
z=conv(x,h)
subplot(3,1,3)
stem(zlim,z)

21
xlabel('interval')
ylabel('z')
title('convolved signal' )

AIM:- To visualize the continuous-time Fourier transform of a signal.


Continuous-Time Fourier Transform
INTRODUCTION
The Fourier transform is a reversible, linear transform with many important properties.  For any
function f(x) (which in astronomy is usually real-valued, but f(x) may be complex), the Fourier
transform can be denoted F(s), where the product of x and s is dimensionless.  Often x is a
measure of time t (i.e., the time-domain signal) and so s corresponds to inverse time, or
frequency  (i.e., the frequency-domain signal).  

The Fourier transform is defined by


F(s) ∫ f ( x)e−2 π isxdx


−∞

which is usually known as the forward transform, and 


f(x) ∫ F (s )e−2 π isxdx


−∞

which is the inverse transform.  In both cases, i −1 . Alternative definitions of the Fourier
transform are based on angular frequency ( =2 ), have different normalizations, or the
opposite sign convention in the complex exponential.  Since Fourier transformation is reversible,
the symmetric symbol   is often used to mean "is the Fourier transform of"; e.g., F(s) f(x).

The complex exponential is the heart of the transform.  A complex exponential is simply a complex
number where both the real and imaginary parts are sinusoids.  The exact relation is called Euler's
formula 

ei =cos +isin (SF3)

22
which leads to the famous (and beautiful) identity ei +1=0 that relates five of the most important
numbers in mathematics.  Complex exponentials are much easier to manipulate than
trigonometric functions, and they provide a compact notation for dealing with sinusoids of
arbitrary phase, which form the basis of the Fourier transform. Complex exponentials (or sines and
cosines) are periodic functions, and the set of complex exponentials is complete and orthogonal. 
Thus the Fourier transform can represent any piecewise continuous function and minimizes the
least-square error between the function and its representation. 

PROGRAM 8
AIM:- To visualize the continuous-time fourier transform of a signal
%Determine the CTFT of a signal
clc
clear all
syms t a w;
f=input('enter input signal')
k=fourier(f,t,w)
fprintf('the fourier transform of f is...')
disp(k)

23
AIM: - To visualize the Laplace Transform of a signal.

Laplace Transform
INTRODUCTION
The response of a Linear Time Invariant system with impulse response h(t) to a complex
exponential input of the form est can be represented in the following way :

Let

Where  H(s) is known as the Laplace Transform of h(t). We notice  that the limits are from [-
∞ to  +∞] and hence this transform is also referred to as Bilateral or Double sided Laplace
Transform. There exists a one-to-one correspondence between the h(t) and H(s)  i.e. the original
domain and the transformed domain. Therefore L.T. is a unique transformation and the 'Inverse
Laplace Transform' also exists.

24
Note that  est  is also an eigen function of the LSI system only if  H(s) converges. The range of
values for which the expression described above is finite is called as the Region of Convergence
(ROC). In this case, the  region of convergence is Re(s) > 0.

Thus,  the Laplace transform has two parts which are , the expression and region of convergence 
respectively. The region of convergence of the Laplace transform is essentially determined
by Re(s). Here onwards we will consider trivial examples for a better understanding of the ROC.

PROGRAM-9
AIM:- To visualize the laplace transform of a signal.
%Determine the laplace transform of a signal
clc
clear all
syms a b s t;
x=input('enter input signal')
Xs=laplace(x,t,s);
fprintf('the laplace transform of signal is...')
disp(Xs)

25

You might also like