added Schmitt trigger

This commit is contained in:
Ahmet Inan 2024-04-16 12:34:30 +02:00
parent b8c98317b1
commit 8a1d7ca7ba
2 changed files with 31 additions and 1 deletions

View file

@ -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;

View file

@ -0,0 +1,28 @@
/*
Schmitt Trigger
Copyright 2024 Ahmet Inan <xdsopl@gmail.com>
*/
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;
}
}