필터 지우기
필터 지우기

How do I compute 3 minute moving average in timeseries?

조회 수: 24 (최근 30일)
Sirish Selvam
Sirish Selvam 2019년 3월 14일
댓글: Peter Perkins 2020년 5월 13일
I have a time series object with two columns : Date,time (dd-mm-yyyy HH:MM:SS format) and Value. The data is sampled every 2 seconds. The total data is available is for around 10 days. How do I compute a timeseries with 3-minute moving average values?

채택된 답변

Image Analyst
Image Analyst 2019년 3월 14일
3 minutes at every 2 seconds would be about 91 elements, so use movmean():
movingAverageSignal = movmean(signal, 91);
  댓글 수: 1
Chris Turnes
Chris Turnes 2019년 3월 15일
If the times are stored as datetimes, you don't even need to figure out that it's about 91 elements; you can do
y = movmean(x, minutes(3), 'SamplePoints', timestamps)

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

추가 답변 (2개)

Peter Perkins
Peter Perkins 2019년 3월 15일
If you mean, "means for each 3-minute time window", consider using a timetable and the retime function. If you mean, "means at each 2-sec step over the previous 3 minutes", you can also do that on a timetable, using smoothdata.
  댓글 수: 2
nlm
nlm 2020년 5월 7일
How to calculate a 10 day average when the timeseries has duplicate dates. I do not want to average the dupliate dates priorly. I want to include them in the 10 day average. When I use movmean, I get this error, any suggestions ?
Error using builtin
'SamplePoints' value contains duplicates.
Error in datetime/movmean (line 105)
y = builtin('_movmeandt', args{:});
Peter Perkins
Peter Perkins 2020년 5월 13일
Use retime.

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


Andrei Bobrov
Andrei Bobrov 2019년 3월 14일
Let ts - your timeseries object.
k = 3*60/2; % the number of elements corresponding to three minutes in your case
ts.Data(:,2) = movmean(ts.Data,[0, k - 1]);

카테고리

Help CenterFile Exchange에서 Preprocessing Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by