I used to average over my data with MeanFilter before I learn about MovingAverage and thought that these two functions are similar except that MeanFilter is more powerful for its ability to deal with 2D data. However,even with 1D data I prefer MeanFilter because it will not shorten the list which saves my effort for taking care of the length of data list until I found that MeanFilter is surprisingly slow:
for example define the data:
dat = RandomReal[{0, 1}, 2000000];
caculate time consuming:
timeofmoav =
AbsoluteTiming[MovingAverage[dat[[1 ;; #]], 5];] & /@ (2^Range[10, 20])
and
timeofmefi =
AbsoluteTiming[MeanFilter[ dat[[1 ;; #]], 2][[3 ;; -3]];] & /@ (2^Range[10,20])
plot by:
ListLogLogPlot[
Transpose[{2^Range[10, 20], #}] & /@ {timeofmoav[[All, 1]],
timeofmefi[[All, 1]]}, Joined -> True, PlotStyle -> Thick,
PlotRange -> All, Frame -> True, ImageSize -> 500,
FrameTicksStyle -> 15, GridLines -> Automatic,
GridLinesStyle -> Directive[Orange, Dashed],
FrameLabel -> {"dat", "time consumed"}, LabelStyle -> 20,
PlotLegends ->
Placed[LineLegend[{"MovingAverage", "MeanFilter"},
LegendFunction -> "Panel"], {0.2, 0.8}]]
which looks like:
how should MeanFilter be so slow?
MeanFilter
(image processing and such). $\endgroup$