% Assignment NO. 01;

% Question 1:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x = [-4 5 1 -2 -3 0 2];         % Sequence x
xn = -3:3;                      % Support for sequence x
y = [6 -3 -1 0 8 7 -2];         % Sequence y
yn = -1:5;                      % Support for sequence x
w = [3 2 2 -1 0 -2 5];          % Sequence w
wn = 2:8;                       % Support for sequence x

% Plotting x[-n + 2]
sequence = fliplr(x);           % x[-n]
tempXN = xn + 2;                % x[-n + 2]
stem(tempXN, x);
xlabel('n');
ylabel('x[-n + 2]');
title('x[-n + 2] vs. n');
figure

% Plotting w[-n]
sequence = fliplr(w);           % w[-n]
stem(wn, sequence);
xlabel('n');
ylabel('w[-n]');
title('w[-n] vs. n');
figure


% Plotting x[n] + y[n - 2]
tempYN = yn + 2;                % y[n - 2]
% duration of result signal
n = min(min(xn),min(tempYN)):max(max(xn),max(tempYN));
tempSeq1 = zeros(1,length(n));  % initialization
tempSeq2 = tempSeq1;
% x with duration of result
tempSeq1(find((n>=min(xn))&(n<=max(xn))==1))=x;
% y[n - 2] with duration of result
tempSeq2(find((n>=min(tempYN))&(n<=max(tempYN))==1))=y;
sequence = tempSeq1 + tempSeq2;
stem(n, sequence);
xlabel('n');
ylabel('x[n] + y[n - 2]');
title('x[n] + y[n - 2] vs. n');
figure


% Plotting x[n].w[n + 4]
tempWN = wn - 4;                % w[n + 4]
n = min(min(xn),min(tempWN)):max(max(xn),max(tempWN));
tempSeq1 = zeros(1,length(n));  % initialization
tempSeq2 = tempSeq1;
% x with duration of result
tempSeq1(find((n>=min(xn))&(n<=max(xn))==1))=x;
% y[n - 2] with duration of result
tempSeq2(find((n>=min(tempWN))&(n<=max(tempWN))==1))=w;
sequence = tempSeq1 .* tempSeq2;
stem(n, sequence);
xlabel('n');
ylabel('x[n].w[n + 4]');
title('x[n].w[n + 4] vs. n');
figure

% Plotting 3.5y[n]
sequence = 3.5 .* y;
stem(yn, sequence);
xlabel('n');
ylabel('3.5y[n]');
title('3.5y[n] vs. n');

