For a fast computation you can implement moving sums of X and X^2 for both signals, then obtain moving averages and variances as
M = sum(X)/windowLen;
V = ( sum(X^2) - sum(X)^2 )/windowLen;
Then find sum
V12 = sum( (X1-M1)*(X2-M2) );
And then sliding correlation itself:
It can be done efficiently within one for loop by adding one new value and substacting the old one.
*The same way we can find statistical moments, by adding moving sums of higher powers - X^3, X^4 etc.
**Additionally, you can add any span value for integer decimation.
2 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/195903-how-to-compute-sliding-or-running-window-correlation-coefficient#comment_276316
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/195903-how-to-compute-sliding-or-running-window-correlation-coefficient#comment_276316
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/195903-how-to-compute-sliding-or-running-window-correlation-coefficient#comment_276322
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/195903-how-to-compute-sliding-or-running-window-correlation-coefficient#comment_276322
Sign in to comment.