Example #1
0
void fft2d(double **xtre, double **xtim, int width, int height)
{
    double **xint_re = Matrix::allocateMatrixData(height, width);
    if (!xint_re)
        return;
    double **xint_im = Matrix::allocateMatrixData(height, width);
    if (!xint_im){
        Matrix::freeMatrixData(xint_re, height);
        return;
    }

#ifdef Q_CC_MSVC
    QVarLengthArray<double> x_int_l(width), x_int2_l(width), x_int_c(height), x_int2_c(height);
#else
    double x_int_l[width], x_int2_l[width], x_int_c[height], x_int2_c[height];
#endif
    for(int k=0; k<height; k++){
        for(int j=0; j<width; j++){
            //x_int_l[j] = x[k][j];
            //x_int2_l[j] = 0.0;

            x_int_l[j] = xtre[k][j];
            x_int2_l[j] = xtim[k][j];
        }
#ifdef Q_CC_MSVC
        fft(x_int_l.data(), x_int2_l.data(), width);
#else
        fft(x_int_l, x_int2_l, width);
#endif
        for(int j=0; j<width; j++){
            xint_re[k][j]=x_int_l[j];
            xint_im[k][j]=x_int2_l[j];
        }
    }

    for(int k=0; k<width; k++){
        for(int i=0; i<height; i++){
            x_int_c[i]=xint_re[i][k];
            x_int2_c[i]=xint_im[i][k];
        }
#ifdef Q_CC_MSVC
        fft(x_int_c.data(),x_int2_c.data(), height) ;
#else
        fft(x_int_c,x_int2_c, height) ;
#endif
        for(int i=0; i<height; i++){
            xtre[(i+(height>>1))%height][(k+(width>>1))%width]=x_int_c[i];
            xtim[(i+(height>>1))%height][(k+(width>>1))%width]=x_int2_c[i];
        }
    }
    Matrix::freeMatrixData(xint_re, height);
    Matrix::freeMatrixData(xint_im, height);
}
Example #2
0
void fft2d_inv(double **xtre, double **xtim, double **xrec_re, double **xrec_im,
               int width, int height) {
  double **xint_re = Matrix::allocateMatrixData(height, width);
  if (!xint_re)
    return;
  double **xint_im = Matrix::allocateMatrixData(height, width);
  if (!xint_im) {
    Matrix::freeMatrixData(xint_re, height);
    return;
  }

  QVarLengthArray<double> x_int_l(width), x_int2_l(width), x_int_c(height),
      x_int2_c(height); // double x_int_l[width], x_int2_l[width],
                        // x_int_c[height], x_int2_c[height];
  for (int k = 0; k < height; k++) {
    for (int j = 0; j < width; j++) {
      int idx_h = (k + (height >> 1)) % height;
      int idx_w = (j + (width >> 1)) % width;
      x_int_l[j] = xtre[idx_h][idx_w];
      x_int2_l[j] = xtim[idx_h][idx_w];
    }
    fft_inv(x_int_l.data(), x_int2_l.data(),
            width); // fft_inv(x_int_l, x_int2_l, width) ;
    for (int j = 0; j < width; j++) {
      xint_re[k][j] = x_int_l[j];
      xint_im[k][j] = x_int2_l[j];
    }
  }
  for (int k = 0; k < width; k++) {
    for (int i = 0; i < height; i++) {
      x_int_c[i] = xint_re[i][k];
      x_int2_c[i] = xint_im[i][k];
    }
    fft_inv(x_int_c.data(), x_int2_c.data(),
            height); // fft_inv(x_int_c,x_int2_c, height) ;
    for (int i = 0; i < height; i++) {
      xrec_re[i][k] = x_int_c[i];
      xrec_im[i][k] = x_int2_c[i];
    }
  }
  Matrix::freeMatrixData(xint_re, height);
  Matrix::freeMatrixData(xint_im, height);
}