Hi.
I’m using cufft in a project I’m working on. What I need, is to get the result from cufft and normalize it, the same way MATLAB normalizes it’s fft’s. Does anyone have an idea on how to do this? I’m really quite clueless of how to do it. Tried a normal, complex-vector normalization, but it didn’t give the same result.
The normalization algorithm in C.
void normalize(cufftComplex *vec, cufftComplex *result, int N)
{
cufftComplex norm;
norm.x = norm.y = 0.0f;
for(int i = 0; i < N; ++i) {
norm.x += (vec[i].x*vec[i].x - vec[i].y*vec[i].y);
norm.y += (vec[i].x*vec[i].y + vec[i].x*vec[i].y);
}
float r = sqrt(norm.x*norm.x + norm.y*norm.y);
float x = norm.x;
float y = norm.y;
norm.x = sqrt((r + x)*0.5);
norm.y = y/sqrt(2*(r+x));
float div = (norm.x*norm.x + norm.y*norm.y);
if(div != 0) {
div = 1.0 / div;
for(int i = 0; i < N; ++i) {
result[i].x = (vec[i].x*norm.x + vec[i].y*norm.y) / div;
result[i].y = (vec[i].x*norm.y - vec[i].y*norm.x) / div;
}
}
}