Last active
July 25, 2019 19:40
-
-
Save tryggvigy/02fc7c3187165ca448ff5c246eb8174a to your computer and use it in GitHub Desktop.
autoCorrelation optimization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function autoCorrelation(arr) { | |
var ac = new Float32Array(2048); | |
for (var lag = 0; lag < arr.length; lag++) { | |
var value = 0; | |
for (var index = 0; index < arr.length - lag; index++) { | |
let a = arr[index]; | |
- let b = arr[index-lag]; | |
+ let otherindex = index - lag; | |
+ let b = otherindex >= 0 ? arr[index-lag] : 0; | |
value = value + a * b; | |
} | |
ac[lag] = value; | |
} | |
return ac; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment