Repository navigation
fix: match PIDtoolbox step response with scaled regularization and no smoothing - #241
Conversation
…time axis) Both moving-average smoothers (initial gyro, post-average curve) used a trailing window, delaying the trace and Td by (window-1)/2 samples each. Make them centered (zero-phase) with shortened edge windows. The start-at-zero shift now uses the raw first sample of the average. Build response_time as i / sample_rate instead of linspace(0, 0.5, N), which stretched the axis by up to 1 sample over the response. Document the rule in OVERVIEW.md and AGENTS.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoqKWyH8bEnezDzEVxkNPQ
response_time used linspace(0, RESPONSE_LENGTH_S, N) with N = ceil(RESPONSE_LENGTH_S * sample_rate), so the spacing was RESPONSE_LENGTH_S / (N - 1) instead of 1 / sample_rate. The plotted trace stretched by up to one sample over the response (0.02 ms at 50 ms for 1878 Hz, 0.7 ms at 500 ms for 1422 Hz). Sample i is now at i / sample_rate, matching PIDtoolbox (t = 0 : 1/lograte). Revert the centered smoothing, which changed the default step-response output and is not part of this fix. Document the axis in OVERVIEW.md and add a unit test of the axis. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoqKWyH8bEnezDzEVxkNPQ
Run the step-response time-axis test at 1000 Hz and 1001 Hz. At 1001 Hz RESPONSE_LENGTH_S * sample_rate is 500.5, so the response length rounds up and the last sample time is not a round number. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoqKWyH8bEnezDzEVxkNPQ
The test needs at least one window to pass QC, not every window. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoqKWyH8bEnezDzEVxkNPQ
… smoothing wiener_deconvolution_window divided by |H|^2 + 1e-4 on raw FFTs. PIDtoolbox scales both spectra by 1/N first, so its term acts as 1e-4 * N^2. The unscaled term was negligible, giving a noisy estimate and a Td about 5 ms too fast. Scale both spectra by 1/padded_n and move the term to WIENER_REGULARIZATION. Remove the two trailing 15-sample moving averages (gyro before deconvolution, and the averaged curve). They delayed the trace by about 7 ms each and produced a slow start before the rise. PIDtoolbox applies neither by default. Floor the step response plot y-axis at 0 when no trace is negative, so the plot origin is (0, 0). Add tests from the plant definition: identity plant (unit step, no delay) and first-order lag (50% point from the closed-form step response). Update OVERVIEW.md for regularization, smoothing, time axis and the PIDtoolbox sample-rate rounding. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoqKWyH8bEnezDzEVxkNPQ
# Conflicts: # OVERVIEW.md # src/data_analysis/calc_step_response.rs
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
@coderabbitai — AI generated comment Analysis requested on PR 241, three points:
|
|
Tip For best results, initiate chat on the files or code changes. Analysis chain
1. FFT scalingYes. In The inverse normalization is also correct. 2. Smoothing referencesI found no remaining references to either removed smoothing function or constant. There are stale labels and comments in
The peak is now taken from the unsmoothed, shifted and normalized response. These labels and comments should be updated. 3. Plant testsBoth tests derive their timing expectations from the plant definitions. The identity test expects an immediate crossing; the lag test uses Both tests can pass with the old unscaled regularization. An independent NumPy model of the fixtures, with smoothing still removed, gave:
I did not run the Rust tests. The model supports the conclusion, but the exact Rust results remain to be verified. A direct regression test could call Additional coverage gap: The tests stop before the plot’s final processing. In You are interacting with an AI system. |
Scale the deconvolution spectra by 1/n (window length) instead of the power-of-two padded length. Padding can double between nearby sample rates, so the padded length made the regularization jump up to 4x between rates. With n the term is 1e-4 * n^2 on unscaled FFTs, as in PIDtoolbox, and varies continuously with the rate. The step response legend said "Smoothed Peak" after the smoothers were removed. Use "Peak". Add a regularization test from the definition: a unit impulse as input and output gives 1 / (1 + r n^2) at sample 0. Update OVERVIEW.md and the constant comment. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoqKWyH8bEnezDzEVxkNPQ
|
@coderabbitai — AI generated comment Dispositions for the analysis reply and local findings on head 8fc25f2:
Analysis requested on head 95372de: any remaining issue? |
|
Tip For best results, initiate chat on the files or code changes. Analysis chain
Remaining validation: The PR description notes that Optimal P thresholds need recalibration and that peak-based P:D recommendations have not been fully re-verified. I recommend checking those outputs on representative logs for this head before relying on them. GitHub’s Test and Lint check passed. The release builds were still in progress at my last check. If the existing follow-up does not cover final plot-processing tests, would you like a separate issue for that coverage? Learnings added
Learnings used
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
|
@coderabbitai review |
Action performed
|
AI Generated pull-request
Summary
Step response differed from PIDtoolbox in two ways. Both moved Td by several ms and changed the curve shape.
wiener_deconvolution_windowused|H|^2 + 1e-4on raw FFTs. PIDtoolbox divides both spectra by their length first (PTstepcalc.m), so its term acts as1e-4 * N^2. The unscaled term was negligible: noisy estimate, Td about 5 ms too fast. Both spectra are now scaled by1/n(window length); the term isWIENER_REGULARIZATION.Also: y-axis floor is 0 when no trace is negative, so the plot origin is (0, 0). Tests from the plant definition (identity plant, first-order lag).
OVERVIEW.mdupdated, including PIDtoolbox rounding its sample rate to 0.1 kHz (axis about 1% compressed on a 1.88 kHz log).Effect on outputs (two EmuFlight logs, 1878 Hz)
Test plan
cargo clippy --all-targets --all-features -- -D warnings,cargo fmt --all,cargo test🤖 Generated with Claude Code
https://claude.ai/code/session_01KoqKWyH8bEnezDzEVxkNPQ
Summary by CodeRabbit