Package edu.purdue.wind.util

Source Code of edu.purdue.wind.util.WaveCrackDetector

package edu.purdue.wind.util;

import java.io.IOException;

import edu.purdue.wind.Wave;
import edu.purdue.wind.CrackDetector;
import edu.purdue.wind.Turbine;

public class WaveCrackDetector {
    public static void main(String[] args) {
  if (args.length != 2) {
      System.err.println("usage: WaveCrackDetector <file.wav> <probingFreq");
      System.exit(1);
  }

  Wave wave;
  try {
      wave = Wave.readFile(args[0]);
  } catch (IOException e) {
      throw new RuntimeException(e);
  }

  if (wave.channels() != 2) {
      System.err.println("Stereo input data required");
      System.exit(1);
  }

  int nSamples = 0;
  for (int i = 0; i < 32; i++) {
      if ((1 << i) > wave.samples()) {
    break;
      }
      nSamples = 1 << i;
  }

  double[][] data = new double[2][nSamples];
  for (short c = 0; c < 2; c++) {
      int[] samples = wave.sampleData(c);
      for (int i = 0; i < nSamples; i++) {
    data[c][i] = (double)samples[i];
      }
  }

  CrackDetector detector = new CrackDetector(wave.sampleRate(), nSamples);
  Turbine t = new Turbine();

  double probingFreq = Double.parseDouble(args[1]);
  detector.processAudio(t.blade(0), data[0], probingFreq);
  detector.processAudio(t.blade(1), data[1], probingFreq);

  if (detector.detect(t.blade(0), t.blade(1))) {
      System.out.println("Crack detected");
  } else {
      System.out.println("No cracks");
  }
    }
}
TOP

Related Classes of edu.purdue.wind.util.WaveCrackDetector

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.