BME | EEG Analysis - Convolution and Dot Product
Dot Product
Mathematical Definition
Assuming two input vectors, and , the dot product is calculated as:
Code
MATLAB Code:
1 | z = dot(x, y) |
Python Code
1 | z = np.dot(x, y) |
Convolution
Mathematical Definitions
Discrete Convolution Definition:
Assuming two vectors, and , the convolution result is calculated as:
Continuous Convolution Definition:
Assuming two continuous functions and , the convolution result is:
Explanation and Understanding
Convolution is commonly applied to signals where ‘x’ represents the signal and ‘h’ is the convolution kernel, usually shorter than the signal.
Discrete Convolution: If both the signal ‘x’ and the convolution kernel ‘h’ are discrete, convolution can be understood as ‘h’ sliding along ‘x’, taking a set of data points equal to ‘h’ and performing point-wise multiplication, summing up the results as the first convolution output. The convolution kernel ‘h’ then slides to the right by one unit, repeating the process to obtain subsequent convolution results until the signal ‘x’ is completely traversed.
Continuous Convolution: If both the signal ‘x’ and the convolution kernel ‘h’ are continuous, convolution can be visualized as the overlap between ‘x’ and ‘h’, with the area of overlap representing the first convolution result. The convolution kernel ‘h’ then slides along the signal ‘x’, repeating the process to obtain subsequent convolution results until the signal ‘x’ is entirely covered.
In theory, convolution occurs from negative infinity to positive infinity, but in practice, only non-zero sections of the signal ‘x’ are considered. The length of the resulting convolution might require manual selection, although MATLAB and Python offer options for the convolution result’s length. Padding the signal’s ends with zeros ensures full coverage by the kernel. Post-convolution scaling may alter the amplitude, and to compare with the original signal amplitude, dividing the convolution result by the kernel’s length suffices. Odd-length kernels are typically recommended.
Code
Matlab Code
1 | y = conv(u, h) % Equivalent to conv(h, u) |
Python Code
1 | y = np.convolve(u, h) # Equivalent to conv(h, u) |
! Exercise
Calculate the moving average of a signal using a kernel of length 11.
1 | x = cumsum(randn(1,1000)) |
1 | import numpy as np |
Note: The content in this blog is class notes shared for educational purposes only. Some images and content are sourced from textbooks, teacher materials, and the internet. If there is any infringement, please contact aursus.blog@gmail.com for removal.