Quick question/explination Re 'movavg'

3 ビュー (過去 30 日間)
Scragmore 2011 年 12 月 22 日
I have just created five arrays, four of them using 'movavg' of variang sample lengths, the last array is just the raw data.
>> [mavS1, mavS2] = movavg(LSEtest{7,2}(:,5),5,20,'e');
>> [mavS3, mavS4] = movavg(LSEtest{7,2}(:,5),50,200,'e');
>> mavS0 = LSEtest{7,2}(:,5);
What is confusing me is that they are all the same size, "double 466x1". This should not be correct as my raw data is 466x1 and a movavg of '200' must be no more than 266x1 as there is insufficient data points for the first 200 entries to creat the average. I have looked at the m-files for movavg and filter and I am just not getting it. Could some one please explain so I know which data points I need to ignore/discard.
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 12 月 22 日
Related material: http://www.mathworks.com/matlabcentral/answers/1190-movavg-function-lead-and-lag-meaning


回答 (1 件)

Matt Tearle
Matt Tearle 2011 年 12 月 22 日
With filter, ignore the first n points. However, you're using the 'e' option, which doesn't actually call filter. It uses the code:
for j = 2:r
a(j) = a(j-1) + alphal*(asset(j) - a(j-1));
where alphal is determined by the lead n, and a(1) = asset(1). Hence, the output values are, in fact, legitimately determined for the entire length of the data set. Essentially, the window length goes from the beginning of the data to the current point.
  2 件のコメント
Matt Tearle
Matt Tearle 2011 年 12 月 27 日
Yeah, "legitimately" was the best word I could think of at the time. I guess what I really meant was "isn't zero padded". That's the big difference between 'e' and the others. You're right that they all return the same sized vectors as the input. With the regular averaging (using filter), the start of the output is essentially what you said: sum/n even though the sum doesn't include n elements (equivalently, the sum includes n values which are padded with zeros when there's fewer than n data points).
A good way to see the difference between 'e' and the others is to try it on some constant data:
n = 100;
x = linspace(0,1,n)';
y = ones(n,1);
[ysl,yst] = movavg(y,5,20,0);
[ysl,yst] = movavg(y,5,20,'e');


Community Treasure Hunt

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

Start Hunting!

Translated by