Created by Dr. V. R. Ratnaparkhe
Signals & SystemsVirtual Laboratory
Experiment 04 ยท Signals & Systems Lab

Basic Operations on Signals

Add, subtract, multiply, fold, shift and scale discrete-time signals with step-by-step animation.

FoldingShiftingScalingCO 1-3

Aim

Perform basic operations on discrete-time signals: addition, subtraction, multiplication, folding (time reversal), time shifting, amplitude scaling and time scaling.

Objectives

  • Line up two sequences with different index ranges before adding or multiplying them.
  • Fold a sequence (n โ†’ โˆ’n) and shift it (n โ†’ n โˆ’ k), and know which way each one moves.
  • Combine operations such as x(โˆ’n + k) in the correct order.
  • Check every result against a hand-worked value table.

Key idea

A MATLAB vector has no time axis of its own. You must carry the index vector n with every signal. Most mistakes in this experiment come from forgetting to pad, flip or shift n along with x.

OperationDefinitionEffect on the plotMATLAB idea
Additiony[n] = xโ‚[n] + xโ‚‚[n]Add the values at each npad both to a common n, then x1+x2
Subtractiony[n] = xโ‚[n] โˆ’ xโ‚‚[n]Subtract at each nx1-x2
Multiplicationy[n] = xโ‚[n]ยทxโ‚‚[n]Multiply at each n (windowing)x1.*x2
Amplitude scalingy[n] = aยทx[n]Vertical stretch or flipa*x
Foldingy[n] = x[โˆ’n]Mirror about n = 0fliplr(x), -fliplr(n)
Shiftingy[n] = x[n โˆ’ k]k > 0 means a delay (moves right)n + k
Time scalingy[n] = x[Mn]Keep every M-th sample (down-sampling)x(1:M:end) aligned to n

Order matters: x(โˆ’n + k)

x(โˆ’n + k) = x(โˆ’(n โˆ’ k)) โ†’ first FOLD, then SHIFT RIGHT by k or first SHIFT LEFT by k, then FOLD
000 x[n]x[โˆ’n] (fold)x[โˆ’n+4] (shift right 4) โ†’โ†’
Fold first, then shift by +k.
  1. In the Simulator, type xโ‚ and xโ‚‚ as comma-separated values, and give the index of the first sample of each.
  2. Pick Addition. Look at how the shorter signal is padded with zeros so the two index ranges match.
  3. Pick Fold and press โ–ถ Animate to watch each sample mirror about n = 0.
  4. Pick Shift with k = +2 and then k = โˆ’2. Note which way the sequence moves.
  5. Pick Fold + shift xโ‚(โˆ’n + k). Predict y at a probe index first, then look.
  6. For every operation, record a reading. Type your hand-worked value of y[nprobe] and compare.
Edge cases to try: shift by more than the signal length; time scaling with M = 3 on a short sequence; adding sequences whose index ranges do not overlap at all.

Pre-lab diagnostic

Signals

Operation

xโ‚[n]
xโ‚‚[n]
y[n]
AudioEach sample is a note: pitch and loudness follow the value, and zero is a soft tick. Folding plays the tune backwards, shifting delays it, and scaling makes it louder.

Operations table

Work out y[nprobe] by hand before you look at the value table, then type it in.

Analysis

Post-lab quiz

Self-evaluation

exp4_operations.m

%% Experiment 4: Basic operations on signals
clc; clear; close all;
x1 = [1 2 3 4];   n1 = 0:3;
x2 = [2 1 -1];    n2 = -1:1;
% --- align on a common index ---
n  = min([n1 n2]):max([n1 n2]);
y1 = zeros(size(n)); y2 = y1;
y1(n>=n1(1) & n<=n1(end)) = x1;
y2(n>=n2(1) & n<=n2(end)) = x2;
ya = y1 + y2;  ys = y1 - y2;  ym = y1 .* y2;
% --- folding ---
xf = fliplr(x1);  nf = -fliplr(n1);
% --- shifting by k (delay) ---
k = 2;  nsh = n1 + k;
% --- x1(-n+k): fold then shift ---
nfk = -fliplr(n1) + k;  xfk = fliplr(x1);
subplot(3,2,1); stem(n,ya); title('x1+x2');
subplot(3,2,2); stem(n,ys); title('x1-x2');
subplot(3,2,3); stem(n,ym); title('x1.*x2');
subplot(3,2,4); stem(nf,xf); title('x1(-n)');
subplot(3,2,5); stem(nsh,x1); title('x1(n-2)');
subplot(3,2,6); stem(nfk,xfk); title('x1(-n+2)');