diff --git a/src/matchedTemplateClassifer/MTClassifier.java b/src/matchedTemplateClassifer/MTClassifier.java index 75f30ef1..b1d43ee5 100644 --- a/src/matchedTemplateClassifer/MTClassifier.java +++ b/src/matchedTemplateClassifer/MTClassifier.java @@ -103,9 +103,14 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters if (waveformMatchFFT==null || currentSr!=sR) { if (fft==null) fft=new FastFFT(); + + //System.out.println("interpWaveform: " + waveformMatch.waveform.length + " sR " + waveformMatch.sR); + //re-sample the waveform if the sample rate is different this.interpWaveformMatch=interpWaveform(this.waveformMatch, sR); + //System.out.println("interpWaveformMatch: " + interpWaveformMatch.length + " sR " + sR); + //normalise //this.interpWaveformMatch=PamArrayUtils.normalise(interpWaveformMatch); @@ -115,9 +120,11 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters // System.out.println("MatchNorm: MATCH"); // MTClassifierTest.normalizeTest(interpWaveformMatch); - //here use the FFT length with the maximum template size. - waveformMatchFFT = fft.rfft(PamArrayUtils.flip(interpWaveformMatch), - length); + waveformMatchFFT = fft.rfft(interpWaveformMatch, length); + + //need to calculate the complex conjugate - note that originally I was flipping the array but this means + //the max value does not equal one with identical waveforms...doh. + waveformMatchFFT = waveformMatchFFT.conj(); // System.out.println("waveformMatch: " + waveformMatch.waveform.length + // " interpWaveformMatch: " + interpWaveformMatch.length + " for " +sR + " sr "); @@ -155,9 +162,11 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters // MTClassifierTest.printWaveform(inteprWaveformReject); //System.out.println("waveformReject: " +inteprWaveformReject.length + " fftLength: " + getFFTLength(sR)); + waveformRejectFFT = fft.rfft(inteprWaveformReject, length); - //must flip the waveform for cross correlation - might as well do this here. - waveformRejectFFT = fft.rfft(PamArrayUtils.flip(inteprWaveformReject), length); + //need to calculate the complex conjugate - note that originally I was flipping the array but this means + //the max value does not equal one with identical waveforms...doh. + waveformRejectFFT = waveformRejectFFT.conj(); } return waveformRejectFFT; } @@ -342,11 +351,9 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters //set the stored sR currentSr=sR; -// System.out.println("Matched click classifier: Waveform click: " + click.length()); -// System.out.println("Matched click classifier: Waveform click: " + click.length()); + //System.out.println("Waveform click: len: " + click.length()); -// System.out.println("Waveform Reject max: " + PamArrayUtils.max(this.inteprWaveformReject)); -// System.out.println("Waveform Reject max: " + PamArrayUtils.max(this.inteprWaveformReject)); + //System.out.println("Waveform Reject max: " + PamArrayUtils.max(this.inteprWaveformReject)+ " len " + interpWaveformMatch.length); //int fftLength = getFFTLength(sR); //int fftLength = this.getFFTLength(sR); @@ -363,7 +370,10 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters ComplexArray matchResult= new ComplexArray(fftLength); ComplexArray matchTemplate = getWaveformMatchFFT(sR,fftLength); - //System.out.println("matchTemplate: Waveform click: " + matchTemplate.length()); + + //System.out.println("matchTemplate interp: len: " + interpWaveformMatch.length+ " max: " + PamArrayUtils.max(interpWaveformMatch)); + //System.out.println("matchTemplate: len: " + waveformMatch.waveform.length+ " max: " + PamArrayUtils.max(waveformMatch.waveform)); + for (int i=0; i templates) { + testCorrelation(testWaveform, sR, templates, MatchedTemplateParams.NORMALIZATION_RMS); + } + + + /** * Test the correlation of several templates - * @param testWaveform - * @param sR - * @param templates - * @return + * @param testWaveform - the waveform to correlate against. + * @param sR - the sample rate of the waveform. + * @param templates - the match templates to test. + * @param normalisation - the normalisation type to use e.g. MatchedTemplateParams.NORMALIZATION_RMS */ - private static void testCorrelation(double[] testWaveform, float sR, ArrayList templates) { + private static void testCorrelation(double[] testWaveform, float sR, ArrayList templates, int normalisation) { //create the classifier object for (int i=0; i templates = importTemplates(templteFilePath); + + testCorrelation(templates.get(0).waveform, templates.get(0).sR, templates); + + } + public static void main(String args[]) { testMatchCorr(); diff --git a/src/matchedTemplateClassifer/layoutFX/MTSettingsPane.java b/src/matchedTemplateClassifer/layoutFX/MTSettingsPane.java index a3cb83b6..2ca0748e 100644 --- a/src/matchedTemplateClassifer/layoutFX/MTSettingsPane.java +++ b/src/matchedTemplateClassifer/layoutFX/MTSettingsPane.java @@ -257,7 +257,7 @@ public class MTSettingsPane extends SettingsPane { //click normalisation normBox = new ComboBox(); - normBox.getItems().addAll("peak to peak", "RMS", "none"); + normBox.getItems().addAll("peak to peak", "norm", "none"); PamHBox clickNormPane= new PamHBox(); clickNormPane.setSpacing(5);