Moving Window Statistics

版本 1.2.0.0 (220.8 KB) 作者: atharva aalok
Toolbox for calculating moving window statistics FAST!
50.0 次下载
更新时间 2023/9/7

Moving-Window-Statistics

This is a toolbox for calculating moving window statistics such as mean, variance, skewness, etc. fast!

Get started with the Example.m file.

Released on MATLAB FileExchange View Moving Window Statistics on File Exchange

Introduction

A simple and naive approach towards calculating moving window statistics could be to move the window over the data and for each window calculate the moving window statistic using in-built functions (such as var, skewness etc. in MATLAB). But this approach is very slow as it involves a lot of redundant calculations. For example, consider the case of finding the moving variance. Using this naive approach, for each window one would have to square all the data points towards calculation of the variance. Now since the windows will have a good amount of overlap the same data point which is common amongst several windows will be squared repeatedly, leading to redundant calculations which slow down the process.

To calculate the different moving window statistics fast we use a one-pass approach where we go through each data point only once, getting rid of all redundant operations.

The formulas used for calculating the statistical values and the proofs for the formulas are explained in the pdf document Moving_Window_Statistics_Explanations.pdf provided.

Performance Comparison

The speed gains, as measured by the ratio of time taken by the naive approach and the moving statistic functions are quite astonishing!1.

Statistic Speed Gain
Mean 108x
RMS 151x
Variance 71x
Skewness 400x
Kurtosis 310x
Autocorrelation 765x

These tests can be performed by running the Performance_Comparison.m file provided.

References

Wikipedia: Algorithms for calculating variance
MATLAB Answers: Optimizing for speed. Moving skewness finder. Cumulative sum proving to be bottleneck.

Note

Suggestions for improving the method and code are highly encouraged!

Footnotes

  1. The speed gains are approximate. Also, they depend on the length of the time series. Current results are for a length of 100,000.

引用格式

atharva aalok (2024). Moving Window Statistics (https://github.com/atharvaaalok/Moving-Window-Statistics/releases/tag/v1.2), GitHub. 检索来源 .

MATLAB 版本兼容性
创建方式 R2023a
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.2.0.0

See release notes for this release on GitHub: https://github.com/atharvaaalok/Moving-Window-Statistics/releases/tag/v1.2

1.1.0.0

See release notes for this release on GitHub: https://github.com/atharvaaalok/Moving-Window-Statistics/releases/tag/v1.1

1.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库