Example #1
0
  private static Dataset ifft1d(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);
        float[] fdata = null;
        shape = a.getShape();
        shape[axis] = n;
        result = new ComplexFloatDataset(shape);
        dest = new ComplexFloatDataset(new int[] {n});
        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.complexInverse(fdata, true);
          result.setItemsOnAxes(pos, hit, fdata);
        }
        break;
      case Dataset.FLOAT64:
      case Dataset.COMPLEX128:
        DoubleFFT_1D dfft = new DoubleFFT_1D(n);
        double[] ddata = null;
        shape = a.getShape();
        shape[axis] = n;
        result = new ComplexDoubleDataset(shape);
        dest = new ComplexDoubleDataset(new int[] {n});
        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.complexInverse(ddata, true);
          result.setItemsOnAxes(pos, hit, ddata);
        }
        break;
      default:
        logger.warn("Non-float dataset not yet supported");
        break;
    }

    return result;
  }
Example #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);
  }
  public static void coupe100(AudioSignal input) {
    int fs = input.samplingRate;
    int N = input.getLength();
    float[] Y = Arrays.copyOf(input.data, 2 * N);
    FloatFFT_1D fft = new FloatFFT_1D(N);
    fft.realForwardFull(Y);

    int threshold = 100 * 2;
    Arrays.fill(Y, 0, Math.round(threshold * (float) N / fs), 0);
    Arrays.fill(Y, Math.round(2 * N - threshold * (float) N / fs), 2 * N - 1, 0);

    fft.complexInverse(Y, true);

    for (int i = 0; i < N; i++) {
      input.data[i] = Y[2 * i];
    }
  }
  public static List<float[]> deconvol(float[] signal, int fs, int fenetre, int n0) {
    int nbfram = signal.length;

    int frameparfenetre = Math.round(fs * (float) fenetre / 1000);
    int recoupframe = Math.round(frameparfenetre / 2);
    float[] hamming = new float[frameparfenetre];
    for (int i = 0; i < frameparfenetre; i++) {
      hamming[i] = (float) (0.54 - 0.46 * Math.cos(2 * Math.PI * i / (frameparfenetre - 1)));
    }
    int fftsize = (int) Math.pow(2, Math.ceil(log2(frameparfenetre)));

    List<float[]> result = new ArrayList<>();

    int end = nbfram - frameparfenetre;
    for (int i = 0; i < end; i += frameparfenetre - recoupframe) {
      int to = Math.min(i + frameparfenetre - 1, end);
      float[] sfen = new float[to - i + 1];
      System.arraycopy(signal, i, sfen, 0, sfen.length);
      sfen = accentue(sfen);
      for (int j = 0; j < sfen.length; j++) {
        sfen[j] = sfen[j] * hamming[j];
      }

      FloatFFT_1D fft = new FloatFFT_1D(sfen.length);
      fft.realForward(sfen);
      for (int j = 0; j < sfen.length; j++) {
        sfen[j] = (float) Math.log(Math.abs(sfen[j]));
      }
      fft.realInverse(sfen, true);
      Arrays.fill(sfen, n0 + 1, sfen.length - 1, 0);
      fft.realForward(sfen);
      for (int j = 0; j < sfen.length; j++) {
        sfen[j] = (float) Math.abs(Math.exp(sfen[j]));
      }
      result.add(Arrays.copyOfRange(sfen, 2, Math.round(fftsize / 2) - 1));
    }

    return result;
  }
  private void processRecordedData() {
    mIsProcessing = true;

    float[] recordedDataFFT;
    recordedDataFFT = FrequencyDetector.convertToFloats(mRecordedData);
    fft.realForward(recordedDataFFT);

    float[] halfAbsFFT;
    halfAbsFFT = FrequencyDetector.absAndHalve(recordedDataFFT);

    int[] peaks;
    peaks = FrequencyDetector.identifyPeaksAndRemove(halfAbsFFT);

    String peakString = "";
    for (int e : peaks) peakString += e + " ";
    Log.d(TAG, peakString);

    int frequency = FrequencyDetector.detectFrequency(peaks);
    if (frequency != -1) this.updateStrings(frequency);

    mIsProcessing = false;
  }