You are on page 1of 29

Lab Experiment 05

Unit impulse
Unit Step
Complex Signals
Unit Impulse
General Syntex
x=[n==0];
n=[-5:5];
x=[n==0];
stem(n,x);
grid on
xlabel('x-axis');
ylabel('y-axis');
title('unit impulse at zero');

Unit Step
n=[-5:5];
x=[n>=0];
Stem(n,x);
//Give the unit step at zero;
%Unit step
%example
n=[-5:10];
x=[n>=0];
%stem(n,x);
%unit step at zero
title('unit step at zero');

x=[n>=4];
stem(n,x);
title('unit step at 4');

Unit step at 4

Complex Signals
General Syntax
x=exp^(-0.7+4j);
0=<n<=1;
Stem(n,real(x)); //plot the real part of signal;
Stem(n,imag(x)); //plot the imaginary part of signal;
Stem(n,abs(x));

//plot the absolute value of signal;

Stem(n,(180/pi)*angle(x)); //plot the phase of signal;

Signal Addition
+ operater is used to add two signals
%Signal Addition Example
n1=[-1:3];
y1=[10 5 10 5 10];
n2=[-1:3];
y2=[1 3 5 7 9];
y=y1+y2;
n=[-1:3];
subplot(3,1,1);

stem(n1,y1);
grid on;
title('first signal');
subplot(3,1,2);
stem(n2,y2);
grid on;
title('second signal');
subplot(3,1,3);
stem(n,y);
grid on;
title('ssignal after addition');

Signal Multiplication
.* operater is used to multiply two signals
%Signal multiplication Example
n1=[-1:3];
y1=[10 5 10 5 10];
n2=[-1:3];
y2=[1 3 5 7 9];
y=y1.*y2;
n=[-1:3];
subplot(3,1,1);
stem(n1,y1);
ylim([0 25]);
grid on;
title('first signal');
subplot(3,1,2);
stem(n2,y2);
ylim([0 25]);
grid on;
title('second signal');
subplot(3,1,3);
stem(n,y);
grid on;
title('signal after mulptiplication');

Scalling of Signals
%Scalling
n=[0:4];
y=[2 5 6 7 8];
y1=y.*3.5;
subplot(2,1,1);
stem(n,y);
xlim([0 8]);
ylim([0 20]);

grid on;
title('original signal');
subplot(2,1,2);
stem(n,y1);
title('scalled signal');
grid on;

Shifting Of Signals
%Shifting
n=[2:6];
x=[1 2 3 4 5];
%Right shifting
m=n+3;
y=x;
%Left shifting
t=n-2;
z=x;
subplot(3,1,1);
stem(n,x);
xlim([0 10]);
title('original signal');
grid on;
subplot(3,1,2);
stem(m,y);
xlim([0 10]);
title('3 unit Right shifted signal');
subplot(3,1,3);
stem(t,z);
xlim([-3 10]);
title('2 unit Left shifted signal');

Folding Of Signals
%Flipping
x=[1 2 3 4 5];
n=[0:4];
subplot(3,1,1);
stem(n,x);
grid on;
title('original signal');
subplot(3,1,2);
y1=fliplr(x);
stem(n,y1);
grid on;
title('Flipped signal');
subplot(3,1,3);
y2=-fliplr(x);
stem(n,y2);
grid on;
title('Flipped signal');

Lab Task 01
%part a
n=[-5:5];
x=2*[n==-2]-[n==4];
subplot(3,1,1);
stem(n,x);
title('Lab 5 Task 1 part a');

grid on;
%part b
n=[0:20];
x=n.*([n>=0]-[n>=10])+10.*exp(-0.3.*(n-10)).*([n>=10]-[n>=20]);
subplot(3,1,2);
stem(n,x);
title('Lab 5 Task 1 part b');
grid on;
%part 3
n=[0:50];
x=cos(0.04.*pi.*n)+0.2.*randn(size(n));
subplot(3,1,3);
stem(n,x);
title('Lab 5 Task 1 part c');
grid on;

Lab Task 02
%Lab 5 Task 2 Energy and power of a signal
%part a
t=[0:2];
x=10.*cos(100.*t+pi/3);
energy=sum(abs(x).^2);

energy =

200.6135
power=energy/length(t);
power =

66.8712
%part b
t=[0:1];
signal=(10+2.*sin(3.*t)).*cos10.*t;
energy=sum(abs(signal).^2);

energy =
174.4344
power=sum(abs(signal).^2)/length(t);
power =
87.2172

Lab Task 03
complex exponential signal
n=[-10:10];
x=exp((-0.1+0.3i).*n);
subplot(2,2,1);
%Real part of signal
stem(n,real(x));
grid on;
title('Real part of signal');
subplot(2,2,2);
%imaginary part of signa
stem(n,imag(x));
grid on;
title('imaginary part of signal');
subplot(2,2,3);
%absolute vale of signal
stem(n,abs(x));
grid on;
title('Absolute value of signal');
subplot(2,2,4);
%Phase of signal
stem(n,(180/pi).*angle(x));
grid on;title('phase of signal');

Lab Task 04
%Lab 5 task 4
%Shifting and scalling
n=[-2:10];
x=[1 2 3 4 5 6 7 6 5 4 3 2 1];
subplot(2,2,1);
stem(n,x);
grid on;
title('original signal');
%part a
m=n-5;

z=x;

subplot(2,2,2);
stem(m,z);
grid on;
title('5 units left shifted signal');
%part b
s=n+7;
g=x;
subplot(2,2,3);
stem(s,g);
grid on;
title('7 units Right shifted signal');
%part c
t=6*x;
subplot(2,2,4);
stem(n,t);
grid on;
title('Scalled signal');

Lab Experiment 04
Function plotting in Matlab
A function, in mathematics, associates one quantity, the argument of the function, also known
as the input, with another quantity, thevalue of the function, also known as the output.

y='cos(tan(x))-tan(sin(x))';

fplot(y,[0 50]);
xlabel('x-axis');
ylabel('y-axis');
title('function plotting ,graph of a function');
grid on
gtext('function..gtext');

Draw more then one function on same graph


Hold command is used to draw more then one function on same graph
x=[0:0.1:10];
y=sin(x);
z=x;

plot(x,y);
hold

plot(x,z);
title('hold');

Plotting
%General syntex

[0=<x<=50]

%Matlab Syntex for plotting


x=[0:0.01:50];
y=x.^2+2.*x;

plot(x,y);
%To label x and y axis
xlabel('x-axis');
ylabel('y-axis');
%To give title
title('graph between x and y');
%Grid
grid on
%To set the range of x and y axis
axis([0 50 0 2600]);

[Matlab only plot the real part of graph]

Subplotting
general Syntex
subplot(2,2,1)
2 rows 2 columns
x=[0:0.01:50];
y=sin(x);
z=sin(x);
t=sin(x);
s=sin(x);

subplot(2,2,1);
plot(x,y);

subplot(2,2,2);
plot(x,z);

subplot(2,2,3);
plot(x,t);

subplot(2,2,4);
plot(x,m);
plot(x,s);
title('subplotting');

Lab Task 01
t=[0:0.01:8];
z=exp(-0.5)*cos(20.*t-6);
plot(t,z);
xlabel('x-axis');
ylabel('y-axia');
title('graph of funcion 1,,,,Lab task#1');
grid on

Lab Task 02
%use of hold command
x=[0:0.001:1];
y1=cosh(x);
y2=0.5*exp(x);

plot(x,y1,'*');
hold
plot(x,y2,'--');
xlabel('x1,x2'); %q_3

%use of hold command


x=[0:0.01:1];
y=sin(x);
y1=x-x.^3/3;

plot(x,y,'^');
xlabel('x');
ylabel('y,y1');
gtext('sin');
hold

plot(x,y1,'-');
gtext('function');
title('q#3');
ylabel('y1,y2');

title('graph of lab task#2');


grid on

Lab Task 03
%plotting signal in matlab
t=[0:0.01:5];
x=3*cos(0.1.*pi.*t+pi/3)+2.*sin(0.5.*pi.*t);

plot(t,x);

Square wave plotting


x1=3*square(5.*pi.*t+pi/2)

plot(t,x1);
title('square wave potting');

sawtooth plot
x2=3*sawtooth(5.*pi.*t+pi/2);

plot(t,x2);
title('sawtooth wave plotting');

Lab Task 05

Exponential signal
t=[0:0.01:1];
x=60.*sin(20.*pi.*t).*exp(-6.*t);

plot(t,x);
title('q#5 decaying exp function');

stem(t,x);
title('q#5 discreate decaying exponential');

Lab Task 06
increasing exponential
t=[0:0.01:6];
x=4.*sin(6.*pi.*t+pi/2).*exp(4.*t);

plot(t,x);
title('q#6 increasing exponential contiuous');

Lab Task 07
%Discreate time signal
n=[-3:4];
x=[2 1 -1 0 1 2 3 5];

stem(n,x);
title('q#7 discreate time signal');

Lab Task 08
%Discreate time signal
n=[-4:4];
x=[1 2 3 4 0 4 3 2 1];
stem(n,x);
title('q#8 discreate time signal');

You might also like