Arithmetic operations of different discrete time signals. I. Time Shifting II. Folding/ Symmetry of the signal III. Addition IV. Multiplication V. Time scaling in MATLAB

 MATLAB Program to verify the time-shifting property of discrete time signals where, x1[n] = {1,0,1,0} & x2[n] = {1,2,1,2} (underline indicates the value at the zero index) by plotting: 

A. x1[n]+x2[n] 

B. x1[n].*x2[n] 

C. x1[-n+2] 

D. x2[-n-2] 

E. x1[-n+2].*x2[-n-2]


Copy and paste the following program code in the Editor to run the program.

Program Code:

% Plot of the two discrete sequences

n1 = [-1:2];

x1 = [1 0 1 0];

subplot(4,2,1);

stem(n1,x1);

xlabel('time index');

ylabel('amplitude');

title('discrete time sequence of x1');

axis([-2 2 0 3]);

n2 = [-2:1];

x2 = [1 2 1 2];

subplot(4,2,3);

stem(n2,x2);

xlabel('time index');

ylabel('amplitude');

title('discrete time sequence of x2');

axis([-2 2 0 3]);


% Addition of the two sequences

n3 = [min(min(n1,n2)):max(max(n1,n2))];

z1 = [zeros((length(n3)-length(x1))),x1];

z2 = [x2,zeros((length(n3)-length(x2)))];

z3 = z1 + z2;

subplot(4,2,5);

stem(n3,z3);

xlabel('time index');

ylabel('amplitude');

title('ADDITION of two discrete sequences');

axis([-2 2 0 3]);


% Multiplication of two discrete sequences

z4 = z1.*z2;

subplot(4,2,7);

stem(n3,z4);

xlabel('time index');

ylabel('amplitude');

title('MULTIPLICATION of two discrete sequences');

axis([-2 2 0 3]);


% Time shifting of x1 & x2

x3 = fliplr(x1);

n4 = fliplr(-n1)+2;

subplot(4,2,2);

stem(n4,x3);

xlabel('time index');

ylabel('amplitude');

title('sequence of x1 shifted by -n+2');

axis([-3 3 0 3]);

x4 = fliplr(x2);

n5 = fliplr(-n2)-2;

subplot(4,2,4);

stem(n5,x4);

xlabel('time index');

ylabel('amplitude');

title('sequence of x2 shifted by -n-2');

axis([-3 3 0 3]);


% Multiplication of two discrete time shifted sequences

n6 = [min(min(n4,n5)):max(max(n4,n5))];

z5 = [zeros(1,(length(n6)-length(x3))),x3];

z6 = [x4,zeros(1,(length(n6)-length(x3)))];

z7 = z5.*z6;

subplot(4,2,6);

stem(n6,z7);

xlabel('time index');

ylabel('amplitude');

title('MULTIPLICATION of two time shifted sequences');

axis([-3 3 0 3]);


Output:



For any code related queries comment below. Thanks for reading and happy learning!

Oh, by the way, If you like reading tech related articles, visit Modern Technology: Boon or Bane? or if you want to read some 'ambiguous' blogs then visit "Out of the Box" ;) Hope you'll like it.

Comments

Popular posts from this blog

Verification of Commutative, Distributive and Associative Property of Linear Convolution in MATLAB