File: Autocorrelation.cpp

package info (click to toggle)
fmit 1.3.2-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,356 kB
  • sloc: cpp: 9,515; sh: 69; makefile: 12
file content (18 lines) | stat: -rw-r--r-- 450 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "Autocorrelation.h"

/* Compute the autocorrelation
 *			,--,
 *  ac(i) = >  x(n) * x(n-i)  for all n
 *	  		`--'
 * for lags between 0 and lag-1, and x == 0 outside 0...n-1
 */
void autocorrelation(
		int   n, double const * x,   /*  in: [0...n-1] samples x   */
	int lag, double       * ac)  /* out: [0...lag-1] ac values */
{
	double d; int i;
	while (lag--) {
		for (i = lag, d = 0; i < n; i++) d += x[i] * x[i-lag];
		ac[lag] = d;
	}
}