Robust LOWESS target curve with intentional exposure offsets removed, blended by Tukey weight and surviving-window fraction; flicker spectrum from the autocorrelation of detrended luminance recommends a window of four periods. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using System.Globalization;
|
|
using Titano.Core.Analysis;
|
|
using Titano.Core.Diagnostics.Synthetic;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.Core.Tests.Analysis;
|
|
|
|
public sealed class FlickerSpectrumTests(TestContext context)
|
|
{
|
|
[Theory]
|
|
[Case(12.0)]
|
|
[Case(7.5)]
|
|
[Case(20.0)]
|
|
public void RecoversAKnownPeriodFromRenderedFrames(double period)
|
|
{
|
|
var sequence = SyntheticSequence.Create(new SyntheticSequenceOptions
|
|
{
|
|
Width = 48,
|
|
Height = 32,
|
|
FrameCount = 240,
|
|
Seed = 12,
|
|
StartEv = 0,
|
|
EndEv = -2,
|
|
FlickerEv = 0.1,
|
|
FlickerPeriodFrames = period,
|
|
LandFlickerEv = 0.02,
|
|
});
|
|
var measured = AnalysisFixtures.MeasureSeries(sequence);
|
|
var result = FlickerSpectrum.Analyze(measured);
|
|
context.Log(string.Create(CultureInfo.InvariantCulture,
|
|
$"true period {period}, found {result.DominantPeriod:F3} (r = {result.PeakCorrelation:F3}), window {result.RecommendedWindow}"));
|
|
var found = Assert.NotNull(result.DominantPeriod);
|
|
Assert.Approximately(period, found, 0.5);
|
|
Assert.Equal(1, result.RecommendedWindow % 2);
|
|
Assert.InRange(result.RecommendedWindow, 4 * period - 1, 4 * period + 2);
|
|
}
|
|
|
|
[Test]
|
|
public void WhiteFlickerHasNoPeriodAndGetsTheMinimumWindow()
|
|
{
|
|
var random = new Random(2);
|
|
var series = Enumerable.Range(0, 300).Select(i => -0.01 * i + 0.1 * (2 * random.NextDouble() - 1)).ToArray();
|
|
var result = FlickerSpectrum.Analyze(series);
|
|
Assert.Null(result.DominantPeriod);
|
|
Assert.Less(result.CorrelationLength, 1.5);
|
|
Assert.Equal(FlickerSpectrumOptions.Default.MinimumWindow, result.RecommendedWindow);
|
|
}
|
|
|
|
[Test]
|
|
public void SlowCorrelatedFlickerWidensTheWindow()
|
|
{
|
|
// AR(1) flicker with correlation 0.9 per frame: e-folding length about 9.5 frames.
|
|
var random = new Random(4);
|
|
var series = new double[400];
|
|
var state = 0.0;
|
|
for (var i = 0; i < series.Length; i++)
|
|
{
|
|
state = 0.9 * state + 0.05 * (2 * random.NextDouble() - 1);
|
|
series[i] = state;
|
|
}
|
|
var result = FlickerSpectrum.Analyze(series);
|
|
Assert.InRange(result.CorrelationLength, 4, 15);
|
|
Assert.Greater(result.RecommendedWindow, 15);
|
|
Assert.Equal(1, result.RecommendedWindow % 2);
|
|
}
|
|
}
|