I'm calculating discrete Fourier transform using Numerical Recipes and (to confirm the result) Matlab. Working with real values only. 

My Matlab code

```
in(1)=0.0;
in(2)=1.0;
in(3)=2.0;
in(4)=3.0;
in(5)=4.0;
in(6)=5.0;
in(7)=6.0;
in(8)=7.0;

out = fft(in);

```

gives me

```
out =
 28.0000 + 0.0000i
 -4.0000 + 9.6569i
 -4.0000 + 4.0000i
 -4.0000 + 1.6569i
 -4.0000 + 0.0000i
 -4.0000 - 1.6569i
 -4.0000 - 4.0000i
 -4.0000 - 9.6569i

```

What `data` input do I need to send to Numerical recipes 

```
void realft( float data[], unsigned long n, int isign ){...}

```

in order to get the same output as Matlab? 

From this [NR forum](http://numerical.recipes/forum/showthread.php?t=1539) link, I found out that input to `realft` needs to be shifted one place, so I am using `in[0] = 0`, and consequently input is 1 element larger than N. 

Test code: 

```
#include <stdio.h>
#define LEN 8
int main()
{
  float inout[LEN+1];

  inout[0] = 0.0;
  inout[1] = 0.0;
  inout[2] = 1.0;
  inout[3] = 2.0;
  inout[4] = 3.0;
  inout[5] = 4.0;
  inout[6] = 5.0;
  inout[7] = 6.0;
  inout[8] = 7.0;

  realft( inout, LEN, 1 );

  for( unsigned int i=0; i<LEN+1; i=i+1)
      printf("%15.10f \n",inout[i]);

  return 0;
}

```

Output from the test code is: 

```
 0.00000000 
28.00000000
-4.00000000
-4.00000000 
-9.65685463
-4.00000000
-4.00000000
-4.00000000
-1.65685427

```

which is similar, but different from Matlab. 

`realft` is taken from Numerical Recipes (uses `four1` routine):