Quick question/explination Re 'movavg'
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
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.
Regards,
AD
댓글 수: 3
Walter Roberson
2011년 12월 22일
Related material: http://www.mathworks.com/matlabcentral/answers/1190-movavg-function-lead-and-lag-meaning
답변 (1개)
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));
end
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
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);
plot(x,y,x,ysl,x,yst)
figure
[ysl,yst] = movavg(y,5,20,'e');
plot(x,y,x,ysl,x,yst)
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!