Skip to content

Commit d7501ee

Browse files
AsCressmarcnause
authored andcommitted
feat: added the Noise Detection enhancement to the Auto-Scale feature
1 parent dd5db82 commit d7501ee

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

app/src/main/java/io/pslab/activity/OscilloscopeActivity.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.widget.LinearLayout;
2727
import android.widget.RelativeLayout;
2828
import android.widget.TextView;
29+
import android.widget.Toast;
2930

3031
import androidx.annotation.IdRes;
3132
import androidx.annotation.NonNull;
@@ -1170,7 +1171,7 @@ protected void onPostExecute(Void aVoid) {
11701171
public void autoScale() {
11711172
double minY = Double.MAX_VALUE;
11721173
double maxY = Double.MIN_VALUE;
1173-
double maxPeriod = Double.MIN_VALUE;
1174+
double maxPeriod = -1 * Double.MIN_VALUE;
11741175
double yRange;
11751176
double yPadding;
11761177
double[] voltage = new double[512];
@@ -1203,14 +1204,14 @@ public void autoScale() {
12031204
}
12041205
yRange = maxY - minY;
12051206
yPadding = yRange * 0.1;
1206-
if ((maxPeriod * 5) < maxTimebase) {
1207-
xAxisScale = maxPeriod * 5;
1207+
if (maxPeriod > 0) {
1208+
xAxisScale = Math.min((maxPeriod * 5), maxTimebase);
1209+
yAxisScale = maxY + yPadding;
1210+
samples = 512;
1211+
timeGap = (2 * xAxisScale * 1000.0) / samples;
12081212
} else {
1209-
xAxisScale = maxTimebase;
1213+
Toast.makeText(this, getString(R.string.auto_scale_error), Toast.LENGTH_SHORT).show();
12101214
}
1211-
yAxisScale = maxY + yPadding;
1212-
samples = 512;
1213-
timeGap = (2 * xAxisScale * 1000.0) / samples;
12141215
}
12151216

12161217
public class XYPlotTask extends AsyncTask<String, Void, Void> {

app/src/main/java/io/pslab/communication/AnalyticsClass.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.commons.math3.transform.DftNormalization;
1111
import org.apache.commons.math3.transform.FastFourierTransformer;
1212
import org.apache.commons.math3.transform.TransformType;
13+
1314
import io.pslab.filters.BandstopFilter;
1415
import io.pslab.filters.Lfilter;
1516

@@ -330,7 +331,12 @@ public double findFrequency(double[] voltage, double samplingInterval) {
330331
index = i;
331332
}
332333
}
333-
return frequency[index];
334+
double noiseThreshold = 0.1;
335+
if (max >= noiseThreshold) {
336+
return frequency[index];
337+
} else {
338+
return -1;
339+
}
334340
}
335341

336342
public ArrayList<double[]> amplitudeSpectrum(double[] voltage, int samplingInterval, int nHarmonics) {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@
10561056
<string name="limit_average">Average</string>
10571057
<string name="no_playback_data">No data to display</string>
10581058
<string name="privacy_policy">Privacy Policy</string>
1059+
<string name="auto_scale_error">No input found</string>
10591060
<string name="auto_scale">Auto</string>
10601061
<string name="control_stop">Stop</string>
10611062
<string name="control_run">Run</string>

0 commit comments

Comments
 (0)