You are on page 1of 21

Experiment 3

Aim: - To find odd and even component of continuous time and


discrete time signals.

Software: - MATLAB 2020b

Group Member:
1. Omkar Bhilare 191060901
2. Omkar Sargar 181060047
3. Om Fuke 181060046
4. Lukesh Ankamwar 181060038

Code:-

clc;
clear all;
time_start=input('Enter start time: ');
time_end=input('Enter end time: ');

time_c=time_start:0.001:time_end;
time_d=time_start:1:time_end;

n=input('Input the type of signal ?\n1:Continuous


Time\n2:Discrete Time\nn = ');
m = input('Enter the wave you want\n1:Sine Wave
\n2:Cosine Wave\n3:Step Function\n4:Ramp
Function\n5:Exponential Function\n6:Custom Signal
1\n7:Custom Signal 2\n8:User Customized:\n');

switch m
case 1
if n==1
A=input('Enter the Amplification or
Scaling factor:');
p_x = A*sine(time_c);
%p= A*sine(comp*(time_c-d));
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
plot(time_c , p_x , 'r'); grid on;
title('Sine Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
plot(time_c,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
elseif n==2
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*sine(time_d);
%p= A*sine(comp*(time_c-d));
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
stem(time_d , p_x ,'r'); grid on;
title('Sine Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
stem(time_d,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
end
case 2
if n==1
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*cosine(time_c);
%p= A*sine(comp*(time_c-d));
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
plot(time_c , p_x,'r'); grid on;
title('Sine Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
plot(time_c,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
elseif n==2
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*cosine(time_d);
%p= A*sine(comp*(time_c-d));
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
stem(time_d , p_x,'r'); grid on;
title('Cosine Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
stem(time_d,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
end
case 3
if n==1
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*Unit_Step(time_c);
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
plot(time_c , p_x , 'r'); grid on;
title('Unit Step Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
plot(time_c,p_o ,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c,p_e ,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
elseif n==2
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*Unit_Step(time_d);
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
stem(time_d , p_x,'r'); grid on;
title('Unit Step Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
stem(time_d,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
end
case 4
if n==1
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*Ramp(time_c);
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
plot(time_c , p_x,'r'); grid on;
title('Ramp Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
plot(time_c,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
elseif n==2
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*Ramp(time_d);
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
stem(time_d , p_x,'r'); grid on;
title('Sine Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
stem(time_d,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
end
case 5
if n==1
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*exponential(time_c);
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
plot(time_c , p_x,'r'); grid on;
title('Exponential Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
plot(time_c,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
elseif n==2
A=input('Enter the Amplification or Scaling
factor:');
p_x = A*exponential(time_d);
%p= A*sine(comp*(time_c-d));
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
stem(time_d , p_x,'r'); grid on;
title('Exponential Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
stem(time_d,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
end
case 6
if n==1
p_x = Custom1(time_c);
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
plot(time_c , p_x,'r'); grid on;
title('Custom Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
plot(time_c,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
elseif n==2
p_x = Custom1(time_d);
%p= A*sine(comp*(time_c-d));
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
stem(time_d , p_x,'r'); grid on;
title('Custom Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
stem(time_d,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
end
case 7
if n==1
p_x = Custom2(time_c);
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
plot(time_c , p_x,'r'); grid on;
title('Custom Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
plot(time_c,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
elseif n==2
p_x = Custom2(time_d);
%p= A*sine(comp*(time_c-d));
p_y=fliplr(p_x);
p_o = (p_x-p_y)*0.5;
p_e = (p_x+p_y)*0.5;
subplot(3,1,1)
stem(time_d , p_x,'r'); grid on;
title('Custom Signal');
xlabel('time');
ylabel('Amplitude')
subplot(3,1,2)
stem(time_d,p_o,'r');grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d,p_e,'r');grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
end
case 8
if n==1
z=input('Enter Signal:');
subplot(3,1,1)
title('User Customized Signal');
xlabel('time');
ylabel('Amplitude');
plot(time_c,z);grid on;
y = fliplr(z)
subplot(3,1,2)
plot(time_c ,y); grid on;
p_e = (z + y)*0.5;
p_o = (z -y) * 0.5;
subplot(3,1,2)
plot(time_c ,p_e); grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
plot(time_c ,p_o); grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');

elseif n==2
z=input('Enter Signal:');
subplot(3,1,1)
title('User Customized Signal');
xlabel('time');
ylabel('Amplitude');
stem(time_d,z);grid on;
y = fliplr(z)
subplot(3,1,2)
stem(time_d ,y); grid on;
p_e = (z + y)*0.5;
p_o = (z -y) * 0.5;
subplot(3,1,2)
plot(time_c ,p_e); grid on;
title('Even Signal');
xlabel('time');
ylabel('Amplitude');
subplot(3,1,3)
stem(time_d ,p_o); grid on;
title('Odd Signal');
xlabel('time');
ylabel('Amplitude');
end
otherwise
fprintf('Invalid input');
end

function [ramp] = Ramp(t)


ramp=zeros(size(t));
c=find(t==0);
[~,n]=size(t);
for x=1:n
if x>=c
ramp(1,x)=t(1,x);
end
end

end

function [unit_step] = Unit_Step(t)


unit_step=zeros(size(t));
c=find(t==0);
[~,n]=size(t);
for x=1:n
if x>=c
unit_step(1,x)=1;
end
end
end

function [sine] = sine(t)


sine = sin(t);
end

function [cosine] = cosine(t)


cosine = cos(t);
end

function [exponential] = exponential(t)


exponential = exp(t);
end

function [custom1] = Custom1(t)


custom1 = Unit_Step(t)+ Unit_Step(t-1)- Unit_Step(t-2)-
Unit_Step(t-3);
end

function [custom2] = Custom2(t)


custom2 = -Unit_Step(t+3)+2*Unit_Step(t+2)+Ramp(t+1)-
2*Ramp(t)+Ramp(t-1)-2*Unit_Step(t-2)+Unit_Step(t-3);
end

Theoretical Analysis:

1) x[n] = unit step[n-1] – unit step [n-4]


Even component = (x[n] + x[-n]) * 0.5
Odd component = (x[n] - x[-n]) * 0.5

Even Component

Input n Input values X[-n] Even part Final


outputs

X[-3] 0 1 0.5 (-3,0.5)


X[-2] 0 1 0.5 (-2,0.5)
X[-1] 0 1 0.5 (-1,0.5)
X[0] 0 0 0 (0,0)
X[1] 1 0 0.5 (1,0.5)
X[2] 1 0 0.5 (2,0.5)
X[3] 1 0 0.5 (3,0.5)

Odd Component

Input n Input values X[-n] Odd part Final


outputs

X[-3] 0 1 -0.5 (-3,-0.5)


X[-2] 0 1 -0.5 (-2,-0.5)
X[-1] 0 1 -0.5 (-1,-0.5)
X[0] 0 0 0 (0,0)
X[1] 1 0 0.5 (1,0.5)
X[2] 1 0 0.5 (2,0.5)
X[3] 1 0 0.5 (3,0.5)
2)
X[n]=Ramp[n]
Even component = (x[n] + x[-n]) * 0.5
Odd component = (x[n] - x[-n]) * 0.5

Input n Input values X[-n] Odd part Final


outputs

X[-3] 0 3 -1.5 (-3,-1.5)


X[-2] 0 2 -1.0 (-2,-1.0)
X[-1] 0 1 -0.5 (-1,-0.5)
X[0] 0 0 0 (0,0)
X[1] 1 0 0.5 (1,0.5)
X[2] 2 0 1.0 (2,1.0)
X[3] 3 0 1.5 (3,1.5)

Input n Input values X[-n] Even part Final


outputs

X[-3] 0 3 1.5 (-3,1.5)


X[-2] 0 2 1.0 (-2,1.0)
X[-1] 0 1 0.5 (-1,0.5)
X[0] 0 0 0 (0,0)
X[1] 1 0 0.5 (1,0.5)
X[2] 2 0 1.0 (2,1.0)
X[3] 3 0 1.5 (3,1.5)
Outputs:
Conclusion: - In this program we operated on original signals and got
the even and odd part of the signals. Through this experiment we can
conclude that every signals have an even and odd component and the
original signal can be obtained by addition of even and odd
components of signal .

You might also like