Skip to main content

split_hill_persistence

Function split_hill_persistence 

Source
pub fn split_hill_persistence(
    hill: &Hill,
    height_frac: f64,
    valley_ratio: f64,
    sigma_mult: f64,
    min_scans: usize,
) -> Vec<Hill>
Expand description

Split a hill containing multiple co-eluting peaks (the “persistence” algorithm). Designed to be robust to noisy scans while separating visually-obvious dual peaks.

  1. Despike (median-3) and smooth (moving average) a WORKING COPY — all peak finding runs on this; sub-hill intensities still come from the raw trace.
  2. Candidate maxima above height_frac * robust_max (95th-percentile max, so a single noise spike can’t inflate the threshold). No hard min-distance eviction — close real peaks survive.
  3. Agglomeratively merge adjacent peaks unless the valley between them is BOTH relatively deep (valley / smaller_peak <= valley_ratio) AND absolutely deep (smaller_peak - valley >= sigma_mult * noise_sigma).
  4. Width gate: drop surviving 1–2 scan spikes median-3 couldn’t remove.
  5. Split at the (smoothed) valley between adjacent survivors.