Esempio n. 1
0
  private PCMReader buildLOBFFilter(Shell shell) throws IncompatibleDataTypeError {
    PCMReader reader = new PCMReader();
    PlotData timeData = new PlotData();
    PlotCanvas timeCanvas = new PlotCanvas(shell, timeData);
    timeCanvas.setup();
    timeData.setDataPerHeight(0x20000000 / 1);
    timeData.setDataPerWidth(30000);
    timeData.xoffset = 5000;
    timeData.title = "Input";
    reader.addListener(timeCanvas);

    LocalMaximaFilter filter1 = new LocalMaximaFilter();
    filter1.connectTo(reader);

    LOBFFilter filter2 = new LOBFFilter(100);
    PlotData maData = new PlotData();
    PlotCanvas maCanvas = new PlotCanvas(shell, maData);
    maCanvas.setup();
    maData.setDataPerHeight(0x20000000);
    maData.setDataPerWidth(30000);
    maData.xoffset = 5000;
    maData.title = "LOBF";
    filter2.addListener(maCanvas);
    filter2.connectTo(filter1);

    // spectrumData.spectrum = freqListener.getSpectrum();
    // spectrumData.freq_from = freqListener.getFreq_from();
    // spectrumData.freq_to = freqListener.getFreq_to();

    return reader;
  }
Esempio n. 2
0
  private PCMReader buildDifferentialFilter(Shell shell) throws IncompatibleDataTypeError {
    PCMReader reader = new PCMReader();
    PlotData timeData = new PlotData();
    PlotCanvas timeCanvas = new PlotCanvas(shell, timeData);
    timeCanvas.setup();
    timeData.setDataPerHeight(0x20000000 / 1);
    timeData.setDataPerWidth(30000);
    timeData.xoffset = 5000;
    timeData.title = "Input";
    reader.addListener(timeCanvas);

    LocalMaximaFilter filter1 = new LocalMaximaFilter();
    filter1.connectTo(reader);

    DifferentialFilter filter2 = new DifferentialFilter(10.0);
    PlotData maData = new PlotData();
    PlotCanvas maCanvas = new PlotCanvas(shell, maData);
    maCanvas.setup();
    maData.setDataPerHeight(0x20000000 / 1);
    maData.setDataPerWidth(30000);
    maData.xoffset = 5000;
    maData.title = "Differential";
    filter2.addListener(maCanvas);
    filter2.connectTo(filter1);

    return reader;
  }
Esempio n. 3
0
  private PCMReader buildFFTFilter(final Shell shell, boolean generatePNG)
      throws IncompatibleDataTypeError {
    PCMReader reader = new PCMReader();
    PlotData timeData = new PlotData();
    PlotCanvas timeCanvas = new PlotCanvas(shell, timeData);
    timeCanvas.setup();
    timeData.setDataPerHeight(0x20000000 / 1);
    timeData.setDataPerWidth(30000);
    timeData.xoffset = 5000;
    timeData.title = "Input";
    reader.addListener(timeCanvas);

    final FFTFilter filter1 = new FFTFilter(4096, 1024);
    PlotData maData = new PlotData();
    PlotCanvas maCanvas = new PlotCanvas(shell, maData);
    maCanvas.setup();
    maData.setDataPerHeight(5000);
    maData.setDataPerWidth(30000);
    maData.xoffset = 5000;
    maData.title = "FFT";
    filter1.addListener(maCanvas);
    if (generatePNG) {
      filter1.addListener(
          new FilterListener() {

            @Override
            public void filterOutput(FilterData output) {
              if (output == null) {
                return;
              }
              final FFTOutputData op = (FFTOutputData) output;
              final Display display = shell.getDisplay();

              display.asyncExec(
                  new Runnable() {

                    @Override
                    public void run() {
                      Image image = new Image(display, 800, 600);
                      GC gc = new GC(image);
                      gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
                      gc.fillRectangle(image.getBounds());

                      gc.drawString("Hello", 10, 20);
                      Complex[] spectrum = op.spectrum;
                      for (int i = 0; i < spectrum.length; i++) {
                        gc.drawLine(i, 0, i, (int) (spectrum[i].re() / 1e8));
                      }

                      PNGExporter exporter = new PNGExporter();
                      exporter.export(image.getImageData(), new File("spectro-" + op.x + ".png"));

                      image.dispose();
                    }
                  });
            }

            @Override
            public void filterEnd(long count) {}
          });
    } else {
      filter1.addListener(
          new FilterListener() {

            @Override
            public void filterOutput(FilterData output) {
              if (output == null) {
                return;
              }
              final FFTOutputData op = (FFTOutputData) output;
              Complex[] spectrum = op.spectrum;
              for (int i = 0; i < 200; i++) {
                System.out.print(spectrum[i].abs() + ",");
              }
              System.out.println();
            }

            @Override
            public void filterEnd(long count) {}
          });
    }
    filter1.connectTo(reader);

    return reader;
  }