八度时间序列移动平均线

Alg*_*Man 9 matlab signal-processing time-series octave financial

我有一个矩阵,每列代表一个特征随着时间的推移.我需要找到给定窗口大小的这些值的移动平均值.

有没有像一个功能一个在MATLAB?

output = tsmovavg(vector, 's', lag, dim)
Run Code Online (Sandbox Code Playgroud)

Amr*_*mro 19

您可以使用FILTER功能.一个例子:

t = (0:.001:1)';                                %#'
vector = sin(2*pi*t) + 0.2*randn(size(t));      %# time series

wndw = 10;                                      %# sliding window size
output1 = filter(ones(wndw,1)/wndw, 1, vector); %# moving average
Run Code Online (Sandbox Code Playgroud)

甚至使用Image Package中的IMFILTERFSPECIAL

output2 = imfilter(vector, fspecial('average', [wndw 1]));
Run Code Online (Sandbox Code Playgroud)

最后一个选项是使用索引(不推荐用于非常大的向量)

%# get indices of each sliding window
idx = bsxfun(@plus, (1:wndw)', 0:length(vector)-wndw);
%'# compute average of each
output3 = mean(vector(idx),1);
Run Code Online (Sandbox Code Playgroud)

请注意填充的区别:output1(wndw:end)对应output3