You are on page 1of 26

EXPERIMENT - 1

• AIM: - Intro to MATLAB & its basic commands.


• SOFTWARE USED: - MATLAB.
• THEORY: -
 MATLAB is used for machine learning, signal processing, image processing,
computer vision, communications, computational finance, control design,
robotics, and much more.
 MATLAB platform is optimized for solving engineering and scientific problems.
The matrix-based MATLAB language is the world’s most natural way to express
computational mathematics.
 MATLAB code can be integrated with other languages, enabling you to deploy
algorithms and applications within web, enterprise, and production systems.
 MATLAB allows matrix manipulations, plotting of functions and data,
implementation of algorithms, creation of user interfaces, and interfacing with
programs written in other languages.
• PRIMARY COMMANDS: -
• help lists all primary help topics in the Command Window. Each main help topic
corresponds to a folder name on the MATLAB® search path.
• help name displays the help text for the functionality specified by name, such as
a function, method, class, toolbox or variable.
• Plot Draw a plot, see also figure, axis, subplot.
• Print Print the current plot (to a printer or postscript file)
• Subplot Divide the plot window up into pieces, see also plot, figure
• xlabel/ylabel Add a label to the horizontal/vertical axis of the current plot, see
also title, text, gtext
• PROS, & CONS.: -
PROS. CONS.
MATLAB contains a lot of advance There is not as much open source
toolboxes such as signal processing, code available because MATLAB
wavelet, etc. Find analogous functionality
requires a license
in other languages is possible but difficult
Good documentation You cannot integrate your code
into a web service
Good customer support MATLAB is expensive

• OUTPUT: -

Name Rollno
• RESULT: - The study of MATLAB and the various commands used in
MATLAB is complete.
• VIVA: -
1. What is MATLAB & where it is used?
MATLAB (matrix laboratory) is a multi-paradigm numerical computing
environment and fourth-generation programming language. ... MATLAB users
come from various backgrounds of engineering, science, and economics.
2. How to start and quit MATLAB?
START Select MATLAB Icon. On Microsoft® Windows® platforms, double-click
the MATLAB icon.
QUIT Click the Close box in the MATLAB® desktop.
Click on the left side of the desktop title bar and select Close.
Type quit or exit at the command prompt.

Name Rollno
3. What are the various desktop tools and windows used in MATLAB?

Start Button and Launch Pad--Run tools and access documentation for all of your
MathWorks products.
Command Window--Run MATLAB functions.
Command History--View a log of the functions you entered in the Command
Window, copy them, and execute them.
Help Browser--View and search the documentation for MATLAB.
Current Directory Browser--View MATLAB files and related files, perform file
operations such as open, and find content.
Workspace Browser--View and make changes to the contents of the workspace.

4. Explain 10-15 basic commands used in MATLAB.


Ans. MATLAB is an interactive program for numerical computation and data
visualization. You can enter a command by typing it at the MATLAB prompt '>>'
on the Command Window.
1. Commands for Managing a Session
Command Purpose
clc Clears command window.
clear Removes variables from memory.
exist Checks for existence of file or variable.

Name Rollno
global Declares variables to be global.
help Searches for a help topic.
2. Commands for Working with the System
Command Purpose

cd Changes current directory.

date Displays current date.

delete Deletes a file.

diary Switches on/off diary file recording.

3. Input and Output Commands


Command Purpose

disp Displays contents of an array or string.

fscanf Read formatted data from a file.

format Controls screen-display format.

fprintf Performs formatted writes to screen or file.

input Displays prompts and waits for input.

4. Vector, Matrix and Array Commands


Command Purpose
cat Concatenates arrays.
find Finds indices of nonzero elements.
length Computes number of elements.
linspace Creates regularly spaced vector.
5. Plotting Commands
print Prints plot or saves plot to a file.
title Puts text at top of plot.
xlabel Adds text label to x-axis.
ylabel Adds text label to y-axis.
axes Creates axes objects.
close Closes the current plot.

Name Rollno
EXPERIMENT – 2

• AIM: - To plot unit step, unit impulse, ramp, exponential functions


& sinusoidal signals.
• SOFTWARE USED: - MATLAB.
• PROGRAMS: -
%Generation of sine wave
t=0:0.01:pi;
x=sin(2*pi*t);
subplot(3,2,1);
plot(t,x);
title(‘sine wave’);
xlabel(‘time’);
ylabel(‘amplitude’);
%Generation of cosine wave
t=0:0.01:pi;
Y=cos(2*pi*t);
subplot(3,2,2);
plot(t,y);
title(‘cosine wave’);
xlabel(‘time’);
ylabel(‘amplitude’);
%Generation of Ramp wave
n=0,N-1;
r=n;
subplot(3,2,3);
stem(n,r);
title(‘Ramp signal’);
xlabel(‘time’);
ylabel(‘amplitude’);

Name Rollno
%Generation of exponential wave
N=input(‘enter the value of N’);
n=0:N-1;
a=input(‘enter the value of a’);
e=exp(a*n);
subplot(3,2,4);
stem(n,e);
title(‘Exponential signal’);
xlabel(‘time’);
ylabel(‘amplitude’);
%Generation of unit step function
s=ones(1,N);
subplot(3,2,5);
stem(n,s);
title(‘unit step function’);
xlabel(‘time’);
ylabel(‘amplitude’);
%Generation of unit impulse
ni=-2:1:2;
I=[zeros(1,2) ones(1,1) zeros(1,2)];
subplot(3,2,6);
stem(ni,I);
title(‘unit impulse function’);
xlabel(‘time’);
ylabel(‘amplitude’);

• OUTPUT: -

Name Rollno
• RESULT:- plotting of unit step, unit impulse, ramp , exponential
functions and sinusoidal signals using MATLAB software is
completed.

Name Rollno
EXPERIMENT-3
• AIM: - To plot unit step, unit impulse, ramp, exponential functions &
sinusoidal signals.
• SOFTWARE USED: - MATLAB.
• THEORY: -
convolution of two functions mathematically is given by: -

f(t)=x(t)*h(t)= ∫−∞ 𝑥𝑥(𝜏𝜏)ℎ(𝑡𝑡 − 𝜏𝜏)𝑑𝑑𝑑𝑑
• PROGRAMS: -
clc;
clear all;
close all;
%defination of i/p sequence
x=input('Enter the value of x');
nx=0:1;
subplot(3,1,1);
stem(nx,x);grid on;
title('Input Sequence');
xlabel('Time');
ylabel('Amplitude');
%Definatation of impulse sequence h
h=input('Enter the value of h');
nh=0:2;
subplot(3,1,2);
stem(nh,h);grid on;
title('Input impulse seq.');
xlabel('Time');
8ylabel('Amplitude');
%Convolution of x & h
nyl=nx(1)+nh(1);
nyr=nx(length(x))+nh(length(h));
ny=nyl:nyr;
y=conv(x,h)
subplot(3,1,3);
stem(ny,y);grid on;t
title('output Sequence');
xlabel('Time');
ylabel('Amplitude');

Name Rollno
• OUTPUT:-

• RESULT: - study of convolution of two functions using MATLAB is finished


successfully.

Name Rollno
EXPERIMENT: 4

AIM: To plot auto correlation and cross correlation of two sequences.

SOFTWARE USED: MATLAB R2012a

THEORY:

CROSS CORRELATION: In signal processing, cross-correlation is a measure of similarity of two series


as a function of the displacement of one relative to the other. This is also known as a sliding dot
product or sliding inner-product. It is commonly used for searching a long signal for a shorter, known
feature. It has applications in pattern recognition, single particle analysis, electron tomography,
averaging, cryptanalysis, and neurophysiology.

AUTO CORRELATION: Autocorrelation, also known as serial correlation, is the correlation of a signal
with a delayed copy of itself as a function of delay. Informally, it is the similarity between
observations as a function of the time lag between them. The analysis of autocorrelation is a
mathematical tool for finding repeating patterns, such as the presence of a periodic signal obscured
by noise, or identifying the missing fundamental frequency in a signal implied by its harmonic
frequencies. It is often used in signal processing for analysing functions or series of values, such as
time domain signals.
Unit root processes, trend stationary processes, autoregressive processes, and moving average
processes are specific forms of processes with autocorrelation.

PROGRAM:

Name Rollno
clear all;
close all;
clc;
% definition of x
x=input('Enter the value of x ');
nx=0:1;
subplot(4,1,1);
stem(nx,x);
grid on
xlabel('Time');
ylabel('Amplitude');
title('Definition of x ');
% definition of h
h=input('Enter the value of h ');
nh=0:2;
subplot(4,1,2);
stem(nh,h);
grid on
xlabel('Time');
ylabel('Amplitude');
title('Definition of h ');
% Autocorreletion of x & x
x1=fliplr(x);
nx1=-1:0;
nylac=nx(1)+nx1(1);
nyrac=nx(length(x))+nx1(length(x1));
yac=conv(x,x1);
nyac=nylac:nyrac;
subplot(4,1,3);
stem(nyac,yac);
grid on
xlabel('Time');
ylabel('Amplitude');
title('Auto correletion');
% Crosscorreletion of x & h
h1=fliplr(h);
nh1=-2:0;
nylcc=nx(1)+nh1(1);
nyrcc=nx(length(x))+nh1(length(h1));
ycc=conv(x,h1);
nycc=nylcc:nyrcc;
subplot(4,1,4);
stem(nycc,ycc);
grid on
xlabel('Time');
ylabel('Amplitude');
title('Cross correletion');
OUTPUT:

Name Rollno
Name Rollno
EXPERIMENT NO. 5
Aim : To plot the magnitude and phase plot spectrum of signal using Fourier
Series .

Software Used : R2017a

Theory :
Fourier series is just a means to represent a periodic signal as an infinite sum
of sine wave components. A periodic signal is just a signal that repeats its
pattern at some period. The primary reason that we use Fourier series is that
we can better analyze a signal in another domain rather in the original domain.
Fourier Series expansion is given below,
𝑇𝑇
Cn = 1/T ∫0 𝑥𝑥 (𝑡𝑡)𝑒𝑒 −𝑗𝑗𝑗𝑗𝑗𝑗𝑗𝑗 dt

• To plot the Magnitude spectrum calculate √𝑅𝑅2 + 𝐼𝐼2 and


𝐼𝐼
• To plot the phase spectrum, calculate tan−1 � �
𝑅𝑅
where, R is the Real part and I is the Imaginary part.

The function abs (|Cn|) returns the magnitude and angle (<Cn) returns the phase
angle in radians.
Magnitude Response is |Cn| vs. n and phase plot is <Cn vs. n.

Code / Program :

clc;
clear all;
close all;

syms t;
T = pi;
w = 2*pi/T;
xt = exp(-t/2);
n = -4:4;
Cn = 1/T*int(xt*exp(-1j*w*n*t),t,0,T);
Cn = double(Cn)
magnitudeCn = abs(Cn) %magnitude
angleCn = angle(Cn) %angle

subplot(2,1,1);

Name Rollno
stem(n,magnitudeCn);
grid on
xlabel('n');
ylabel('|Cn|');
title('Magnitude Plot');

subplot(2,1,2);
stem(n,angleCn);
grid on
xlabel('n');
ylabel('<Cn');
title('Phase Plot');

Output :

Name Rollno
Result : The magnitude and phase plot spectrum of signals are plotted using
Fourier Series .

Name Rollno
EXPERIMENT NO. 6
Aim : To plot the magnitude and phase plot spectra of signal using Fourier
Transforms.

Software Used : R2017a

Theory:
A function derived from a given function and representing it by a series of
sinusoidal functions. The Fourier Transform decomposes any function into a
sum of sinusoidal basis functions. Each of these basis functions is a complex
exponential of a different frequency.
The following definition:

F(s) = ∫−∞ 𝑓𝑓(𝑥𝑥)𝑒𝑒 −2ð𝑗𝑗𝑗𝑗𝑗𝑗 𝑑𝑑𝑑𝑑
for any real number .

Code / Program :

clc;
clear all;
close all;
syms t omega;
xt = 2;
expw = exp (-j*omega*t) ;
xjw = int (xt*expw,omega,-2,2) ;
xjw = simplify (xjw) ;
figure (1) ;
subplot (2,1,1) ;
ezplot ('2',[-2 2]) ; grid on
subplot (2,1,2) ;
ezplot(xjw); grid on

Name Rollno
Output :

Result : The magnitude and phase plot spectra of signals are plotted using
Fourier Transform.

Name Rollno
Experiment No. 7
Aim:Determine and plot discrete time Fourier time transform of the following: - (A)
Rectangularfunction (B) Sinusoidalfunction.

SoftwareUsed:Matlab(R2017a)

Theory: In mathematics, the discrete-time Fourier transform (DTFT) is a form of


Fourier analysis that is applicable to the uniformly spaced samples of a continuous
function. The term discrete time refers to the fact that the transform operates on
discrete data (samples) whose interval often has units of time. From only the
samples, it produces a function of frequency that is a periodic summation of the
continuous Fourier transform of the original continuous function. Under certain
theoretical conditions, described by the sampling theorem, the original continuous
function can be recovered perfectly from the DTFT and thus from the original
discrete samples. The DTFT itself is a continuous function of frequency, but discrete
samples of it can be readily calculated via the discrete Fourier transform (DFT) (see
Sampling the DTFT), which is by far the most common method of modern Fourier
analysis.

DTFT =

CODE:
clc;
clear all;
close all;

%1.Rectangular Function:
n1=-2:2;
xn=ones(1,5);
k=-400:400;
w=(pi/100)*k;
Xw=xn1*(exp(-1*j*pi/100).^(n1'*k));
magXw1=abs(Xw);
subplot(221)
stem(-8:8,[zeros(1,6) xn1 zeros(1,6)]);

Name Rollno
xlabel('n');
ylabel('x');
title('Rectangular Signal');
subplot(223)
plot(w/pi,magXw1);
xlabel('frequency in pi units');
ylabel('magnitude');
title('DTFT');
n2=0:100;
xn2=cos(pi*n2/4);

%2.Sinusoidal Signal:
Xw2=xn2*(exp(-1*j*pi/100).^(n2'*k));
magXw2=abs(Xw2);
subplot(222)
stem(n2,xn2);
axis([0 100 -1.5 1.5]);
xlabel('n');
ylabel('xn');
title('sinusoidal signal');
subplot(224)
plot(w/pi,magXw2);
xlabel('frequency in pi units');
ylabel('magnitude');
title('DTFT');

Output:

Name Rollno
Result:The DTFT of the Rectangular and Sinusoidal functions are plotted
successfully.

Name:Eisha Goel
Branch:ECE(First Shift)
Section:S3
Enrollment Number:
01615602818

Name Rollno
Experiment No. 8

Aim:Write a program of sampling at:


A) Less than Nyquist rate (fs<2fm)
B) Nyquist rate (fs = 2fm)
C) Above Nyquist rate (fs>2fm)

Software Used:Matlab (R2017a)

Theory:
The Nyquist Theorem, also known as the sampling theorem, is a principle that
engineers follow in the digitization of analog signals. For analog-to-digital conversion
(ADC) to result in a faithful reproduction of the signal, slices, called samples, of the
analog waveform must be taken frequently. The number of samples per second is
called the sampling rate or sampling frequency.

Any analog signal consists of components at various frequencies. The simplest case
is the sine wave, in which all the signal energy is concentrated at one frequency. In
practice, analog signals usually have complex waveforms, with components at many
frequencies. The highest frequency component in an analog signal determines the
bandwidth of that signal. The higher the frequency, the greater the bandwidth, if all
other factors are held constant.

Suppose the highest frequency component, in hertz, for a given analog signal is
fmax. According to the Nyquist Theorem, the sampling rate must be at least 2fmax,
or twice the highest analog frequency component. The sampling in an analog to
digital converter is actuated by a pulse generator (clock). If the sampling rate is less
than 2fmax, some of the highest frequency components in the analog input signal
will not be correctly represented in the digitized output. When such a digital signal is
converted back to analog form by a digital-to-analog converter, false frequency
components appear that were not in the original analog signal. This undesirable
condition is a form of distortion called aliasing.

Code:
clc;
close all;

clear all;

t=0:0.01:1;

fm=input('enter frequency fm'); xt=cos(2*pi*fm*t);

Name Rollno
subplot(411);
plot(t,xt);
title('cos function');
xlabel('time---->');
ylabel('amplitude------->');

%program sampling at (A)(fs<2fm):


fs1=1.3*fm;
n1=0:1/fs1:1;
xn1=cos(2*pi*fm*n1);
subplot(412);
plot(t,xt,'r',n1,xn1,'b');
title('undersmapling');
xlabel('time------->.');
ylabel('amplitude------->');

%program sampling at (B)(fs=2fm):


fs2=2*fm;
n2=0:1/fs2:1;
xn2=cos(2*pi*fm*n2);
subplot(413);
plot(t,xt,'r',n2,xn2,'b');
title('nyquist rate');
xlabel('time');
ylabel('amplitude');

%program sampling at(C)fs<2fm:


fs3=2.9*fm;
n3=0:1/fs3:1;
xn3=cos(2*pi*fm*n3);
subplot(414);
plot(t,xt,'r',n3,xn3,'b');
title('oversampling');
xlabel('time------->');
ylabel('amplitude------>');

Output:

Name Rollno
Result:The program of sampling for the given rates has been done successfully.

Name: Eisha Goel


Branch:ECE(First shift)
E.Number:01615602818

Name Rollno
Experiment No. 9

Aim:To find the z transform of a given causal system and check the stability using
pole zero location.
Y (n) = 0.9 y (n-1) +x (n)

Software Used:Matlab (R2017a)

Theory: In mathematics and signal processing, the Z-transform converts a


discrete-time signal, which is a sequence of real or complex numbers, into a complex
frequency domain representation.

It can be considered as a discrete-time equivalent of the Laplace transform. This


similarity is explored in the theory of time scale calculus.

Code:
%z transform
clc;
close all;
clear all;
b=[1]; a=[1 -0.9];
zplane(b,a);
w=[-200:1:200]*pi/100;
H=freqz(b,a,w);
magH=abs(H)
angH=angle(H)
figure;
subplot(211);
plot(w/pi,magH);
xlabel('frequency in pi units ');
ylabel('magnitude');
title('magnitude response');
subplot(212);
plot(w/pi,angH);
xlabel('frequency in pi units ');

ylabel('phase in pi units');

title('phase response');

Name Rollno
Output:

Name Rollno
Result:The z transform of the given causal system has been found successfully
and the stability of the system using pole zero location has been checked.

Name:Eisha Goel
Branch:ECE(First Shift)
Section:S3
Enrollment Number:
01615602818

Name Rollno

You might also like