Skip to content

Welch estimation pooled over multiple data segments in tfest and coherence - #211

Open
baggepinnen wants to merge 1 commit into
masterfrom
fb/welch-segments
Open

baggepinnen wants to merge 1 commit into
masterfrom
fb/welch-segments

Conversation

@baggepinnen

Copy link
Copy Markdown
Member

Summary

tfest(d; method = :welch) and coherence(d) return H, the noise spectrum and κ², but not the Welch sums. Pooling Welch estimates over several data segments (for example repeated experiments, or disjoint parts of one experiment in which every window must lie within one part) therefore required recovering the sums algebraically from the returned quantities or calling the internal wcfft.

This PR adds Welch estimation pooled over a vector of data segments of possibly different lengths:

  • tfest(ds::AbstractVector{<:AbstractIdData}; n = minimum(length, ds) ÷ 10, noverlap = n ÷ 2, window = hamming) returns H, N.
  • coherence(ds::AbstractVector{<:AbstractIdData}; n, noverlap, window) returns κ².
  • wcfft(ys::AbstractVector{<:AbstractVector}, us::AbstractVector{<:AbstractVector}; n, noverlap, window) accumulates the cross- and auto-spectral sums over the windows of all segments; the existing wcfft(y, u) forwards to it.

The sums are accumulated over all windows of all segments before H, N and κ² are formed, so the result equals the Welch estimate over the union of the windows, not an average of per-segment estimates. Every window lies within one segment; a segment shorter than n contributes no window. N is normalized by the total number of samples of the contributing segments. Only method = :welch is supported for vectors (other methods throw an ArgumentError); multiple outputs are handled output by output in tfest, as for a single dataset. The API follows the existing vector-of-datasets methods arx(ds::AbstractVector{<:AbstractIdData}, ...) and era(ds::AbstractVector{<:AbstractIdData}, ...). As a consequence, tfest(ds, G0::LTISystem) now also accepts a vector of segments.

Tests (test/test_frd.jl)

  • A single segment gives the same result as tfest(d; method = :welch) and coherence(d), with explicit and default window lengths.
  • Several segments of different lengths (one shorter than the window) give the result of manually summing the per-segment wcfft sums.
  • A known transfer function is recovered from 20 noisy segments of random lengths (relative error below 5 % in the band of high coherence).
  • Multiple-output data, and the error cases (unsupported method, different sample times, no segment as long as the window).

test/test_frd.jl passes locally (76 tests).

Documentation

Docstrings for the new methods and for wcfft, cross-references from the single-dataset docstrings, and a subsection "Multiple data segments" in docs/src/freq.md.


Host: battomenstation, session ceeed800-f3a6-49ab-a067-a9619908b6cb, working directory /tmp/claude-1000/-home-fredrikb-repos-QBotControl-Qbot/ceeed800-f3a6-49ab-a067-a9619908b6cb/scratchpad/CSI

🤖 Generated with Claude Code

https://claude.ai/code/session_01JGy8YaVQubQ5iZpmGTGTfG

tfest and coherence accept a vector of iddata segments of possibly
different lengths. The cross- and auto-spectral sums are accumulated over
the Welch windows of all segments, each window lying within a single
segment, before the transfer function, noise spectrum and coherence are
formed. wcfft accepts vectors of signal segments for this purpose.

Assisted-by: Claude-Code:claude-opus-5-5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant