Add residual input mode for error envelope spectrum#90
Merged
Arcadia-1 merged 1 commit intoJul 8, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the
errevspecparity fixture by making the input contract explicit for error-envelope spectrum analysis.The core Python high-level API was not the underlying problem:
analyze_error_envelope_spectrum(signal)is a valid convenience path that accepts a raw signal, fits/subtracts a sine, then analyzes the residual envelope.The compare fixture was the mismatch. MATLAB
run_errevspec.mdoes:So MATLAB
errevspecreceives a precomputed residual. The previous Python integration also computederr_data, but then passed that residual intoplot_envelope_spectrum(err_data), whose default path treated the residual as a raw signal and fit/subtracted another sine. That made the Python comparison analyze a residual-of-residual envelope rather than the residual envelope MATLAB analyzes.Changes
input_kindtoanalyze_error_envelope_spectrum:input_kind="signal"keeps the existing default behavior.input_kind="error"treats the input as a precomputed residual and skips sine fitting.plot_envelope_spectrumintegration for MATLAB parity to callinput_kind="error".test_compare_err_envelope_spectrumwith a local1e-4threshold for the remaining residual-generation difference between Pythonfit_sine_4paramand MATLABsinfit.run_errevspecreference CSVs from the current MATLAB implementation. The oldNFreference was stale relative to currentplotspecnoise-floor semantics.fit_sine_4param, signal-input mode still does, and invalidinput_kindis rejected.Experiment
Dataset:
reference_dataset/sinewave_noise_200uV.csvMATLAB current reference path:
read_data -> sinfit -> err_data -> errevspec(err_data, 'Fs', 1)0.450591600162input_kind="error"4.64013392865e-05Selected per-metric diffs after the fix:
-4.23774012541-4.237747687547.5621e-06-23.7511955550-23.75124107904.5524e-050.3230674105820.3230420056982.5405e-05-23.0219513983-23.02199779974.6401e-05-1.69939776031-1.69938018073-1.7580e-05-32.2253391830-32.22535405161.4869e-05-9.20338778469-9.20335625197-3.1533e-05The remaining small deltas are from the independently generated residuals (
fit_sine_4paramvs MATLABsinfit), not from the envelope-spectrum input contract.Reference refresh note: current MATLAB regenerated
NF=-9.20335625197; the previous committed reference hadNF=+9.33090873637, which does not match currentplotspecnoise-floor semantics.Tests
uv run --with pytest pytest tests/unit/aout/test_analyze_error_envelope_spectrum.py -quv run --with pytest pytest tests/integration/test_err_envelope_spectrum.py -q --artifact-root E:/.tmp_artifacts/error-envelope-input-kinduv run --with pytest pytest tests/compare/test_compare_err_envelope_spectrum.py -q --comparison-output-root E:/.tmp_artifacts/error-envelope-input-kind/test_outputuv run --with pytest pytest tests/unit/test_skill_cli.py -quv run --with pytest pytest tests/integration/test_user_guide_skill_examples.py -qAlso ran MATLAB to regenerate the
run_errevspecreference from current code: