diff --git a/src/Numerics/Statistics/Statistics.cs b/src/Numerics/Statistics/Statistics.cs
index 3fe30641..9a92fafe 100644
--- a/src/Numerics/Statistics/Statistics.cs
+++ b/src/Numerics/Statistics/Statistics.cs
@@ -931,5 +931,21 @@ namespace MathNet.Numerics.Statistics
{
return StreamingStatistics.Entropy(data.Where(d => d.HasValue).Select(d => d.Value));
}
+
+ ///
+ /// Evaluates the sample mean over a moving window, for each samples.
+ /// Returns NaN if no data is empty or if any entry is NaN.
+ ///
+ /// The sample stream to calculate the mean of.
+ /// The number of last samples to consider.
+ public static IEnumerable MovingAverage(this IEnumerable samples, int windowSize)
+ {
+ var movingStatistics = new MovingStatistics(windowSize);
+ return samples.Select(sample =>
+ {
+ movingStatistics.Push(sample);
+ return movingStatistics.Mean;
+ });
+ }
}
}