Experiment
Experiment
Experiment
Aim:Operation on Signals and Sequences such as Addition, Multiplication, Scaling, Shifting, Folding,
Computation of Energy and Average Power.
clear all;
close all;
clc;
x = input(' Enter sequence 1 ');
y = input(' Enter sequence 2 ');
M = length(x);
N = length(y);
subplot(2,2,1);
stem(x);
xlabel('Time ');
ylabel('Amplitude ');
title('Input sequence 1');
subplot(2,2,2);
stem(y);
xlabel('Time ');
ylabel('Amplitude ');
title('Input sequence 2');
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
subplot(2,2,3);
stem(z);
xlabel('Time ');
ylabel('Amplitude ');
clear all;
close all;
clc;
s = input('Enter the sequence ');
a = input('Enter the scaling Factor ');
m = length(s);
k = ceil(m/a);
s_scal = [];
for i = 1:m,
if mod(i-1,a) == 0
s_scal = [s_scal,s(i)];
end;
end;
subplot(2,1,1)
stem([0:m-1],s);
xlabel('Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:k-1],s_scal);
xlabel(' Time');
ylabel(' Amplitude');
title('Scaled Sequence');
OUTPUT
Enter the sequence [1 2 3 4 5 6 7 8 9 10 11 12 13 14]
Enter the scaling Factor 4
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel(' Time');
ylabel(' Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel(' Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel(' Time');
ylabel('Amplitude');
title('Shifted Sequence');
end;
OUTPUT
Enter the sequence [1 2 3 4 5 6 7 8 9 10 11 12 13 14]
Enter the length to be shifted 5
clear all;
close all;
clc;
s = input('Enter the sequence ');
m = length(s);
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel(' Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1,m)]);
xlabel(' Time');
ylabel(' Amplitude');
title('folded Sequence');
OUTPUT
Enter the sequence [1 2 3 4 5 6 7]
clear all;
close all;
clc;
tes = input('Enter the sequence ');
M = length(tes);
sum = 0;
for i = 1:M,
sum = sum + tes(i)*tes(i);
end;
disp('Energy of the given sequence is ');
Energy = sum
disp('Average Power of the given sequence is ');
Average_power = sum/M
OUTPUT
Enter the sequence [1 2 3 4 5 4 3 2 1]
Energy of the given sequence is
Energy =
85
Average Power of the given sequence is
Average_power =
9.4444
6. Addition and Multiplication of two Signals
clear all;
close all;
clc;
t = 0:0.01:2;
x = sin(2*pi*t);
y = cos(2*pi*t);
M = length(x);
N = length(y);
subplot(4,1,1);
stem(x);
xlabel('Time ');
ylabel('Amplitude ');
title('Input signal 1');
subplot(4,1,2);
stem(y);
xlabel('Time ');
ylabel('Amplitude ');
title('Input signal 2');
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
z = x + y;
subplot(4,1,3);
stem(z);
xlabel('Time ');
ylabel('Amplitude ');
title('Addition of signals 1 and 2');
if M > N
a = x.*[y,zeros(1,M-N)];
else
a = [x,zeros(1,N-M)].*y;
end;
a = x.*y;
subplot(4,1,4);
stem(a);
xlabel('Time ');
ylabel('Amplitude ');
title('Multiplication of signals 1 and 2');
OUTPUT
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the scaling Factor ');
m = length(s);
k = ceil(m/a);
s_scal = [];
for i = 1:m,
if mod(i,a) == 0
s_scal = [s_scal,s(i-1)];
end;
end;
subplot(2,1,1)
stem([0:m-1],s);
xlabel(' Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:k-1],s_scal);
xlabel(' Time');
ylabel(' Amplitude');
title('Scaled Sequence');
OUTPUT
Enter the scaling Factor 3
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the length to be shifted ');
m = length(s);
if a == 0
subplot(2,1,1)
stem([0:m-1],s); xlabel(' Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m-1],s); xlabel(' Time');
ylabel(' Amplitude');
title('Shifted Sequence');
elseif a > 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel(' Time');
ylabel(' Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel(' Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel(' Time');
ylabel(' Amplitude');
title('Shifted Sequence');
end;
OUTPUT
Enter the length to be shifted 75
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
m = length(s);
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel(' Time');
ylabel(' Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1,m)]);
xlabel(' Time');
ylabel(' Amplitude');
title('folded Sequence');
OUTPUT
clear all;
close all;
clc;
t = 0:0.01:4;
tes = cos(2*pi*t);
M = length(tes);
sum = 0;
for i = 1:M,
sum = sum + tes(i)*tes(i);
end;
disp('Energy of the given sequence is ');
Energy = sum
disp('Average Power of the given sequence is ');
Average_power = sum/M
OUTPUT
Average_power =
0.5012