add numerical recipes library
This commit is contained in:
25
lib/nr/cpp/recipes/correl.cpp
Normal file
25
lib/nr/cpp/recipes/correl.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "nr.h"
|
||||
|
||||
void NR::correl(Vec_I_DP &data1, Vec_I_DP &data2, Vec_O_DP &ans)
|
||||
{
|
||||
int no2,i;
|
||||
DP tmp;
|
||||
|
||||
int n=data1.size();
|
||||
Vec_DP temp(n);
|
||||
for (i=0;i<n;i++) {
|
||||
ans[i]=data1[i];
|
||||
temp[i]=data2[i];
|
||||
}
|
||||
realft(ans,1);
|
||||
realft(temp,1);
|
||||
no2=n>>1;
|
||||
for (i=2;i<n;i+=2) {
|
||||
tmp=ans[i];
|
||||
ans[i]=(ans[i]*temp[i]+ans[i+1]*temp[i+1])/no2;
|
||||
ans[i+1]=(ans[i+1]*temp[i]-tmp*temp[i+1])/no2;
|
||||
}
|
||||
ans[0]=ans[0]*temp[0]/no2;
|
||||
ans[1]=ans[1]*temp[1]/no2;
|
||||
realft(ans,-1);
|
||||
}
|
||||
Reference in New Issue
Block a user