How to apply multiple convolutions in one step?

5 views (last 30 days)
I have a matrix of signals where each row corresponds to a signal and I also have a corresponding matrix of filters where each row is a filter.
Thus, each signal has a filter associated with it. How do I apply the corresponding convolutions at once?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Jun 2021
One way to solve this problem is to convert the filters and signals into cell arrays and make use of 'cellfun' operation to apply row by row convolution.
Assume:
A is the signal matrix where the rows are different signals.
B is the filter matrix with 2 filters
A = [[1 0 1];[1 0 1]];
B = [[2,7];[2,7]];
Convert these matrices into a cell array for faster computation
cellA = num2cell(A, 2)
cellB = num2cell(B,2)
Perform convolution on each row using 'cellfun':
result = cellfun(@(A,B) conv(A, B), cellA,cellb, 'UniformOutput', false);
The last function applies convolution to each row of A with its corresponding filter from B.
'cellfun' applies the desired function (convolution here) to each element of the cell array. More details about 'cellfun' can be found here:

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!