Filter löschen
Filter löschen

How do I compute 3 minute moving average in timeseries?

24 Ansichten (letzte 30 Tage)
Sirish Selvam
Sirish Selvam am 14 Mär. 2019
Kommentiert: Peter Perkins am 13 Mai 2020
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?

Akzeptierte Antwort

Image Analyst
Image Analyst am 14 Mär. 2019
3 minutes at every 2 seconds would be about 91 elements, so use movmean():
movingAverageSignal = movmean(signal, 91);
  1 Kommentar
Chris Turnes
Chris Turnes am 15 Mär. 2019
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Peter Perkins
Peter Perkins am 15 Mär. 2019
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 Kommentare
nlm
nlm am 7 Mai 2020
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{:});

Melden Sie sich an, um zu kommentieren.


Andrei Bobrov
Andrei Bobrov am 14 Mär. 2019
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]);

Kategorien

Mehr zu Preprocessing Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by