Experiment-1(b)
AIM:
To Perform Linear Convolution on MATLAB.
Software Used:
MATLAB
Theory:
Convolution is a fundamental operation in Digital Signal Processing (DSP). It describes the relationship between
input, impulse response, and output of an LTI system.
1. Linear Convolution:
Linear convolution is a fundamental operation in signals and systems used to determine the output of an LTI
(Linear Time-Invariant) system when the input and the system’s impulse response are known.
∞
𝑦(𝑛) = ∑ 𝑥 (𝑘)ℎ(𝑛 − 𝑘)
𝑛=−∞
Code:
clc;
clear;
close all;
% ---- Input Sequences ----
x = [1 2 3 4];
h = [1 2 1];
N1 = length(x);
N2 = length(h);
% -------- Plot Input Sequences --------
figure;
subplot(2,2,1);
stem(0:N1-1, x, 'filled');
title('Input Sequence x[n]');
xlabel('n'); ylabel('x[n]');
subplot(2,2,2);
stem(0:N2-1, h, 'filled');
title('Input Sequence h[n]');
xlabel('n'); ylabel('h[n]');
%-------- Direct Linear Convolution using conv --------
y_linear_direct = conv(x, h);
subplot(2,2,3);
stem(0:length(y_linear_direct)-1, y_linear_direct, 'filled');
title('Direct Linear Convolution (conv)');
xlabel('n'); ylabel('y[n]');
%-------- Direct Linear Convolution using for-loop --------
y_linear_loop = zeros(1, N1+N2-1);
for n = 1:(N1+N2-1)
for k = 1:N1
if (n-k+1 > 0) && (n-k+1 <= N2)
y_linear_loop(n) = y_linear_loop(n) + x(k)*h(n-k+1);
end
end
end
subplot(2,2,4);
stem(0:length(y_linear_loop)-1, y_linear_loop, 'filled');
title('Direct Linear Convolution using for-loop');
xlabel('n'); ylabel('y[n]');
Result:
Conclusion:
Linear convolution using for loop in MATLAB was successfully implemented and verified with the direct
convolution method.