Skip to content

Step 3 ‐ Find Best Offset

HRAshton edited this page Oct 18, 2025 · 1 revision

Consolidate multiple candidate offsets into a single robust result.
Given many noisy candidate intervals from correlation, this step selects one representative Interval(start, end) by clustering and robust statistics.

Input

  • Candidate Intervals
    • A list of intervals from Step 2 for the same comparison scope.
    • Each item provides start and end offsets in seconds for each signal (audio file). Some values may be NaN.
  • Configuration Parameters
    • precision_secs — resolution used to decide if values are already “close enough.”

Transformation

1. NaN handling

  • Remove NaN entries from start and end lists independently.
  • If a list becomes empty, the result for that side is NaN.

2. Fast path for “already consistent” values

  • If all remaining values are within precision_secs / 2 of each other, return their common value (e.g., median).

3. KMeans-based consolidation

  • Otherwise, cluster the 1-D values using KMeans.
  • Determine cluster count k by maximizing the silhouette score over a small k-grid.
  • Select candidate clusters with the highest membership (most points).
  • If several clusters tie on size, pick the one with the smallest spread (range).

4. Robust representative per side

  • For the chosen cluster, return the median value.
  • Apply Steps 1-4 independently to start values and to end values.

5. Compose final interval

  • Combine the consolidated start and end into a single Interval(start, end).
  • If either side is NaN, the interval is considered invalid for subsequent stages.

Output

  • Best Interval
    • One Interval(start, end) that represents the dominant offset among candidates.
    • Designed to be stable under outliers and multi-modal candidate distributions.

Data Flow

flowchart TD
A[Candidate Intervals] --> B[NaN Filtering]
B --> C[Close-Values Fast Path]
C --> D[KMeans + Silhouette Selection]
D --> E[Median per Cluster]
E --> F[Compose Interval(start, end)]
Loading

Clone this wiki locally