mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2025-02-18 02:02:48 +00:00
More bug fixes for matched template
This commit is contained in:
parent
cf4e3ccfe1
commit
5b2f6f440b
@ -4,6 +4,7 @@ import java.io.Serializable;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.jamdev.jpamutils.wavFiles.WavInterpolator;
|
||||||
|
|
||||||
import com.jmatio.types.MLArray;
|
import com.jmatio.types.MLArray;
|
||||||
import com.jmatio.types.MLDouble;
|
import com.jmatio.types.MLDouble;
|
||||||
@ -87,6 +88,12 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters
|
|||||||
|
|
||||||
public final static int TEST_FFT_LENGTH=300;
|
public final static int TEST_FFT_LENGTH=300;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decimates waveforms.
|
||||||
|
*/
|
||||||
|
private WavInterpolator wavInterpolator = new WavInterpolator();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default MT classifier
|
* Default MT classifier
|
||||||
*/
|
*/
|
||||||
@ -444,10 +451,26 @@ public class MTClassifier implements Serializable, Cloneable, ManagedParameters
|
|||||||
*/
|
*/
|
||||||
private double[] interpWaveform(MatchTemplate waveformMatch, double sR) {
|
private double[] interpWaveform(MatchTemplate waveformMatch, double sR) {
|
||||||
//System.out.println("Interp waveform: " + " old: " + waveformMatch.sR + " new: " + 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);
|
double[] interpWaveformMatch=reSampleWaveform(waveformMatch.waveform, waveformMatch.sR, sR);
|
||||||
//System.out.println("RESULT: old len: " + waveformMatch.waveform.length + " new len: " +interpWaveformMatch.length);
|
|
||||||
return interpWaveformMatch;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public double[] binArray(int start, int stop, double step) {
|
public double[] binArray(int start, int stop, double step) {
|
||||||
|
@ -115,7 +115,7 @@ public class MTClassifierTest {
|
|||||||
|
|
||||||
testWaveform = MTClassifier.normaliseWaveform(testWaveform, MatchedTemplateParams.NORMALIZATION_RMS);
|
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.
|
//calculate the click FFT.
|
||||||
@ -196,7 +196,7 @@ public class MTClassifierTest {
|
|||||||
MLDouble clickUID=(MLDouble) mlArrayRetrived.getField("UID", i);
|
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;
|
return clicks;
|
||||||
}
|
}
|
||||||
@ -327,14 +327,14 @@ public class MTClassifierTest {
|
|||||||
*/
|
*/
|
||||||
public static void testMatchCorrLen() {
|
public static void testMatchCorrLen() {
|
||||||
|
|
||||||
String testClicksPath = "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS2clks_test.mat";
|
String testClicksPath = "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS3clks_test.mat";
|
||||||
String templteFilePath= "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS2templates_test.mat";
|
String templteFilePath= "/Users/au671271/MATLAB-Drive/MATLAB/PAMGUARD/matchedclickclassifer/DS3templates_test.mat";
|
||||||
|
|
||||||
float sR = 288000; //sample rate in samples per second.
|
float sR = 288000; //sample rate in samples per second.
|
||||||
ArrayList<MatchTemplate> clicks = importClicks(testClicksPath, sR);
|
ArrayList<MatchTemplate> clicks = importClicks(testClicksPath, sR);
|
||||||
ArrayList<MatchTemplate> templates = importTemplates(templteFilePath);
|
ArrayList<MatchTemplate> templates = importTemplates(templteFilePath);
|
||||||
|
|
||||||
int index = 0;
|
int index = 24;
|
||||||
//values in MATLAB are9.73577287114938 8.82782814105430 3.51936216182390
|
//values in MATLAB are9.73577287114938 8.82782814105430 3.51936216182390
|
||||||
System.out.println("Number of clicks: " + clicks.size() + " UID " + clicks.get(index).name);
|
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--------");
|
System.out.println("------Restricted Length--------");
|
||||||
|
|
||||||
int restrictedBins= 1024;
|
int restrictedBins= 2048;
|
||||||
|
|
||||||
ClickLength clickLength = new ClickLength();
|
ClickLength clickLength = new ClickLength();
|
||||||
int[][] lengthPoints = clickLength.createLengthData(clicks.get(index), sR, 5.5, 3, false, null);
|
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[]) {
|
public static void main(String args[]) {
|
||||||
testMatchCorr();
|
testMatchCorrLen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ public class GenericModelTest {
|
|||||||
//long time1 = System.currentTimeMillis();
|
//long time1 = System.currentTimeMillis();
|
||||||
data = new float[][][] {DLUtils.toFloatArray(((FreqTransform) transform).getSpecTransfrom().getTransformedData())};
|
data = new float[][][] {DLUtils.toFloatArray(((FreqTransform) transform).getSpecTransfrom().getTransformedData())};
|
||||||
|
|
||||||
|
|
||||||
//data = new float[][][] { DLUtils.makeDummySpectrogram(40, 40)};
|
//data = new float[][][] { DLUtils.makeDummySpectrogram(40, 40)};
|
||||||
|
|
||||||
//System.out.println("data len: " + data.length + " " + data[0].length + " " + data[0][0].length);
|
//System.out.println("data len: " + data.length + " " + data[0].length + " " + data[0][0].length);
|
||||||
|
Loading…
Reference in New Issue
Block a user