public static void realTransform(double data[],boolean inverse){
  double c1=0.5;
  int n=data.length;
  double twoPi=-MathUtils.TWOPI;
  if (inverse)   twoPi=MathUtils.TWOPI;
  double delta=twoPi / n;
  double wStepReal=Math.cos(delta);
  double wStepImag=Math.sin(delta);
  double wReal=wStepReal;
  double wImag=wStepImag;
  double c2;
  if (!inverse) {
    c2=-0.5;
    transform(data,false);
  }
 else {
    c2=0.5;
  }
  int n4=n >> 2;
  for (int i=1; i < n4; i++) {
    int twoI=i << 1;
    int twoIPlus1=twoI + 1;
    int nMinusTwoI=n - twoI;
    int nMinusTwoIPlus1=nMinusTwoI + 1;
    double h1r=c1 * (data[twoI] + data[nMinusTwoI]);
    double h1i=c1 * (data[twoIPlus1] - data[nMinusTwoIPlus1]);
    double h2r=-c2 * (data[twoIPlus1] + data[nMinusTwoIPlus1]);
    double h2i=c2 * (data[twoI] - data[nMinusTwoI]);
    data[twoI]=h1r + wReal * h2r - wImag * h2i;
    data[twoIPlus1]=h1i + wReal * h2i + wImag * h2r;
    data[nMinusTwoI]=h1r - wReal * h2r + wImag * h2i;
    data[nMinusTwoIPlus1]=-h1i + wReal * h2i + wImag * h2r;
    double oldWReal=wReal;
    wReal=oldWReal * wStepReal - wImag * wStepImag;
    wImag=oldWReal * wStepImag + wImag * wStepReal;
  }
  if (!inverse) {
    double tmp=data[0];
    data[0]+=data[1];
    data[1]=tmp - data[1];
    data[n / 2 + 1]=-data[n / 2 + 1];
  }
 else {
    double tmp=data[0];
    data[0]=0.5 * (tmp + data[1]);
    data[1]=0.5 * (tmp - data[1]);
    data[n / 2 + 1]=-data[n / 2 + 1];
    transform(data,true);
  }
}

public static void realTransform ( double data [ ] , boolean inverse ) { double c1 = 0.5 ; int n = data . length ; double twoPi = - MathUtils . TWOPI ; if ( inverse ) twoPi = MathUtils . TWOPI ; double delta = twoPi / n ; double wStepReal = Math . cos ( delta ) ; double wStepImag = Math . sin ( delta ) ; double wReal = wStepReal ; double wImag = wStepImag ; double c2 ; if ( ! inverse ) { c2 = - 0.5 ; transform ( data , false ) ; } else { c2 = 0.5 ; } int n4 = n > > 2 ; for ( int i = 1 ; i < n4 ; i ++ ) { int twoI = i << 1 ; int twoIPlus1 = twoI + 1 ; int nMinusTwoI = n - twoI ; int nMinusTwoIPlus1 = nMinusTwoI + 1 ; double h1r = c1 * ( data [ twoI ] + data [ nMinusTwoI ] ) ; double h1i = c1 * ( data [ twoIPlus1 ] - data [ nMinusTwoIPlus1 ] ) ; double h2r = - c2 * ( data [ twoIPlus1 ] + data [ nMinusTwoIPlus1 ] ) ; double h2i = c2 * ( data [ twoI ] - data [ nMinusTwoI ] ) ; data [ twoI ] = h1r + wReal * h2r - wImag * h2i ; data [ twoIPlus1 ] = h1i + wReal * h2i + wImag * h2r ; data [ nMinusTwoI ] = h1r - wReal * h2r + wImag * h2i ; data [ nMinusTwoIPlus1 ] = - h1i + wReal * h2i + wImag * h2r ; double oldWReal = wReal ; wReal = oldWReal * wStepReal - wImag * wStepImag ; wImag = oldWReal * wStepImag + wImag * wStepReal ; } if ( ! inverse ) { double tmp = data [ 0 ] ; data [ 0 ] += data [ 1 ] ; data [ 1 ] = tmp - data [ 1 ] ; data [ n / 2 + 1 ] = - data [ n / 2 + 1 ] ; } else { double tmp = data [ 0 ] ; data [ 0 ] = 0.5 * ( tmp + data [ 1 ] ) ; data [ 1 ] = 0.5 * ( tmp - data [ 1 ] ) ; data [ n / 2 + 1 ] = - data [ n / 2 + 1 ] ; transform ( data , true ) ; } }
calculates the fourier transform of a set of n real - valued data points . replaces this data ( which is stored in array data [ 1 . . n ] ) by the positive frequency half of its complex fourier transform . the real - valued first and last components of the complex transform are returned as elements data [ 1 ] and data [ 2 ] , respectively . n must be a power of 2 . this routine also calculates the inverse transform of a complex data array if it is the transform of real data . ( result in this case must be multiplied by 2 / n . )
