diff --git a/app/src/main/java/xdsopl/robot36/Demodulator.java b/app/src/main/java/xdsopl/robot36/Demodulator.java index e050bcb..3171236 100644 --- a/app/src/main/java/xdsopl/robot36/Demodulator.java +++ b/app/src/main/java/xdsopl/robot36/Demodulator.java @@ -18,6 +18,10 @@ public class Demodulator { private final Phasor baseBandOscillator; private final Delay syncPulseDelay; private final Delay scanLineDelay; + private final int syncPulseSamples; + private float syncPulseMaxLevel; + private int syncPulseMaxPosition; + private int syncPulseCounter; private Complex baseBand; private Complex syncPulse; private Complex scanLine; @@ -34,8 +38,8 @@ public class Demodulator { int scanLineFilterSamples = (int) Math.round(0.443 * sampleRate / scanLineCutoff) | 1; scanLineFilter = new ComplexMovingAverage(scanLineFilterSamples); double syncPulseSeconds = 0.009; - int syncPulseFilterSamples = (int) Math.round(syncPulseSeconds * sampleRate) | 1; - syncPulseFilter = new ComplexMovingAverage(syncPulseFilterSamples); + syncPulseSamples = (int) Math.round(syncPulseSeconds * sampleRate) | 1; + syncPulseFilter = new ComplexMovingAverage(syncPulseSamples); float lowestFrequency = 1100; float highestFrequency = 2300; float cutoffFrequency = (highestFrequency - lowestFrequency) / 2; @@ -49,7 +53,7 @@ public class Demodulator { scanLineOscillator = new Phasor(-(grayFrequency - centerFrequency), sampleRate); int syncPulseDelaySamples = (powerWindowSamples - 1) / 2; syncPulseDelay = new Delay(syncPulseDelaySamples); - int scanLineDelaySamples = (powerWindowSamples - 1) / 2 + (syncPulseFilterSamples - 1) / 2 - (scanLineFilterSamples - 1) / 2; + int scanLineDelaySamples = (powerWindowSamples - 1) / 2 + (syncPulseSamples - 1) / 2 - (scanLineFilterSamples - 1) / 2; scanLineDelay = new Delay(scanLineDelaySamples); syncPulseTrigger = new SchmittTrigger(0.17f, 0.19f); baseBand = new Complex(); @@ -66,10 +70,25 @@ 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 (syncPulseTrigger.latch(syncPulseLevel)) - buffer[i] = -syncPulseLevel; - else + if (syncPulseTrigger.latch(syncPulseLevel)) { + if (syncPulseMaxLevel < syncPulseLevel) { + syncPulseMaxLevel = syncPulseLevel; + syncPulseMaxPosition = syncPulseCounter; + } + ++syncPulseCounter; + buffer[i] = syncPulseLevel; + } else if (syncPulseCounter > 0 && syncPulseCounter < syncPulseSamples) { + int offset = syncPulseCounter - syncPulseMaxPosition; + if (offset <= i) + buffer[i - offset] = -1; + syncPulseCounter = 0; + syncPulseMaxLevel = 0; buffer[i] = scanLineLevel; + } else { + syncPulseCounter = 0; + syncPulseMaxLevel = 0; + buffer[i] = scanLineLevel; + } } } } diff --git a/app/src/main/java/xdsopl/robot36/MainActivity.java b/app/src/main/java/xdsopl/robot36/MainActivity.java index ff193be..8a4f9e8 100644 --- a/app/src/main/java/xdsopl/robot36/MainActivity.java +++ b/app/src/main/java/xdsopl/robot36/MainActivity.java @@ -62,15 +62,11 @@ public class MainActivity extends AppCompatActivity { private void visualizeSignal() { for (float v : recordBuffer) { - int pixelColor = 0x00010101; - float level = v; - if (v < 0) { - level = -v; - pixelColor = 0x00000100; + int pixelColor = 0xff00ff00; + if (v >= 0) { + int intensity = (int) Math.round(255 * Math.sqrt(v)); + pixelColor = 0xff000000 | 0x00010101 * intensity; } - int intensity = (int) Math.round(255 * Math.sqrt(level)); - pixelColor *= intensity; - pixelColor |= 0xff000000; scopePixels[scopeWidth * curLine + curColumn] = pixelColor; if (++curColumn >= scopeWidth) { curColumn = 0;