1 dimensional convolution of 2d in matlab

To perform a 1D convolution of a 2D signal in Matlab, you can use the conv2 function along with a 1D kernel. Here is an example code:

main.m
% Generate a 2D signal
signal = randn(10,10);

% Define a 1D kernel
kernel = [1 2 1];

% Perform the 1D convolution along the rows
convRows = conv2(signal, kernel, 'same');

% Perform the 1D convolution along the columns
convCols = conv2(convRows, kernel', 'same');
266 chars
12 lines

In this example, we first generate a random 2D signal with a size of 10x10. We then define a 1D kernel with values [1 2 1]. We perform the first convolution along the rows of the signal using the conv2 function with the 'same' option to return a signal of the same size as the original. We then perform the second convolution along the columns of the signal by applying the same 'conv2' function but transposing the kernel. The final result should be a 2D signal that has gone through a 1D convolution along both the rows and columns.

gistlibby LogSnag