I have problems calculating the autocorrelation of my time series using the FFT. I know that
Corr(g,h)_j <-> G_k x H_k*
where G_k and H_k are the discrete Fourier transform of g_j and h_j and H_k* is the complex conjugation of H_k. My Code is:
void fft_corr(float *vin1, float *vin2, float *vout, int n)
{
static complex *A1; //working array
static complex *A2; //working array
static complex *B; //working array
int i,k;
A1 = (complex*) alloc1(n,sizeof(complex));
A2 = (complex*) alloc1(n,sizeof(complex));
B = (complex*) alloc1(n,sizeof(complex));
//copy pressure array to complex array
for(i=0;i<n;i++){
A1[i].r = vin1[i];
A2[i].r = vin2[i];
A1[i].i = 0.;
A2[i].i = 0.;
}
// perform fft inverse flag=1
pfacc(1,n,A1);
pfacc(1,n,A2);
for(k=0;k<n;k++){
B[k].r = A1[k].r * A2[k].r + A1[k].i * A2[k].i;
B[k].i = - A1[k].r * A2[k].i + A1[k].i * A2[k].r;
}
pfacc(-1,n,B);
for(i=0;i<n;i++) vout[i]=B[i].r/n; //write into output and normalize
}//#
What am I missing? The result does not look like an autocorrelation if A1 == A2.
Thanks a lot
pfacc
. – Paul R Jul 16 '13 at 18:14