diff --git a/app/src/main/java/xdsopl/robot36/Demodulator.java b/app/src/main/java/xdsopl/robot36/Demodulator.java index 54799cf..e050bcb 100644 --- a/app/src/main/java/xdsopl/robot36/Demodulator.java +++ b/app/src/main/java/xdsopl/robot36/Demodulator.java @@ -12,6 +12,7 @@ public class Demodulator { private final ComplexMovingAverage scanLineFilter; private final ComplexMovingAverage baseBandLowPass; private final FrequencyModulation scanLineDemod; + private final SchmittTrigger syncPulseTrigger; private final Phasor syncPulseOscillator; private final Phasor scanLineOscillator; private final Phasor baseBandOscillator; @@ -50,6 +51,7 @@ public class Demodulator { syncPulseDelay = new Delay(syncPulseDelaySamples); int scanLineDelaySamples = (powerWindowSamples - 1) / 2 + (syncPulseFilterSamples - 1) / 2 - (scanLineFilterSamples - 1) / 2; scanLineDelay = new Delay(scanLineDelaySamples); + syncPulseTrigger = new SchmittTrigger(0.17f, 0.19f); baseBand = new Complex(); syncPulse = new Complex(); scanLine = new Complex(); @@ -64,7 +66,7 @@ public class Demodulator { float scanLineValue = scanLineDelay.push(scanLineDemod.demod(scanLine)); float syncPulseLevel = Math.min(Math.max(syncPulseValue, 0), 1); float scanLineLevel = Math.min(Math.max(0.5f * (scanLineValue + 1), 0), 1); - if (syncPulseLevel > 0.1) + if (syncPulseTrigger.latch(syncPulseLevel)) buffer[i] = -syncPulseLevel; else buffer[i] = scanLineLevel; diff --git a/app/src/main/java/xdsopl/robot36/SchmittTrigger.java b/app/src/main/java/xdsopl/robot36/SchmittTrigger.java new file mode 100644 index 0000000..93733ec --- /dev/null +++ b/app/src/main/java/xdsopl/robot36/SchmittTrigger.java @@ -0,0 +1,28 @@ +/* +Schmitt Trigger + +Copyright 2024 Ahmet Inan +*/ + +package xdsopl.robot36; + +public class SchmittTrigger { + private final float low, high; + private boolean previous; + + SchmittTrigger(float low, float high) { + this.low = low; + this.high = high; + } + + boolean latch(float input) { + if (previous) { + if (input < low) + previous = false; + } else { + if (input > high) + previous = true; + } + return previous; + } +}