/** * Determines if a power value is a peak at the spectrum. Compares it with the two frequency bins * above and below. * * @param index The index location to test inside the current list of valid frequencies. * @return True if it is a peak at that frequency, else false. * @throws IndexOutOfBoundsException If the given index forces a comparison out of bounds */ private boolean isPeakAt(int index) throws IndexOutOfBoundsException { int frequency = validFrequencies.get(index); // get the frequency at the point. double power = freqPower[frequency]; for (int i = (-3 + index); i <= (3 + index); i++) { if (i >= 0 && i < validFrequencies.size() && i != index) { int oFrequency = validFrequencies.get(i); double oPower = freqPower[oFrequency]; double dp = power - oPower; if (dp < PEAK_THRESHOLD) return false; } } return true; }
/** Extracts the local peaks from the spectrum at this particular time interval. */ private void getLocalPeaks() { for (int i = 0; i < validFrequencies.size(); i++) { try { if (isPeakAt(i)) { int frequency = validFrequencies.get(i); // get the frequency at the particular index Peak peak = new Peak(spectrumNumber, frequency, freqPower[frequency]); // System.out.println(spectrumNumber + " " + frequency); peaks.add(peak); // System.out.println(peak.getTime() + " " + peak.getFrequency()); } } catch (IndexOutOfBoundsException e) { // do nothing } } }