Created by Dr. V. R. Ratnaparkhe
Signals & SystemsVirtual Laboratory
Experiment 06 · Signals & Systems Lab

Discrete-Time Convolution

Convolve any two sequences with an animated flip-shift-multiply-sum, and check against hand calculation.

Flip & slideLTI systemsCO 1,2

Aim

Write a program to convolve any two discrete-time sequences, plot all the sequences, and verify the result by analytical calculation. Convolve x₁(n) with x₂(n), then x₁(n) with x₃(n) and x₄(n), and compare the results. Repeat for x₂(n).

Objectives

  • Carry out linear convolution with the four steps flip → shift → multiply → sum.
  • Predict the length (L₁ + L₂ − 1) and the start index (n₁ + n₂) of the output.
  • Check results by hand with the multiplication-table (tabular) method.
  • See how a difference filter x₃ and an averaging filter x₄ change a signal.

Test sequences

NameValuesStart nRole
x₁[1 2 3 1]0input A
x₂[1 2 1]−1input B
x₃[1 −1]0first difference (high-pass)
x₄[0.5 0.5]02-point average (low-pass)

Convolution sum

For an LTI system with impulse response h[n], the output for any input x[n] is the convolution:

y[n] = x[n] * h[n] = Σₖ x[k] · h[n − k]
  1. Fold h[k] to get h[−k].
  2. Shift it by n to get h[n − k].
  3. Multiply it point by point with x[k].
  4. Sum all the products. That sum is y[n]. Repeat for every n.

Properties

Commutativex * h = h * x
Associative(x * h₁) * h₂ = x * (h₁ * h₂)
Distributivex * (h₁ + h₂) = x * h₁ + x * h₂
Identityx * δ[n] = x
LengthL_y = L_x + L_h − 1, start n_y = n_x + n_h
Sum checkΣy = (Σx)(Σh)

Tabular (multiplication) method

Write x along the top and h down the side, and fill each cell with the product of its row and column. Adding the cells along each anti-diagonal (↙) gives y[n]. The Simulator builds this table live.

  1. Choose the preset x₁ * x₂. Before you press play, predict the output length and start index.
  2. Press ▶ Play or drag the output index n slider. At each n, watch h[n−k] slide, the products light up, and y[n] grow.
  3. Check each value in the multiplication table (the highlighted diagonal is the current n).
  4. Switch on Compare mode to see x₁*x₃ and x₁*x₄ side by side, then x₂*x₃ and x₂*x₄. Describe what the difference and averaging filters do.
  5. Record at least 5 output samples in Observations and type your hand-worked values.
  6. Edge cases: convolve with δ[n] ([1]), with a shifted impulse ([0 0 1]), and with sequences that have negative start indices.

Pre-lab diagnostic

Sequences

x[k] (green) and h[n−k] (amber), shown on the k axis
Products x[k]·h[n−k]
Output y[n] (filled up to the current n)
Audioh[n] is applied as a real FIR filter at audio rate. [1 −1] (x₃) sounds brighter and thinner; [0.5 0.5] (x₄) sounds duller.

Analytical check — multiplication table

Compare mode

The difference filter x₃ picks out changes (edges): its output is near 0 where the input is flat. The average x₄ smooths the input and keeps the total sum (Σx₄ = 1).

Output samples

Comparison of convolutions

Analysis

Post-lab quiz

Self-evaluation

exp6_convolution.m

%% Experiment 6: Discrete-time convolution
clc; clear; close all;
x1 = [1 2 3 1];  n1 = 0:3;
x2 = [1 2 1];    n2 = -1:1;
x3 = [1 -1];     n3 = 0:1;
x4 = [0.5 0.5];  n4 = 0:1;
% user-defined convolution (no built-in) for verification
myconv = @(a,b) arrayfun(@(n) sum(a(max(1,n-length(b)+1):min(n,length(a))) .* ...
         b(n-(max(1,n-length(b)+1):min(n,length(a)))+1)), 1:length(a)+length(b)-1);
pairs = {x1,n1,x2,n2,'x1*x2'; x1,n1,x3,n3,'x1*x3'; x1,n1,x4,n4,'x1*x4';
         x2,n2,x3,n3,'x2*x3'; x2,n2,x4,n4,'x2*x4'};
for i = 1:size(pairs,1)
  [a,na,b,nb,name] = pairs{i,:};
  y  = conv(a,b);  ny = (na(1)+nb(1)) : (na(end)+nb(end));
  fprintf('%s = [%s]  (n = %d..%d)  match=%d\n', name, num2str(y), ny(1), ny(end), isequal(round(y,10),round(myconv(a,b),10)));
  subplot(5,1,i); stem(ny,y,'filled'); title(name); grid on;
end