Autocorrelation function


DoraSzasz
11-11-2009, 09:01 AM
Hello!
I want to implement the autocorrelation function void corel() from 13.3 chapter in a program that uses signals and I don't know where I can find the realft() function and where I declare VecDoub_I&data1, VecDoub_I&data2 VecDoub_O&ans

Cand you help me,please?
Thank you!
Dora

MPD78
11-11-2009, 10:53 AM
This post might help you out.

http://www.nr.com/forum/showthread.php?t=1417&highlight=correl

The realft() function is locate in 12.3 of the NR3 book. It is in the fourier.h header file.

Are you familiar with the Index of Routines on the website?

Thanks
Matt

davekw7x
11-11-2009, 01:15 PM
...autocorrelation...

//
// Illustration using NR3 correl() for autocorrelation
//
// davekw7x
// 11/11/2009
//
#include "../code/nr3.h"
#include "../code/fourier.h"
#include "../code/correl.h"

int main()
{

const Int xsize = 16;

// A zero-padded array (the rest are initialized to zero)
Doub x_array[xsize] = { 1.0, 1.0, 1.0, 1.0 };
VecDoub x(xsize, x_array);

// Result will be a vector of the same size as x
VecDoub z(x.size());

//
// Autocorrelation uses same vector for first and
// second argument
//
correl(x, x, z);

cout << fixed << showpoint;
for (Int i = 0; i < z.size(); i++) {
cout << "x[" << setw(2) << i << "]= " << setw(9) << x[i]
<< " z[" << setw(2) << i << "] = "
<< setw(9) << z[i] << endl;
}

return 0;
}


Output:


x[ 0]= 1.000000 z[ 0] = 4.000000
x[ 1]= 1.000000 z[ 1] = 3.000000
x[ 2]= 1.000000 z[ 2] = 2.000000
x[ 3]= 1.000000 z[ 3] = 1.000000
x[ 4]= 0.000000 z[ 4] = -0.000000
x[ 5]= 0.000000 z[ 5] = -0.000000
x[ 6]= 0.000000 z[ 6] = -0.000000
x[ 7]= 0.000000 z[ 7] = 0.000000
x[ 8]= 0.000000 z[ 8] = 0.000000
x[ 9]= 0.000000 z[ 9] = -0.000000
x[10]= 0.000000 z[10] = -0.000000
x[11]= 0.000000 z[11] = 0.000000
x[12]= 0.000000 z[12] = 0.000000
x[13]= 0.000000 z[13] = 1.000000
x[14]= 0.000000 z[14] = 2.000000
x[15]= 0.000000 z[15] = 3.000000


Regards,

Dave