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.
| Operation | Definition | Effect on the plot | MATLAB idea |
|---|---|---|---|
| Addition | y[n] = xโ[n] + xโ[n] | Add the values at each n | pad both to a common n, then x1+x2 |
| Subtraction | y[n] = xโ[n] โ xโ[n] | Subtract at each n | x1-x2 |
| Multiplication | y[n] = xโ[n]ยทxโ[n] | Multiply at each n (windowing) | x1.*x2 |
| Amplitude scaling | y[n] = aยทx[n] | Vertical stretch or flip | a*x |
| Folding | y[n] = x[โn] | Mirror about n = 0 | fliplr(x), -fliplr(n) |
| Shifting | y[n] = x[n โ k] | k > 0 means a delay (moves right) | n + k |
| Time scaling | y[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
- In the Simulator, type xโ and xโ as comma-separated values, and give the index of the first sample of each.
- Pick Addition. Look at how the shorter signal is padded with zeros so the two index ranges match.
- Pick Fold and press โถ Animate to watch each sample mirror about n = 0.
- Pick Shift with k = +2 and then k = โ2. Note which way the sequence moves.
- Pick Fold + shift xโ(โn + k). Predict y at a probe index first, then look.
- 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]
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)');