More bug fixes for matched template

This commit is contained in:
Jamie Mac 2022-01-20 13:16:19 +00:00
parent cf4e3ccfe1
commit 5b2f6f440b
3 changed files with 31 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.lang.reflect.Field;
import org.apache.commons.lang3.ArrayUtils;
import org.jamdev.jpamutils.wavFiles.WavInterpolator;
import com.jmatio.types.MLArray;
import com.jmatio.types.MLDouble;
@ -87,6 +88,12 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters
public final static int TEST_FFT_LENGTH=300;
/**
* Decimates waveforms.
*/
private WavInterpolator wavInterpolator = new WavInterpolator();
/**
* Default MT classifier
*/
@ -444,9 +451,25 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters
*/
private double[] interpWaveform(MatchTemplate waveformMatch, double sR) {
//System.out.println("Interp waveform: " + " old: " + waveformMatch.sR + " new: " + sR);
if ( waveformMatch.sR>sR) {
//up sample
double[] interpWaveformMatch=reSampleWaveform(waveformMatch.waveform, waveformMatch.sR, sR);
//System.out.println("RESULT: old len: " + waveformMatch.waveform.length + " new len: " +interpWaveformMatch.length);
return interpWaveformMatch;
}
else if (waveformMatch.sR<sR){
// //TODO - make a better decimator?
// double[] interpWaveformMatch=reSampleWaveform(waveformMatch.waveform, waveformMatch.sR, sR);
// return interpWaveformMatch;
if (wavInterpolator == null) wavInterpolator = new WavInterpolator();
return wavInterpolator.decimate(waveformMatch.waveform, waveformMatch.sR, (float) sR);
}
else {
//nothing needed/
return waveformMatch.waveform;
}
}

View File

@ -115,7 +115,7 @@ public class MTClassifierTest {
testWaveform = MTClassifier.normaliseWaveform(testWaveform, MatchedTemplateParams.NORMALIZATION_RMS);
System.out.println("Waveform max: " + PamArrayUtils.max(testWaveform) + " len: " + testWaveform.length);
//System.out.println("Waveform max: " + PamArrayUtils.max(testWaveform) + " len: " + testWaveform.length);
//calculate the click FFT.
@ -196,7 +196,7 @@ public class MTClassifierTest {
MLDouble clickUID=(MLDouble) mlArrayRetrived.getField("UID", i);
clicks.add(new MatchTemplate(Integer.toString((int) clickUID.get(0).doubleValue()), waveform, 288000));
clicks.add(new MatchTemplate(Long.toString(clickUID.get(0).longValue()), waveform, 288000));
}
return clicks;
}
@ -327,14 +327,14 @@ public class MTClassifierTest {
*/
public static void testMatchCorrLen() {
String testClicksPath = "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS2clks_test.mat";
String templteFilePath= "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS2templates_test.mat";
String testClicksPath = "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS3clks_test.mat";
String templteFilePath= "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS3templates_test.mat";
float sR = 288000; //sample rate in samples per second.
ArrayList<MatchTemplate> clicks = importClicks(testClicksPath, sR);
ArrayList<MatchTemplate> templates = importTemplates(templteFilePath);
int index = 0;
int index = 24;
//values in MATLAB are9.73577287114938 8.82782814105430 3.51936216182390
System.out.println("Number of clicks: " + clicks.size() + " UID " + clicks.get(index).name);
@ -343,7 +343,7 @@ public class MTClassifierTest {
System.out.println("------Restricted Length--------");
int restrictedBins= 1024;
int restrictedBins= 2048;
ClickLength clickLength = new ClickLength();
int[][] lengthPoints = clickLength.createLengthData(clicks.get(index), sR, 5.5, 3, false, null);
@ -371,7 +371,7 @@ public class MTClassifierTest {
public static void main(String args[]) {
testMatchCorr();
testMatchCorrLen();
}

View File

@ -75,7 +75,6 @@ public class GenericModelTest {
//long time1 = System.currentTimeMillis();
data = new float[][][] {DLUtils.toFloatArray(((FreqTransform) transform).getSpecTransfrom().getTransformedData())};
//data = new float[][][] { DLUtils.makeDummySpectrogram(40, 40)};
//System.out.println("data len: " + data.length + " " + data[0].length + " " + data[0][0].length);