Input to realft()


eponymous
08-24-2008, 08:21 PM
Hi

I'm new to NR and was just wondering if I can do this to get a forward Fourier transform of just the positive frequency:


float input[1024];

realft(input, 1024, 1);



I wasn't sure this was right becuase it says in the function comments that it replaces data[1..n] with the FFT, but my array starts at index 0, not 1.

I want the values to go from 0 -> 1023, not 1->1024.

Also, does the array look like this when finished:

real // first real component
real // last real component
real
imaginary
real
imaginary

etc..?

I hope someone can help,

Thanks.

davekw7x
09-07-2008, 01:27 PM
...just wondering...realft...go from 0 -> 1023, not 1->1024

To use native (zero-base) 1-D arrays in Numerical Recipes (one-base) C functions like realft, you can fake it by feeding the function a pointer value that is one less than the address of the first element of the array. Realft takes care of the rest.


float x[1024];
.
.
.
/* fill up x[0] through x[1023] with your real values */
.
.
.
.
realft(x-1, 1024, 1);
.
.
.


...when finished?

For a 1024-point real-valued input array, realft calculates the values of 513 complex points, corresponding to frequencies ranging from zero up to, and including, half the sampling frequency.

For zero-based notation, we can consider the transform points to be numbered 0 through 512, and here's the way realft puts their values into your array. (The imaginary components of the first and last transform points are equal to zero, so these values don't be needed to conveyed back to the calling program.)


x[0] --- real component of transform point 0
x[1] --- real component of transform point 512
x[2] --- real component of transform point 1
x[3] --- imaginary component of transform point 1
x[4] --- real component of transform point 2
x[5] --- imaginary component of transform point 2
.
.
.
x[1022] --- real component of transform point 511
x[1023] --- imaginary component of transform point 511



Regards,

Dave