Use quadrature chirplet timing
This commit is contained in:
parent
0a169c4315
commit
bd9659e9d2
8 changed files with 134 additions and 85 deletions
|
|
@ -1,5 +1,10 @@
|
|||
using Mimir.Runtime.Synchronization;
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--chirplet-self-test", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return RunChirpletSelfTest();
|
||||
}
|
||||
|
||||
var duration = TimeSpan.FromSeconds(ParseDoubleOption(args, "--seconds", 10.0));
|
||||
var pollDelay = TimeSpan.FromMilliseconds(ParseDoubleOption(args, "--poll-ms", 10.0));
|
||||
var requireSamples = args.Any(arg => string.Equals(arg, "--require-samples", StringComparison.OrdinalIgnoreCase));
|
||||
|
|
@ -112,6 +117,39 @@ static string DescribeBands(IReadOnlyList<MimirChirpletBandResponse> bands)
|
|||
: string.Join(",", bands.Select(band => $"{band.CenterHz:0}Hz:{band.Energy:0.000}"));
|
||||
}
|
||||
|
||||
static int RunChirpletSelfTest()
|
||||
{
|
||||
var timeline = MimirChirpletTimeline.Default;
|
||||
var decoder = new MimirChirpletStreamDecoder(windowDuration: TimeSpan.FromSeconds(2));
|
||||
MimirChirpletStreamDecode decode = new([], [], [], null);
|
||||
for (ulong segment = 0; segment < 4; segment++)
|
||||
{
|
||||
decode = decoder.Append(timeline.RenderSegmentMonoFloat(segment));
|
||||
}
|
||||
|
||||
var meanAbsoluteError = decode.ClockFit?.MeanAbsoluteErrorSamples ?? double.PositiveInfinity;
|
||||
Console.WriteLine(
|
||||
$"chirplet-self-test frames={decode.Frames.Count} symbols={decode.Symbols.Count} anchors={decode.Anchors.Count} " +
|
||||
$"clock={(decode.ClockFit is null ? "none" : decode.ClockFit.EffectiveSampleRate.ToString("0.000000"))} " +
|
||||
$"confidence={(decode.ClockFit?.Confidence ?? 0.0):0.000} mae={meanAbsoluteError:0.000000}");
|
||||
|
||||
foreach (var anchor in decode.Anchors)
|
||||
{
|
||||
var expected = timeline.EventForIndex(anchor.EventIndex).StartSeconds * MimirChirpletTimeline.SampleRate;
|
||||
Console.WriteLine(
|
||||
$"chirplet-anchor event={anchor.EventIndex} actual={anchor.SampleOffset:0.000} expected={expected:0.000} " +
|
||||
$"error={anchor.SampleOffset - expected:0.000} confidence={anchor.Confidence:0.000}");
|
||||
}
|
||||
|
||||
if (decode.ClockFit == null || decode.Anchors.Count < 12 || meanAbsoluteError > 0.25)
|
||||
{
|
||||
Console.Error.WriteLine("chirplet self-test failed: canonical timeline did not decode to sub-frame anchors");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal sealed class DisposableConfiguration : IDisposable
|
||||
{
|
||||
private readonly List<IMimirStreamSource> ownedSources;
|
||||
|
|
|
|||
Loading…
Reference in a new issue