Why moving average plot is not starting as the original signal

조회 수: 3 (최근 30일)
rohail khan
rohail khan 2018년 4월 4일
댓글: Walter Roberson 2018년 4월 4일
Hi, I am trying to analyze a stock data with only two columns i.e dates and value of stocks Both of these columns have length=63.I am trying to calculate the moving average to smooth the curve.I use the following code and get the out put as shown below
window=5;
mask=ones(1,window)/window;
quarter=conv(stocks,mask,'same');
plot(dates,stocks)
hold on
plot(dates,quarter)
ylim([7300,7700])
legend('input data' ,'filtered data')
Why the filtered data curve is not starting from the point where the original input data is starting? How to fix the plot? Is my method to get the moving average right? Is there a better way? thanks

답변 (1개)

Walter Roberson
Walter Roberson 2018년 4월 4일
You are getting effects from the zero padding. See the 'valid' option instead of 'same'
Or consider using
quarter = movavg(stocks(:), 'simple', window) .';
  댓글 수: 2
rohail khan
rohail khan 2018년 4월 4일
hi, Thank you so much for quick reply. I tried the code but now its giving me the following error: 'Undefined function 'movavg' for input arguments of type 'double'
Please can you explain how to use the 'movavg' function.
Thanks
Walter Roberson
Walter Roberson 2018년 4월 4일
I forgot that movavg is from the Financial Toolbox. You might want movmean() from R2016a or later.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by