STIN void dcsqf1(int n,float *x,float *w,float *xh,int *ifac){
  int modn,i,k,kc;
  int np2,ns2;
  float xim1;

  ns2=(n+1)>>1;
  np2=n;

  kc=np2;
  for (k=1;k<ns2;k++){
    kc--;
    xh[k]=x[k]+x[kc];
    xh[kc]=x[k]-x[kc];
  }

  modn=n%2;
  if (modn==0)xh[ns2]=x[ns2]+x[ns2];

  for (k=1;k<ns2;k++){
    kc=np2-k;
    x[k]=w[k-1]*xh[kc]+w[kc-1]*xh[k];
    x[kc]=w[k-1]*xh[k]-w[kc-1]*xh[kc];
  }

  if (modn==0)x[ns2]=w[ns2-1]*xh[ns2];

  __ogg_fdrfftf(n,x,xh,ifac);

  for (i=2;i<n;i+=2){
    xim1=x[i-1]-x[i];
    x[i]=x[i-1]+x[i];
    x[i-1]=xim1;
  }
}
/**
  * Calculates the Fast Fourier Transformation (FFT).
  */
void FastFourierTransformer::calculateFFT(QList<qint16> wave)
{
    const int n = wave.size();
    if (m_last_n != n) {
        reserve(n);
    }
    for (int i = 0; i < n; i++) {
        m_waveFloat[i] = (float) wave.at(i);
    }

    __ogg_fdrfftf(n, m_waveFloat, m_workingArray, m_ifac);

}
void
DiscreteFourierTransform(int n)
{
	double	p_value, upperBound, percentile, N_l, N_o, d, *m, *X, *wsave;
	int		i, count, ifac[15];

	if ( ((X = (double*) calloc(n,sizeof(double))) == NULL) ||
		 ((wsave = (double *)calloc(2*n,sizeof(double))) == NULL) ||
		 ((m = (double*)calloc(n/2+1, sizeof(double))) == NULL) ) {
			fprintf(stats[7],"\t\tUnable to allocate working arrays for the DFT.\n");
			if( X == NULL )
				free(X);
			if( wsave == NULL )
				free(wsave);
			if( m == NULL )
				free(m);
			return;
	}
	for ( i=0; i<n; i++ )
		X[i] = 2*(int)epsilon[i] - 1;
	
	__ogg_fdrffti(n, wsave, ifac);		/* INITIALIZE WORK ARRAYS */
	__ogg_fdrfftf(n, X, wsave, ifac);	/* APPLY FORWARD FFT */
	
	m[0] = sqrt(X[0]*X[0]);	    /* COMPUTE MAGNITUDE */
	
	for ( i=0; i<n/2; i++ )
		m[i+1] = sqrt(pow(X[2*i+1],2)+pow(X[2*i+2],2)); 
	count = 0;				       /* CONFIDENCE INTERVAL */
	upperBound = sqrt(2.995732274*n);
	for ( i=0; i<n/2; i++ )
		if ( m[i] < upperBound )
			count++;
	percentile = (double)count/(n/2)*100;
	N_l = (double) count;       /* number of peaks less than h = sqrt(3*n) */
	N_o = (double) 0.95*n/2.0;
	d = (N_l - N_o)/sqrt(n/4.0*0.95*0.05);
	p_value = erfc(fabs(d)/sqrt(2.0));

	/*
	printf("\t\t\t\tFFT TEST\n");
	printf("\t\t-------------------------------------------\n");
	printf("\t\tCOMPUTATIONAL INFORMATION:\n");
	printf("\t\t-------------------------------------------\n");
	printf("\t\t(a) Percentile = %f\n", percentile);
	printf("\t\t(b) N_l        = %f\n", N_l);
	printf("\t\t(c) N_o        = %f\n", N_o);
	printf("\t\t(d) d          = %f\n", d);
	printf("\t\ttp_value       = %f\n", p_value);
	printf("\t\tstatus         = %s\n", p_value < ALPHA ? "NON RANDOM" : "RANDOM");
	printf("\t\t-------------------------------------------\n");
	*/
	
	fprintf(stats[TEST_FFT], "\t\t\t\tFFT TEST\n");
	fprintf(stats[TEST_FFT], "\t\t-------------------------------------------\n");
	fprintf(stats[TEST_FFT], "\t\tCOMPUTATIONAL INFORMATION:\n");
	fprintf(stats[TEST_FFT], "\t\t-------------------------------------------\n");
	fprintf(stats[TEST_FFT], "\t\t(a) Percentile = %f\n", percentile);
	fprintf(stats[TEST_FFT], "\t\t(b) N_l        = %f\n", N_l);
	fprintf(stats[TEST_FFT], "\t\t(c) N_o        = %f\n", N_o);
	fprintf(stats[TEST_FFT], "\t\t(d) d          = %f\n", d);
	fprintf(stats[TEST_FFT], "\t\t-------------------------------------------\n");

	fprintf(stats[TEST_FFT], "%s\t\tp_value = %f\n\n", p_value < ALPHA ? "FAILURE" : "SUCCESS", p_value);
	fprintf(results[TEST_FFT], "%f\n", p_value);

	free(X);
	free(wsave);
	free(m);
}