public static IEnumerable <IReadOnlyList <T> > MovingWindows <T>([NotNull] this IEnumerable <T> values, uint windowSize, double overlap) { if (windowSize <= 0) { throw new ArgumentException("window size must be positive"); } if (overlap < 0 || overlap >= 1) { throw new ArgumentException("overlap must in range of [0, 1)"); } var overlapSize = Math.Min((uint)(windowSize * overlap), windowSize - 1); var windowStep = windowSize - overlapSize; var samples = new CircularFifoBuffer <T>(windowSize); uint counter = 0; foreach (var value in values) { samples.Add(value); counter++; if (samples.Count >= windowSize && counter >= windowStep) { counter = 0; yield return(samples); } } }