File Exchange

image thumbnail

Fast Matrix Column-wise/Row-wise Convolution

version (1.95 KB) by Zhen James Xiang
See Description.


Updated 15 Nov 2010

View License

The matlab conv function doesn't provide a way to perform column-wise/row-wise convolution of matrices. Using a loop can be time-consuming. This new function performs this kind of convolution using only matrix operations and fft/ifft. The key to this implementation is the proper zero padding of input matrices. The zip file contains 2 .m files, the function and a demo.

This function computes C = fastConv(A,B,dim), where the i-th column/row of C is the convolution of the i-th column/row of A and the i-th cloumn/row of B.

Comments and Ratings (5)

To Bruno: good point. The speed up is more significant when dealing with large size matrices. Also, A and B are supposed to have the same size.

Bruno Luong

Padding has a bug when length of two arrays differ (same number of columns).
ND-array is not supported.
This function is slower than Matlab for-loop when convolution is carried out in small length arrays. It would be nice to have some recommended usage.

Bruno Luong

I see. I should download and read the file before commenting, my Bad (I though it's row or column convolution between an array and a fixed kernel). This submission is indeed useful.

To Bruno: By column-wise I mean C=conv(A,B), where the i-th column of C is the convolution of the i-th column in A and the i-th column in B. How to use conv2 to do that?

Bruno Luong

Author should revise what he wrote: yes Matlab provides a way to convolute rowwise and column-wise by calling CONV2 with appropriate column-shape or row-shape kernel.


Rewrite the description.

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags