JS8Call-Improved master
Loading...
Searching...
No Matches
coherent_likelihood.h File Reference

Conservative coherent 8-FSK likelihood support for the JS8 decoder. More...

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdlib>
#include <limits>
#include <numbers>
#include <optional>
#include <vector>
Include dependency graph for coherent_likelihood.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  js8::CoherentPilot
struct  js8::CoherentDataSymbol
struct  js8::CarrierPhaseFit
 Result of the low-order carrier-phase fit over pilot symbols. More...
struct  js8::CoherentLikelihoodTelemetry
 Debug/benchmark telemetry for one candidate frame. More...
struct  js8::CoherentToneResult
struct  js8::CoherentBlend< ToneRows, DataSymbols >

Namespaces

namespace  js8
 JS8 namespace for Kalman filter-based trackers.

Functions

double js8::detail::wrapPhase (double angle)
bool js8::detail::solveWeightedLine2 (const double *x0, const double *x1, const double *y, const double *w, std::size_t n, double &a, double &b)
double js8::effectiveSymbolTimeSeconds (double baseTimeSeconds, double shiftSamples, double sampleRateHz)
std::complex< double > js8::normalizeFrequencyTrackerPhase (std::complex< double > bin, double trackerHz, double sampleRateHz, int windowSamples)
std::complex< double > js8::normalizeTimingPhase (std::complex< double > bin, int tone, double shiftSamples, int windowSamples)
CarrierPhaseFit js8::fitCarrierPhase (std::vector< CoherentPilot > const &pilots, int minPilots, double minSpanSeconds, int windowSamples, double sampleRateHz)
double js8::coherentBlendWeight (CarrierPhaseFit const &fit)
double js8::predictCarrierPhase (CarrierPhaseFit const &fit, double timeSeconds)
 Predicted carrier phase at an absolute symbol-start time.
template<std::size_t Tones>
bool js8::blendToneScores (std::array< float, Tones > const &noncoherent, std::array< float, Tones > const &coherent, float alpha, std::array< float, Tones > &out)
template<std::size_t Tones>
std::optional< double > js8::topTwoMargin (std::array< float, Tones > const &scores)
 Margin between the largest and second-largest tone scores, if well-defined.
CoherentToneResult js8::computeCoherentToneScores (std::vector< CoherentPilot > const &pilots, std::vector< CoherentDataSymbol > const &data, int minPilots, double minSpanSeconds, int windowSamples, double sampleRateHz)

Variables

constexpr double js8::detail::kMaxDeltaFHz = 1.0
constexpr double js8::detail::kMaxDriftHzPerSec = 0.05
constexpr double js8::detail::kGoodPhaseRmsRad = 0.20
constexpr double js8::detail::kPoorPhaseRmsRad = 0.60

Detailed Description

Conservative coherent 8-FSK likelihood support for the JS8 decoder.

The JS8 waveform is phase-continuous: over one symbol the tone-dependent phase term accumulates exactly 2*pi*tone radians, so every symbol-start FFT bin for the transmitted tone shares a common carrier phase (mod 2*pi). This header fits that carrier phase trajectory from the known Costas pilot symbols and converts complex data-symbol tone bins into coherent tone numerators.

Phase frame: the decoder's FrequencyTracker and TimingTracker perturb the complex bins deterministically (see normalizeFrequencyTrackerPhase() and normalizeTimingPhase()). Every observation is divided back into one consistent nominal-boundary phase frame before fitting or scoring. The trackers themselves are never modified.

Likelihood units: with complex noise variance sigma^2 = toneNoise * symbolNoise (the WhiteningProcessor convention), the tone-dependent part of the coherent log likelihood for a known amplitude A is (A*projection - 0.5*A*A) * invSigma2, where projection = Re(bin * exp(-j*phase)). The decoder multiplies the numerators produced here by its own per-symbol invSigma2 and blends them with the legacy 0.5*power*invSigma2 scores. No symbol is ever normalized independently, so symbol reliability information is preserved.

Design constraints (see decoder integration):

  • Only Costas/pilot symbols feed the phase fit; data symbols never do.
  • The fit is a low-order carrier model phase(t) = phi0 + 2*pi*delta_f*(t-tc) + pi*fdot*(t-tc)^2 solved in closed form from adjacent pilot phase differences plus one absolute-phase refinement pass: O(pilots), no frequency/drift grid.
  • A measurable quality gate (pilot count, span, residual RMS) decides the blend weight. Poor, ambiguous, or non-finite fits fall back to the existing noncoherent likelihoods (alpha = 0).