Debian Codegraph @

libs/Music/Autocorrelation.cpp

raw
1 #include "Autocorrelation.h"
2
3 /* Compute the autocorrelation
4 * ,--,
5 * ac(i) = > x(n) * x(n-i) for all n
6 * `--'
7 * for lags between 0 and lag-1, and x == 0 outside 0...n-1
8 */
9 void autocorrelation(
10 int n, double const * x, /* in: [0...n-1] samples x */
11 int lag, double * ac) /* out: [0...lag-1] ac values */
12 {
13 double d; int i;
14 while (lag--) {
15 for (i = lag, d = 0; i < n; i++) d += x[i] * x[i-lag];
16 ac[lag] = d;
17 }
18 }