Beispiel #1
0
  private static Dataset fft1d(final Dataset a, final int n, final int axis) {
    Dataset result = null;
    Dataset dest = null;

    int[] shape;
    PositionIterator pi;
    int[] pos;
    boolean[] hit;

    switch (a.getDtype()) {
      case Dataset.FLOAT32:
      case Dataset.COMPLEX64:
        FloatFFT_1D ffft = new FloatFFT_1D(n);
        shape = a.getShape();
        shape[axis] = n;
        result = new ComplexFloatDataset(shape);
        dest = new ComplexFloatDataset(new int[] {2 * n});
        float[] fdata = (float[]) dest.getBuffer();
        pi = a.getPositionIterator(axis);
        pos = pi.getPos();
        hit = pi.getOmit();
        while (pi.hasNext()) {
          Arrays.fill(fdata, 0.f);
          a.copyItemsFromAxes(pos, hit, dest);
          ffft.complexForward(fdata);
          result.setItemsOnAxes(pos, hit, fdata);
        }
        break;
      case Dataset.FLOAT64:
      case Dataset.COMPLEX128:
        DoubleFFT_1D dfft = new DoubleFFT_1D(n);
        shape = a.getShape();
        shape[axis] = n;
        result = new ComplexDoubleDataset(shape);
        dest = new ComplexDoubleDataset(new int[] {2 * n});
        double[] ddata = (double[]) dest.getBuffer();
        pi = a.getPositionIterator(axis);
        pos = pi.getPos();
        hit = pi.getOmit();
        while (pi.hasNext()) {
          Arrays.fill(ddata, 0.);
          a.copyItemsFromAxes(pos, hit, dest);
          dfft.complexForward(ddata);
          result.setItemsOnAxes(pos, hit, ddata);
        }
        break;
      default:
        logger.warn("Non-float dataset not yet supported");
        break;
    }

    return result;
  }
Beispiel #2
0
  private void calculate() {
    float[] samples = getSamples();

    Window.apply(mWindow, samples);

    if (mSampleType == SampleType.REAL) {
      mFFT.realForward(samples);
    } else {
      mFFT.complexForward(samples);
    }

    dispatch(samples);
  }