0% found this document useful (0 votes)
5 views20 pages

Lab 3

The document outlines a laboratory report on convolution conducted by students Lê Tiến Phát and Nguyễn Ngọc Ngân at the International University. It includes a grading checklist, team contributions, and detailed sections on the fundamentals of linear convolution, experimental procedures, and results from various problems implemented using MATLAB. The report emphasizes the mathematical foundations, properties, and applications of convolution in digital signal processing.

Uploaded by

ngannguyen999xxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views20 pages

Lab 3

The document outlines a laboratory report on convolution conducted by students Lê Tiến Phát and Nguyễn Ngọc Ngân at the International University. It includes a grading checklist, team contributions, and detailed sections on the fundamentals of linear convolution, experimental procedures, and results from various problems implemented using MATLAB. The report emphasizes the mathematical foundations, properties, and applications of convolution in digital signal processing.

Uploaded by

ngannguyen999xxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

International University

School of Electrical Engineering

Digital Signal Processing Laboratory


EE093IU

CONVOLUTION

Submitted by

Student name Student ID


Lê Tiến Phát ITITIU21273
Nguyễn Ngọc Ngân SESEIU21025

Date Performed: 18/04/2025


Date Submitted: 06/06/2025
Lab Section: Lab 3
Course Instructor: M. Eng Nguyen Minh Thien

International University EE093IU1 1


School of CSE
GRADING CHECKLIST

Number Content Satisfied? Score Comment


Format (max 9%)
- Font type Yes No
1
- Font size Yes No

- Lab title Yes No

- Page number Yes No

- Table of contents Yes No

- Header/Footer Yes No

- List of figures (if exists) Yes No

- List of tables (if exists) Yes No

- Lab report structure Yes No

2 English Grammar and Spelling (max 6%)


- Grammar Yes No

- Spelling Yes No

3 Data and Result Analysis (max 85%)

Total Score

Date:

Signature

International University EE093IU1 2


School of CSE
TEAM CONTRIBUTION
Task Le Tien Phat Nguyen Ngoc Ngan
Collaborated on all coding tasks, participated in problem-solving
Collaboration
discussions, and jointly tested MATLAB implementations
Lab preparation
Answer in-class questions
and experiment
Data analysis Jointly analyzed & verified the results for all problems
Write fundamental background & Write experiment procedure &
Report writing
Conclusion Results

International University EE093IU1 3


School of CSE
Table of Contents
DISCUSSION OF FUNDAMENTALS ......................................................................................... 5
EXPERIMENTAL PROCEDURE ................................................................................................. 7
EXPERIMENTAL RESULTS........................................................................................................ 8
CONCLUSION ............................................................................................................................. 20

List of Figures
Figure 1. Result of the program in Problem 1. 10

Figure 2. FFT-Based Convolution 11

Figure 3. Direct Convolution 11

Figure 4. Signal plotting problem 2 14

Figure 5. Custom conv() 15

Figure 6. MATLAB conv() 15

Figure 7. Impulse Response h(n) 18

Figure 8. Echo-Added Signal Plotting 19

International University EE093IU1 4


School of CSE
Discussion of Fundamentals
Linear Convolution Theory
Linear convolution is a fundamental operation in digital signal processing that describes the
output of a Linear Time-Invariant (LTI) system when an input signal is applied. The convolution
operation mathematically represents how the system's impulse response interacts with the input
signal over time.
Mathematical Foundation
The discrete-time convolution formula is expressed as:
∞ ∞

𝑦(𝑛) = ∑ ℎ (𝑚)𝑥(𝑛 − 𝑚) = ∑ 𝑥 (𝑚)ℎ(𝑛 − 𝑚)


𝑚=−∞ 𝑚=−∞
For finite duration sequences, this becomes:
𝑀

𝑦(𝑛) = ∑ ℎ (𝑚)𝑥(𝑛 − 𝑚)
𝑚=0
where:
• 𝑥(𝑛) is the input sequence
• ℎ(𝑛) is the impulse response
• 𝑦(𝑛) is the output sequence
• 𝑚 is the summation index
Properties of Convolution
Length Property: For two finite sequences of lengths 𝐿𝑥 and 𝐿ℎ , the convolution result has
length:
𝐿𝑦 = 𝐿𝑥 + 𝐿ℎ − 1
Index Range: For causal sequences starting at n=0, the output sequence spans:
0 ≤ 𝑛 ≤ 𝐿𝑥 + 𝐿ℎ − 2
Frequency Domain Relationship
The convolution theorem states that convolution in the time domain corresponds to
multiplication in the frequency domain:
If 𝑥(𝑛) ↔ 𝑋(𝑒 𝑗𝜔 ) and ℎ(𝑛) ↔ 𝐻(𝑒 𝑗𝜔 ), then:
𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) ↔ 𝑌(𝑒 𝑗𝜔 ) = 𝑋(𝑒 𝑗𝜔 ) ⋅ 𝐻(𝑒 𝑗𝜔 )

This relationship provides an alternative method for computing convolution using Fast Fourier
Transform (FFT) algorithms, which can be computationally more efficient for long sequences.

International University EE093IU1 5


School of CSE
Physical Interpretation
Convolution represents the weighted sum of shifted and scaled versions of the input signal,
where the weights are determined by the impulse response. Each sample of the output is
computed by:
1. Time-reversing the impulse response
2. Shifting it by n samples
3. Multiplying point-wise with the input
4. Summing all products
This process models how an LTI system responds to arbitrary inputs based on its impulse
response characteristics.
Direct Form Implementation
Consider a causal FIR filter of order M with impulse response h(n), n = 0, 1, ..., M. The filter can
be represented as:
𝐡 = [ℎ0 , ℎ1 , … , ℎ𝑀 ]
Its length (number of filter coefficients) is:
𝐿ℎ = 𝑀 + 1
For an input sequence x of length L:
𝐱 = [𝑥0 , 𝑥1 , … , 𝑥𝐿−1 ]
The convolution sum becomes:
𝑀

𝑦(𝑛) = ∑ ℎ (𝑚)𝑥(𝑛 − 𝑚)
𝑚=0

The valid range for the summation index m is:


0≤𝑚≤𝑀
The index of 𝑥(𝑛 − 𝑚) must lie within the legal range:
0 ≤𝑛−𝑚 ≤𝐿−1
Combining these constraints:
0 ≤𝑚 ≤ 𝑛 ≤ 𝐿−1+𝑚 ≤ 𝐿−1+𝑀
Therefore, the output index range is:
0 ≤𝑛 ≤𝐿−1+𝑀
The output sequence y has length:
𝐿𝑦 = 𝐿 + 𝑀 = 𝐿𝑥 + 𝐿ℎ − 1

International University EE093IU1 6


School of CSE
Experimental Procedure
Problem 1: Basic Convolution Implementation
Objective: Implement convolution using MATLAB's built-in conv() function and verify results
using frequency domain methods.
Given Signals:
• System response: ℎ[𝑛] = 2𝑛 𝑢[𝑛], for n = [0:5]
• Input signal: 𝑥[𝑛] = 𝑢[𝑛 + 10] − 𝑢[𝑛 − 5]
Procedure:
1. Define the impulse response h[n] as a finite sequence
2. Create the input signal x[n] over the range n = [-15:15]
3. Compute convolution using conv(x,h)
4. Verify using FFT-based convolution:
o Compute 𝑋(𝑒 𝑗𝜔 ) and 𝐻(𝑒 𝑗𝜔 ) using FFT
o Multiply frequency domain representations
o Apply inverse FFT to obtain time domain result
5. Compare both methods using subplot visualization
Problem 2: Custom Convolution Function
Objective: Develop a custom convolution function without using MATLAB's built-in conv()
function.
Test Signals:
• Impulse response: ℎ[𝑛] = 𝑒 −𝑛 for −10 ≤ 𝑛 ≤ 10, 0 elsewhere
• Input signal: 𝑥[𝑛] = 1 for 0 ≤ 𝑛 ≤ 5, 0 elsewhere
Algorithm Implementation:
1. Determine output sequence length: 𝐿𝑦 = 𝐿𝑥 + 𝐿ℎ − 1
2. Initialize output array with zeros
3. Implement nested loops for convolution sum
4. Validate against MATLAB's conv() function

Problem 3: Echo Generator Application


Objective: Create a practical echo effect using convolution with audio signals.
Parameters:
• Input: Audio file 'Sound.wav'
• Echo delay: 0.2 seconds
• Echo amplitude: 0.8
Implementation Steps:

International University EE093IU1 7


School of CSE
1. Load audio signal using audioread()
2. Design echo impulse response with specified delay and amplitude
3. Apply convolution to create echo effect
4. Compare original and processed audio signals
5. Generate audio playback for subjective evaluation

Experimental Results

Problem 1:
% Problem 1a: Basic convolution with user input
clear all; close all;

% Get input sequences


x_str = input('Enter sequence x[n]: ', 's');
x = str2num(x_str);
nx_start = input('Starting index for x[n]: ');
nx = nx_start:(nx_start + length(x) - 1);

h_str = input('Enter sequence h[n]: ', 's');


h = str2num(h_str);
nh_start = input('Starting index for h[n]: ');
nh = nh_start:(nh_start + length(h) - 1);

% Compute convolution
y = conv(x, h);
ny_start = nx_start + nh_start;
ny = ny_start:(ny_start + length(y) - 1);

fprintf('Convolution result y[n]:\n');


disp([ny; y]);

% Problem 1b: Specific signals


n = -15:15;

% System response h[n] = 2^n * u[n] for n = 0:5


h_b = zeros(1, length(n));
for i = 1:length(n)
if n(i) >= 0 && n(i) <= 5
h_b(i) = 2^n(i);
end
end

% Input signal x[n] = u[n+10] - u[n-5]


x_b = zeros(1, length(n));
for i = 1:length(n)
if n(i) >= -10
x_b(i) = x_b(i) + 1;
end
if n(i) >= 5
x_b(i) = x_b(i) - 1;
end

International University EE093IU1 8


School of CSE
end

% Convolution and plotting


y_conv = conv(x_b, h_b);
ny_start = min(n) + min(n);
ny_full = ny_start:(ny_start + length(y_conv) - 1);

figure;
subplot(3,1,1);
stem(n, x_b, 'b', 'LineWidth', 2);
title('Input Signal x[n] = u[n+10] - u[n-5]');

subplot(3,1,2);
stem(n, h_b, 'r', 'LineWidth', 2);
title('System Response h[n] = 2^n u[n]');

subplot(3,1,3);
stem(ny_full, y_conv, 'k', 'LineWidth', 2);
title('Convolution Output y[n] = x[n] * h[n]');

% Problem 1c: FFT verification


N = 1024;
x_padded = [x_b, zeros(1, N-length(x_b))];
h_padded = [h_b, zeros(1, N-length(h_b))];

X_fft = fft(x_padded);
H_fft = fft(h_padded);
Y_fft = X_fft .* H_fft;
y_ifft = real(ifft(Y_fft));

% Compare results
max_diff = max(abs(y_conv - y_ifft(1:length(y_conv))));
fprintf('Maximum difference: %e\n', max_diff);

figure;
subplot(1,2,1);
stem(ny_full, y_conv, 'b', 'LineWidth', 2);
title('Direct Convolution');

subplot(1,2,2);
stem(ny_full, y_ifft(1:length(y_conv)), 'r', 'LineWidth', 2);
title('FFT-based Convolution');

Result

International University EE093IU1 9


School of CSE
Figure 1. Result of the program in Problem 1.

International University EE093IU1 10


School of CSE
Figure 2. FFT-Based Convolution

Figure 3. Direct Convolution

International University EE093IU1 11


School of CSE
Problem 2:
function [y, ny] = customConv(x, h, nx, nh)
Lx = length(x);
Lh = length(h);
Ly = Lx + Lh - 1;

ny = (min(nx) + min(nh)):(max(nx) + max(nh));


y = zeros(1, Ly);

for n = 1:Ly
for m = 1:Lh
x_idx = ny(n) - nh(m);
x_pos = find(nx == x_idx);
if ~isempty(x_pos)
y(n) = y(n) + h(m) * x(x_pos);
end
end
end
end

% Test signals exactly as specified


nh = -10:10;
h = zeros(size(nh));
for i = 1:length(nh)
if nh(i) >= -10 && nh(i) <= 10
h(i) = exp(-nh(i));
end
end

nx = 0:5;
x = ones(1, length(nx));

% Compute convolution
[y_custom, ny] = customConv(x, h, nx, nh);
y_matlab = conv(x, h);

% Display results
max_error = max(abs(y_custom - y_matlab));
fprintf('Maximum error: %.2e\n', max_error);

% Plot all signals


figure('Position', [100, 100, 800, 600]);

subplot(3,1,1);
stem(nx, x, 'b', 'filled', 'LineWidth', 2);
title('Input Signal x[n] = 1, 0 ≤ n ≤ 5');
xlabel('n'); ylabel('x[n]');
grid on;

subplot(3,1,2);
stem(nh, h, 'r', 'filled', 'LineWidth', 2);
title('Impulse Response h[n] = e^{-n}, -10 ≤ n ≤ 10');
xlabel('n'); ylabel('h[n]');
grid on;

International University EE093IU1 12


School of CSE
subplot(3,1,3);
stem(ny, y_custom, 'k', 'filled', 'LineWidth', 2); hold on;
stem(ny, y_matlab, 'go', 'LineWidth', 1.5);
title('Convolution Output y[n] = x[n] * h[n]');
xlabel('n'); ylabel('y[n]');
legend('Custom Function', 'MATLAB conv()', 'Location', 'best');
grid on;

% Comparison figure
figure('Position', [150, 150, 800, 400]);
subplot(1,2,1);
stem(ny, y_custom, 'b', 'filled', 'LineWidth', 2);
title('Custom Convolution Result');
xlabel('n'); ylabel('y[n]');
grid on;

subplot(1,2,2);
stem(ny, y_matlab, 'r', 'filled', 'LineWidth', 2);
title('MATLAB conv() Result');
xlabel('n'); ylabel('y[n]');
grid on;
Result

International University EE093IU1 13


School of CSE
Figure 4. Signal plotting problem 2

International University EE093IU1 14


School of CSE
Figure 5. Custom conv()

Figure 6. MATLAB conv()

International University EE093IU1 15


School of CSE
International University EE093IU1 16
School of CSE
Problem 3:
clear all; close all;

% Load audio signal


try
[x, Fs] = audioread('Sound.wav');
x = x(:,1)';
fprintf('Audio loaded: %.2f seconds\n', length(x)/Fs);
catch
Fs = 44100;
t = 0:1/Fs:2-1/Fs;
x = 0.5 * sin(2 * pi * 440 * t);
disp('Using synthetic 440 Hz tone');
end

% Design echo impulse response


delay_seconds = 0.2;
echo_amplitude = 0.8;
delay_samples = round(delay_seconds * Fs);

h = zeros(1, delay_samples + 1);


h(1) = 1;
h(delay_samples + 1) = echo_amplitude;

% Apply echo effect


y = conv(x, h);

% Create time vectors


t_orig = (0:length(x)-1) / Fs;
t_echo = (0:length(y)-1) / Fs;

% Plot results
figure;
subplot(2,1,1);
plot(t_orig, x, 'b');
title('Original Audio Signal');
xlabel('Time (s)'); ylabel('Amplitude');

subplot(2,1,2);
plot(t_echo, y, 'r');
title('Echo-Added Audio Signal');
xlabel('Time (s)'); ylabel('Amplitude');

figure;
stem(0:length(h)-1, h, 'filled', 'k');
title('Echo Impulse Response h[n]');
xlabel('Sample Index'); ylabel('Amplitude');

% Audio playback
sound(x, Fs);
pause(length(x)/Fs + 1);
sound(y, Fs);

audiowrite('output_echo.wav', y, Fs);

International University EE093IU1 17


School of CSE
Result

Figure 7. Impulse Response h(n)

International University EE093IU1 18


School of CSE
Figure 8. Echo-Added Signal Plotting

→ The sound of a bark got duplicate, observed through the plotting.

International University EE093IU1 19


School of CSE
Conclusion
Summary of Work
This laboratory successfully demonstrated the fundamental concepts and practical applications of
discrete-time convolution. We implemented convolution using both MATLAB's built-in
functions and custom algorithms, verified results through frequency domain analysis, and
applied convolution to create a practical audio echo effect.
Key Findings
Theoretical Validation: The experiments confirmed the convolution theorem, with FFT-based
and direct time-domain methods producing identical results (error < 1e-15), validating the
fundamental relationship between time and frequency domains.
Algorithm Performance: Our custom convolution function matched MATLAB's precision
while demonstrating O(N×M) computational complexity. This highlights the efficiency
advantage of FFT-based methods for longer sequences.

Practical Applications: The echo generator successfully created realistic audio effects using
0.2-second delay and 0.8 amplitude scaling, demonstrating convolution's role in real-world
signal processing.

Difficulties and Solutions


The main challenges encountered were index management in the custom convolution function
and ensuring proper signal alignment for the echo generator. We solved these by carefully
implementing boundary checks in the convolution loops and using MATLAB's round()
function for sample-accurate delay calculations.
Key Points

The fundamental length relationship 𝐿𝑦 = 𝐿𝑥 + 𝐿ℎ − 1 was consistently observed across all


experiments. Convolution provides complete LTI system characterization through impulse
response, making it essential for digital filter design and signal processing applications.
The convolution principles demonstrated in this lab extend to numerous engineering applications
including digital filtering, image processing, communications systems, and control theory.
Understanding convolution is essential for designing FIR filters, analyzing system stability, and
implementing real-time signal processing algorithms.
The collaborative approach enhanced our understanding of both theoretical foundations and
practical implementation challenges essential for digital signal processing engineering practice.

THE END

International University EE093IU1 20


School of CSE

You might also like