How can I do 1D convolution on a 880*1 feature with filter size 45*1 with stride of 42?

3 views (last 30 days)
I have a 885*1 feature and I would like to do a convolution with 45*1 with stride 42.
I want to get a 21*1 feature as a result.
If input layer(885*1) is named A, what sholud be the code?

Answers (1)

Matt J
Matt J on 19 Jul 2020
Edited: Matt J on 19 Jul 2020
You can create a weight matrix that computes the convolution using func2mat on the File Exchange
For example,
>> k=rand(45,1);
>> C=func2mat(@(z) conv(z,k,'valid'),rand(885,1));
>> C=C(1:42:end,:);
>> whos C
Name Size Bytes Class Attributes
C 21x885 22208 double sparse
If you wish, you can verify that C*x gives the equivalent convolution as follows,
>> x=rand(885,1);
>> y1=conv(x,k,'valid'); y1=y1(1:42:end);
>> y2=C*x;
>> norm(y1-y2)
ans =
1.2809e-14

Products

Community Treasure Hunt

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

Start Hunting!