Professional Documents
Culture Documents
UNIVERSITY OF LUCKNOW
(LAB)
SHAMBO BASU
ELECTRONICS AND COMMUNICATION
46
INDEX
Sr No. Program Signature
1. INTRODUCTION TO MATLAB
The MATLAB is a high-level language and interactive environment
for numerical computation, visualisation and programming. The
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. Built-in graphics
make it easy to visualize and gain insights from data. A vast library of
pre-built toolboxes lets you get started right away with algorithms
essential to your domain. The desktop environment invites
experimentation, exploration, and discovery. These MATLAB tools
and capabilities are all rigorously tested and designed to work together.
MATLAB works beyond the desktop and can run analyses on larger
data sets, and scale up to clusters and clouds. MATLAB code can be
integrated with other languages, enabling algorithms and applications
within web, enterprise, and production systems.
Key Features
• High-level language for scientific and engineering computing.
• Desktop environment tuned for iterative exploration, design, and
problem-solving.
• Graphics for visualizing data and tools for creating custom plots
• Apps for curve fitting, data classification, signal analysis, control
system tuning, and many other tasks.
• Add-on toolboxes for a wide range of engineering and scientific
applications.
• Tools for building applications with custom user interfaces
• Interfaces to C/C++, Java®, .NET, Python, SQL, Hadoop, and
Microsoft® Excel®.
• Royalty-free deployment options for sharing MATLAB programs
with end users.
Command History: View or rerun commands that you entered at the command
line.
You can create symbolic numbers by using sym. Symbolic numbers are
exact representations, unlike floating-point numbers. To declare multiple
symbolic variables it can be done by
syms t s w;
(b) To define and use Vectors and Matrices in MATLAB
A matrix, vector can be defined in MATLAB as
Basic mathematical functions work as intended like ‘+’ , ‘-‘ , ’/’ and ‘*’.
%auto-correlation
n=-0:1:3;
xn=[1 2 5 3];
yn=xcorr(xn);
subplot(2,1,1); stem(n,xn);
xlabel('n');ylabel('x(n)');
subplot(2,1,2);stem(yn);
xlabel('n');ylabel('y(n)');
title('Autocorrelation of x(n)=[1 2 5 3]');
(b)Write a MATLAB program to compute cross correlation of a sequences
x(n) and y(n)
%cross-correlation
nx=0:1:3;
xn=[1 2 5 3];
ny=-2:1:2;
yn=[3 -2 4 1 0];
yy=fliplr(yn);
lx=length(xn);
ly=length(yn);
lxy=lx+ly-1;
fnx=[xn zeros(1,lxy-lx)];
fny=[yy zeros(1,lxy-ly)];
for k=0:lxy-1
sum=0;
for n=0:k
sum=sum+fnx(n+1)*fny(k-n+1);
end
rxy(k+1)=sum;
end
subplot(3,1,1); stem(nx,xn);title('x(n)');
xlabel('n');ylabel('x(n)');axis([-0.5 3.5 0 5.5]);
subplot(3,1,2);stem(ny,yn);title('y(n)');
xlabel('n');ylabel('y(n)');axis([-2.5 2.5 -2.5 4.5]);
nxy=-2:1:5;
subplot(3,1,3);stem(nxy,rxy);
xlabel('n');ylabel('amplitude');axis([-2.5 4.5 min(rxy)-0.5
max(rxy)+0.5]);
title("Cross-Correaltion of x(n) and y(n)");
6.Laplace Transform
(a)Write a MATLAB program to calculate Laplace transform of signals
%laplace transform
syms t;
x=exp(-t);
y=x*cos(10*t);
subplot(4,2,1);ezplot(x,[0,5]);
axis([0 5 0 1.1]);title('x(t)');
subplot(4,2,2);ezplot(y,[-1,5]);
axis([0 5 -1.1 1.1]);title('y(t)');
disp('laplace transform of x(t) is')
X=laplace(x)
disp('laplace transform of y(t) is')
Y=laplace(y)
Xm=abs(X);
Ym=abs(Y);
subplot(4,2,3);ezplot(Xm);
title('Magnitue response of X(s)');
subplot(4,2,4);ezplot(Ym);
title('Magnitude response of Y(s)');
OUTPUT
laplace transform of x(t) is
X =1/(s + 1)
OUTPUT
Enter the numerator coefficients:
[1 1]
Enter the denominator coefficients:
[2 2 1]
Residues in the partial fraction are
0.2500 - 0.2500i
0.2500 + 0.2500i
OUTPUT
Fourier transform of x(t) is
(4*sin(2*w))/w
(b) Z Transform
syms n w;
x1=n+1;
disp('The input signal is');
disp(x1);
X1=ztrans(x1);
disp('The Z-Transform is');
disp(X1);
X11=iztrans(X1);
disp('The inverse Z-Transform is');
disp(X11);
x2=sin(n*w);
disp('The input signal is');
disp(x2);
X2=ztrans(x2);
disp('The Z-Transform is');
disp(X2);
X22=iztrans(X2);
disp('The inverse Z-Transform is');
disp(X22);
OUTPUT
The input signal 1 is
n + 1
The Z-Transform is
z/(z - 1) + z/(z - 1)^2
The Z-Transform is
(z*sin(w))/(z^2 - 2*cos(w)*z + 1)
OUTPUT
The input signal is
X(z)=z^3/((z-0.5)(z-0.75)(z-1))
r1=1.00 p1=1.00
r2=0.00 p2=-2.25
r3=0.00 p3=1.63
9.Discrete time Fourier Transform
(a) Write a MATLAB program to calculate the DTFT of a sequence
n=-4:1:4;
x=[zeros(1,2) ones(1,5) zeros(1,2)];
k=-4:4;
w=(pi)*k;
X=x*(exp(-1j*pi/100)).^(n'*k);
subplot(3,1,1);stem(n,x);
title('Discrete time n');ylabel('amplitude');
Xm=abs(x);
subplot(3,1,2);
plot(w/pi,Xm);
title('Magnitude of DTFT of rectangular signal');
xlabel('Frequency in pi units');ylabel('Phase');
Xp=phase(X);
subplot(3,1,3);plot(w/pi,Xp);
title('Phase of DTFT of rectangular signal');
xlabel('Frequency in pi units');ylabel('Magnitude');
10.Write a MATLAB program to plot
magnitude and phase response of a given
system
%fourier transform
syms t w;
x=exp(-2*t).*heaviside(t);
subplot(3,1,1);ezplot(x);
title('x(t)=e^-2t');
disp('The fourier transform of x(t) is')
X=fourier(x)
X=simplify(X);
subplot(3,1,2);ezplot(abs(X));
title('Magnitude response of x(t)');
subplot(3,1,3);ezplot(atan(imag(X)/real(X)));
title('Phase Response of x(t)');