convolution - MATLAB: Using CONVN for moving average on Matrix -


i'm looking bit of guidance on using convn calculate moving averages in 1 dimension on 3d matrix. i'm getting little caught on flipping of kernel under hood , hoping might able clarify behaviour me.

a similar post still has me bit confused here:

convn example flipping

the problem:

i have daily river , weather flow data watershed @ different source locations.

so matrix so,

dim 1 (the rows) represent each site dim 2 (the columns) represent date dim 3 (the pages) represent different type of measurement (river height, flow, rainfall, etc.)

the goal try , use convn take 21 day moving average @ each site, each observation point each variable.

as understand it, should able use a kernel such as:

ker = ones(1,21) ./ 21.; mat = randn(150,365*10,4); avgmat = convn(mat,ker,'valid'); 

i tried playing around , created kernel should work (i think) , set ker2 as:

ker2 = [zeros(1,21); ker; zeros(1,21)]; avgmat2 = convn(mat,ker2,'valid'); 

the question:

the results don't quite match , i'm wondering if have dimensions incorrect here kernel. guidance appreciated.

judging context of question, have 3d matrix , want find moving average of each row independently on 3d slices. code above should work (the first case). however, valid flag returns matrix size valid in terms of boundaries of convolution. take @ first point of post linked more details.

specifically, first 21 entries each row missing due valid flag. it's when 22nd entry of each row convolution kernel become contained inside row of matrix , it's point valid results (no pun intended). if you'd see these entries @ boundaries, you'll need use 'same' flag if want maintain same size matrix input or 'full' flag (which default) gives size of output starting extreme outer edges, bear in mind moving average done bunch of zeroes , first 21 entries wouldn't expect anyway.

however, if i'm interpreting asking, valid flag want, bear in mind have 21 entries missing accommodate edge cases. in all, code should work, careful on how interpret results.

btw, have symmetric kernel, , flipping should have no effect on convolution output. have specified standard moving averaging kernel, , convolution should work in finding moving average expect.


good luck!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -