applyFilter method
Implementation
double applyFilter(double sample) {
for (var i = 0; i < level; i++) {
if (((cnt - minReq[i] - 1) % pow(2, i).toInt()) == 0 &&
cnt >= minReq[i]) {
results = wDec[i].decompose(sample);
app[i] = results[0];
det[i] = results[1];
sample = app[i];
if (i > 0) {
if (i == 1) {
newDet[i - 1].add(0);
} else {
detWindow[i - 1].add(det[i - 1]);
if (detWindow[i - 1].length == window[i - 1]) {
absDetWindow = [];
for (var s = 0; s < detWindow[i - 1].length; s++) {
absDetWindow.add(detWindow[i - 1][s].abs());
}
threshLevel[i - 1] = thres * absDetWindow.reduce(max);
detWindow[i - 1].removeAt(0);
}
newDet[i - 1]
.add(wDec[i - 1].threshold(det[i - 1], threshLevel[i - 1]));
}
}
}
}
var reconsData = <double>[];
if ((cnt - minReq.last - 1) % pow(2, level) == 0 && cnt > minReq[level]) {
reconsData = [0];
reconsData[0] = app[level - 1];
for (var i = level; i > 0; i--) {
if (i == level) {
detWindow[i - 1].add(det[i - 1]);
if (detWindow[i - 1].length == window[i - 1]) {
absDetWindow = [];
for (var s = 0; s < detWindow[i - 1].length; s++) {
absDetWindow.add(detWindow[i - 1][s].abs());
}
threshLevel[i - 1] = thres * absDetWindow.reduce(max);
detWindow[i - 1].removeAt(0);
}
newDet[i - 1][0] =
wDec[i - 1].threshold(det[i - 1], threshLevel[i - 1]);
}
newApp = reconsData;
if (i == level) {
newDetL = [...newDet[i - 1]];
reconApp = wRec[i - 1].reconstruct(newApp[0], true);
reconDet = wRec[i - 1].reconstruct(newDetL[0], false);
newApp[0] = reconApp[0] + reconDet[0];
newApp.add(reconApp[1] + reconDet[1]);
reconsData = newApp;
} else {
reconsData = [];
for (var k = 0; k < newApp.length; k++) {
if (cntApp[i] >= cutInt) {
cntApp[i] += 1;
newDetL = [...newDet[i - 1]];
newDet[i - 1].removeAt(0);
reconApp = wRec[i - 1].reconstruct(newApp[k], true);
reconDet = wRec[i - 1].reconstruct(newDetL[0], false);
reconsData
..add(reconApp[0] + reconDet[0])
..add(reconApp[1] + reconDet[1]);
} else {
cntApp[i] += 1;
}
}
}
}
}
cnt += 1;
if (level == 1) {
reconstructedData = reconstructedData + reconsData;
if (reconstructedData.length < 2) {
return double.nan;
} else {
reconstructedData.removeAt(0);
if (cutInd < 6) {
cutInd += 1;
return double.nan;
} else {
return reconstructedData[0];
}
}
} else {
if (cntApp[1] > 6) {
reconstructedData = reconstructedData + reconsData;
if (reconsData.isEmpty || reconsData.length == pow(2, level)) {
if (waitInd > 0) {
waitInd -= 1;
return double.nan;
} else {
reconstructedData.removeAt(0);
if (cutInd < 6) {
cutInd += 1;
return double.nan;
} else {
return reconstructedData[0];
}
}
} else {
waitInd = pow(2, level).toInt() - reconsData.length;
waitInd -= 1;
return double.nan;
}
} else {
return double.nan;
}
}
}