MATLAB Full Lab Report

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 30

Lab Report

Signals and Systems


Lab # 1st
Title:
To plot a continuous time signal.

Introduction:
This lab is based on generation of a continuous time signal by MATLAB

Software simulation:
MATLAB is used for performing experiment.

CONTINUOUS TIME SIGNAL GENERATION.


Program And Simulation:
%GENERATING A CONTINOUS TIME SIGNAL:
amp=2;
f=100;
phase=pi/4;
T=1/f;
t=[0:1/200:3]*T;
x=amp*sin(2*pi*f*t+phase);
plot(t,x,'LineWidth',2);
xlabel('TIME');
ylabel('AMPLITUDE');
title('CONTINOUS TIME SIGNAL');
grid on;
axis([0 0.03 -2.5 2.5]);

Results:
Lab # 2nd
Title:
To plot a simple oscillatory function.

Introduction:
This lab is based on generation of an oscillatory function.

Software simulation:
MATLAB is used for performing experiment.

GENERATING SINOSOIDAL OSCILLATIONS


Program And Simulation:
%CASE 1:DAMPED OSCILLATIONS:
c=2;
a=-2; %a<0
f=50;
ph=0;
T=1/f;
t=0:T/20:40*T;
x1=c*exp(a*t);
x2=sin(2*pi*f*t+ph);
x=x1.*x2;
subplot(3,1,1);
plot(t,x,'LineWidth',1);
xlabel('TIME');
ylabel('AMPLITUDE');
title('DAMP OSCILLATIONS(a<0)');
grid on;
%CASE 1:UNDAMPED OSCILLATIONS:
c=2;
a=0; %a=0
f=50;
ph=0;
T=1/f;
t=0:T/20:40*T;
x1=c*exp(a*t);
x2=sin(2*pi*f*t+ph);
x=x1.*x2;
subplot(3,1,2);
plot(t,x,'LineWidth',1);
xlabel('TIME');
ylabel('AMPLITUDE');
title('UNDAMPED OSCILLATIONS(a>0)');
grid on;

%CASE 3:SUSTAINED OSCILLATIONS:


c=2;
a=2; %a>0
f=50;
ph=0;
T=1/f;
t=0:T/20:40*T;
x1=c*exp(a*t);
x2=sin(2*pi*f*t+ph);
x=x1.*x2;
subplot(3,1,3);
plot(t,x,'LineWidth',1);
xlabel('TIME');
ylabel('AMPLITUDE');
title('SUSTAINED OSCILLATIONS(a=0)');
grid on;

Results:
Lab # 3rd
Title:
To plot a simple discrete time signal.

Introduction:
This lab is based on generation of a discrete time signal.

Software simulation:
MATLAB is used for performing experiment.

GENERATING DISCRETE TIME SIGNAL


Program And Simulation:
%CASE1(a>1)
c=2; %variable for scaling
a=7; %variable for base
n=0:15; %variable for index
x=c*a.^n; %signal
figure(1);
subplot(2,1,1);
stem(n,x,'LineWidth',1.5);
title('CASE a>1');
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;
%CASE2(0<a<1)
c=2;
a=0.6;
n=0:15;
x=c*a.^n;
subplot(2,1,2);
stem(n,x,'LineWidth',1.5);
title('CASE 0<a<1');
xlabel('TIME');
ylabel('AMPLITUDE');
title('CASE 0<a<1')
grid on;
%CASE3(-1<a<0)
c=2;
a=-0.5;
n=0:15;
x=c*a.^n;
figure(2);
subplot(2,1,1);
stem(n,x,'LineWidth',1.5);
title('CASE -1<a<0');
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;

%CASE4(a<-1)
c=2;
a=-5;
n=0:15;
x=c*a.^n;
subplot(2,1,2);
stem(n,x,'LineWidth',1.5);
title('CASE a<-1');
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;
%CASE5(a=1)
c=2;
a=1;
n=0:15;
x=c*a.^n;
figure(3);
subplot(2,1,1);
stem(n,x,'LineWidth',1.5);
title('CASE a=1');
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;
%CASE6(a=-1)
c=2;
a=-1;
n=0:15;
x=c*a.^n;
subplot(2,1,2);
stem(n,x,'LineWidth',1.5);
title('CASE a=-1');
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;

Results:
Lab # 4TH
Title:
To plot a simple piecewise signal.

Introduction:
This lab is based on generation of a Piecewise signal.

Software simulation:
MATLAB is used for performing experiment.

GENERATING PIECEWISE SIGNAL


Program And Simulation:
%for the first segment
t0=-5:0.01:-3;
x0=zeros(size(t0));
%for the second segment
t1=-3:0.01:-2;
x1=-t1-3;
%for the third segment
t2=-2:0.01:-1;
x2=ones(size(t2));
%for the fourth segment
t3=-1:0.01:0;
x3=2*ones(size(t3));
%for the fifth segment
t4=0:0.01:1;
x4=2*ones(size(t4));
%for the sixth segment
t5=1:0.01:2;
x5=-t5+2;
%for last segment
t6=2:0.01:5
x6=zeros(size(t6));
x=[x0 x1 x2 x3 x4 x5 x6];
t=[t0 t1 t2 t3 t4 t5 t6];
plot(t,x,'LineWidth',2);
xlabel('TIME');
ylabel('AMPLITUDE');
title('PIECEWISE SIGNAL');
axis([-5 +5 -1.5 +2.5]);
grid on;
Results:
Lab # 5TH
Title:
Scaling And Time Shifting.

Introduction:
This lab is based on scaling and time shifting.

Software simulation:
MATLAB is used for performing experiment.

GENERATING DIFFERENT SIGNAL


Program And Simulation:
figure(1); %Figure 1
t=-2*pi:pi/10:2*pi;
x1=sin(t);
subplot(2,1,1);
plot(t,x1,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

x2=sin(2*t);
subplot(2,1,2);
plot(t,x2,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (2t)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

figure(2); %Figure 1
t=-2*pi:pi/10:2*pi;
x1=sin(t);
subplot(2,1,1);
plot(t,x1,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

x3=sin(0.5*t);
subplot(2,1,2);
plot(t,x3,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t/2)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

figure(3); %Figure 3
t=-2*pi:pi/10:2*pi;
x1=sin(t);
subplot(2,1,1);
plot(t,x1,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

x4=sin(-t);
subplot(2,1,2);
plot(t,x4,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (-t)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

figure(4); %Figure 4
t=-2*pi:pi/10:2*pi;
x1=sin(t);
subplot(2,1,1);
plot(t,x1,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

x5=sin(t+(pi/2));
subplot(2,1,2);
plot(t,x5,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t+pi/2)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;
figure(5); %Figure 5
t=-2*pi:pi/10:2*pi;
x1=sin(t);
subplot(2,1,1);
plot(t,x1,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

x6=sin(t-(pi/2));
subplot(2,1,2);
plot(t,x6,'linewidth',2);
Xlabel('Time t');
Ylabel('Sin (t-pi/2)');
axis([-2.5*pi 2.5*pi -1.25 1.25]);
set(gca,'Xtick',-2.5*pi:pi/2:2.5*pi);
set(gca,'Ytick',-2.5:0.25:2.5);
grid on;

Results:
Lab # 6TH
Title:
Continuous time Convolution of a signal.

Introduction:
This lab is based on convolution.

Software simulation:
MATLAB is used for performing experiment.

GENERATING CONVOLVED SIGNAL


Program And Simulation:

%Continuous time Convolution


t=0:0.01:10;
x=sin(t);
h=2*exp(-t);
y=conv(x,h);
t1=-10:0.01:10;
xlabel('Time');
ylabel('Sin(t)');
subplot(3,1,1);
plot(t,x,'linewidth',2);
title('Input');
grid on;
xlabel('Time');
ylabel('h(t)');
subplot(3,1,2);
plot(t,h,'linewidth',2);
title('Immpulse response of system');
grid on;
subplot(3,1,3);
plot(t1,y,'linewidth',2);
xlabel('Time');
ylabel('y(t)');
title('Convolved Signal');
grid on;
Results:
Lab # 7TH
Title:
Discerete time Convolution of a signal.

Introduction:
This lab is based on convolution.

Software simulation:
MATLAB is used for performing experiment.

GENERATING CONVOLVED SIGNAL


Program And Simulation:
%Discrete Time Convolution of a signal
n=0:10;
x=sin(n); %input
h=(2/3).^n; %Impulse responce
y=conv(x,h); %output
n1=-10:10; %array equal Y array
subplot(3,1,1);
stem(n,x); %plotting input signal
grid on;
title('Input Signal');

subplot(3,1,2);
stem(n,h); %Plotting Impulse Responce
title('Impulse Responce Of System');
grid on;
subplot(3,1,3);
stem(n1,y); %plotting of output Of system
title('Convoled Signal');
grid on;
Results:
Lab # 8TH
Title:
Solving Derivative, Partial Derivative, Integral, Definite
Integral.

Introduction:
This lab is based on solving equation.

Software simulation:
MATLAB is used for performing experiment.

SOLVING EQUATIONS
Program And Simulation:
%solving derivative, partial derivative, Integral, definite
integral
clc
clear all

syms a b c d e g h f1 f2 f3 x y;

%Derivative
f1=3*x^3-4*x^2+5*x-3;
a=diff(f1,x) %First order derivative
b=diff(a,x) %2nd Order derivative
c=diff(b,x) %3rd Order derivative

%Partial derivative
f2=x^2*y+x*y^3-x^3+y^2;
d=diff(f2,x) %Derivative w.r.t x
e=diff(f2,y) %Derivative w.r.t y

%Integral
f3=3*x^3-4*x^3;
g=int(f3,x)
h=int(f3,x,0,5) %Definite Integral
Results:
a = 9*x^2 - 8*x + 5
b = 18*x – 8
c = 18
d = - 3*x^2 + 2*x*y + y^3
e = x^2 + 3*x*y^2 + 2*y
g = -x^4/4
h = -625/4

Lab # 9TH
Title:
Implementation of Laplace Transform & Z-Transform.

Introduction:
This lab is based on solving equation.

Software simulation:
MATLAB is used for performing experiment.

CALCULATING LAPLACE TRANSFORM &


Z-TRANSFORM OF EQUATIONS
Program And Simulation:
%Laplace Z-transform
clc
clear all
syms f1 f2 t n x2 x1; %Symbolic Object Construction
f1=1/sqrt(t);
x1=laplace(f1) %Laplace Transform

f2-(0.5)^(n-3);
x2=ztrans(f2) %Z-Transform
Results:
x1 = pi^(1/2)/s^(1/2)
x2 = z/(z - 1)^2
Lab # 10TH
Title:
Plot Continuous time square wave & Triangular wave

using Fourier series.

Introduction:
This lab is based on solving equation.

Software simulation:
MATLAB is used for performing experiment.

Square waves & Triangular Waves.


Program And Simulation:
%Square Wave
clc
clear all
s_wave=0; %initialization
t=0:0.004:8; %time axis

for n=1:2:1000 %Value of n(Odd) for given instant of time


sq_wave=((4/(n*pi))*sin(n*pi*t));%Simplified Fourier Expression
s_wave=s_wave+sq_wave; %adding all terms
end
subplot(2,1,1);
plot (t,s_wave); %plotting
axis([0 8 -2 2]); %defining axis
title ('Square Wave');
ylabel ('Amplitude');
xlabel ('Time(sec)');
grid on;

%Triangular Wave
clc
clear all
t_wave=0;
t=0:0.01:10;
for n=1:2:1000
trngl_wave=(8/(n^2*pi^2))*((-1)^((n-1)/2))*(sin(n*pi*t/2));
t_wave=t_wave+trngl_wave;
end
subplot(2,1,2);
plot(t,t_wave);
axis([0 10 -2 2]);
title('Triangular Wave');
xlabel('Time');
ylabel('Amplitude');

Results:
Lab # 11TH
Title:
a) Fourier series.

b) Fourier Transform & Inverse Fourier transform.

Introduction:
This lab is based on solving equation & Plotting.

Software simulation:
MATLAB is used for performing experiment.
Program And Simulation:
%Fourier Series
clc
clear all
syms x y
f=exp(-x^2);
fourier(f,x,y)

%Fourier Transform & Inverse Fourier Transform


clc
clear all
t=0:100;
f=-50:50;
x=exp(-2*t);
figure;
plot(t,x); %plotting signal
xlabel('Time');
ylabel('Amplitude');
title('Signal');

y=fft(x);
figure;
plot(f,y);
xlabel('Frequency');
ylabel('Amplitude');
title('Fourier Transform');

z=ifft(y);
figure;
plot(t,z);
xlabel('Time');
ylabel('Amplitude');
title('Inverse Fourier Transform');

Results:

Signal:

F.T:
Inverse F.T:
Lab # 12TH
Title:
Introduction to Simulink.

Introduction:
This lab is based on convolving signals.

Software simulation:
MATLAB is used for performing experiment.
Program And Simulation:
Results:

You might also like