# Peak_Finding_Toolbox kind .......... project status ........ archived since 2025-05-07 · research prototype checked ....... 2026-10-20 stack ......... python · eeg · hrtf · signal processing source ........ https://github.com/bmontt/Peak_Finding_Toolbox page .......... https://brodymontag.com/projects/peak-finding-toolbox A Python toolbox that finds peaks in auditory signals: ABR waves I to V, impulse responses from SOFA files, and transients in audio. A research prototype from my PIRL work. I wrote the toolbox during auditory signal research at UMD's Perceptual Interfaces and Reality Laboratory. An auditory brainstem response (ABR) is a small signal from the scalp after a sound. Each of its five waves needs an exact peak mark. For ABR, the toolbox smooths the signal by its signal-to-noise ratio and looks for peaks in up to three passes. It scores I–III–V triplets against normal time windows, then finds waves II and IV between them. For SOFA and audio files it uses a prominence threshold that the SNR scales. I compared its Wave V picks with manual picks for 8 subjects (54 pairs). The median error was 1.15 ms, and 41% of the picks were within 0.5 ms. It is a prototype, not a clinical tool. Waves I to IV have no benchmark. It reads EEG through MNE-BIDS, SOFA files through h5py, and audio through soundfile. I stopped work on it in May 2025. ## highlights - ABR waves I to V, smoothed by the signal-to-noise ratio - Measured: Wave V median error 1.15 ms against manual picks (8 subjects) - Measured: 41% of Wave V picks within 0.5 ms - Impulse responses from SOFA files, and transients in audio - Loaders for MNE-BIDS, h5py and soundfile - A research prototype. Not clinically validated. ## detail updated 2026-10-20 ### how it works figure 1 · the picks for waves I to V · schematic trace, real windows A schematic ABR trace draws in and is smoothed. Candidate peaks appear, and triplets are tried against the normal interval ranges. The best I, III and V lock in, then II and IV. For an ABR, the toolbox first measures a signal-to-noise ratio (SNR). It compares the RMS from 0 to 10 ms after the click with the RMS in the 5 ms before it. A low SNR gives a wider Gaussian smoothing, up to 4 times the base width. Then the toolbox finds peaks between 0 and 15 ms, and drops those after 9.6 ms when at least three are left. Each set of three candidates is a possible I–III–V triplet. A triplet counts only if its intervals fall in normal ranges. These are 1.80 to 2.30 ms for I–III, 1.40 to 2.30 ms for III–V, and 3.76 to 4.70 ms for I–V. The best triplet is closest to 2, 2 and 4 ms, with double weight on I–V. Waves II and IV are the strongest peaks between their neighbors. figure 2 · from an average to five waves An averaged ABR gets an SNR and a smoothing width. Peaks from 0 to 15 ms go to the triplet test. A fit gives I, III and V. No fit gives a new pass, and after three passes the three most prominent peaks. II and IV come last. ```mermaid flowchart TD A[averaged ABR] --> B[SNR from signal and noise windows] B --> C[Gaussian smoothing, wider at low SNR] C --> D[peaks from 0 to 15 ms] D --> E{a triplet fits the windows?} E -->|yes| F[best I-III-V triplet] E -->|no, next pass| C E -->|no, after 3 passes| G[3 most prominent peaks] F --> H[II and IV between the anchors] G --> H ``` the triplet test and its score peak-finding@f82d762 · toolbox/peak_finder.py:131-149 ```python # score every I–III–V triplet best_score = np.inf for i, j, k in itertools.combinations(range(len(cands)), 3): tI, tIII, tV = T[cands[i]], T[cands[j]], T[cands[k]] d13, d35, d15 = tIII-tI, tV-tIII, tV-tI # enforce normative windows if not (IP_I_III[0] <= d13 <= IP_I_III[1] and IP_III_V[0] <= d35 <= IP_III_V[1] and IP_I_V[0] <= d15 <= IP_I_V[1]): continue # weighted deviation: weight I–V interval more score = abs(d13-2.0) + abs(d35-2.0) + 2*abs(d15-4.0) if score < best_score: best_score, best_tri = score, (cands[i], cands[j], cands[k]) if best_tri is not None: break ``` ### decisions decision: Anchor on the I–III–V triplet, not on single peaks (accepted, 2025-05-04) context: One ABR has many small peaks, and noise adds more. One peak alone can look like any of the five waves. decision: The finder tests every I–III–V triplet against the normal interval ranges and takes the best one. Waves II and IV come last, between their anchors. cost: For a recording with abnormal intervals, no triplet fits, and the finder falls back to the three most prominent peaks. It computes a QC flag for this, but the public function does not return the flag. decision: Smooth by the SNR, and try again (accepted, 2025-05-04) context: One fixed smoothing width blurs clean waves or leaves noise in poor recordings. decision: The smoothing width follows the SNR. When no triplet fits, the next pass smooths 20% more and lowers the prominence by 20%, for up to three passes. cost: A noisy recording can still give a triplet that fits by chance. Nothing checks the picks against the noise. each pass: a wider smoothing and a lower prominence peak-finding@f82d762 · toolbox/peak_finder.py:101-110 ```python # ——— 2) Candidate detection + smart triplet scoring ——— for attempt in range(3): # adaptive, SNR‐weighted smoothing snr = compute_snr_normalized(data_uv, T) sigma = base_sigma * (1 + 0.2*attempt) adj_sigma = np.clip(sigma/(snr+0.1), 0.3*sigma, 4*sigma) smooth = gaussian_filter1d(data_uv, sigma=adj_sigma) # local‑SNR‐based prominence prom = signal_std * (1 - 0.2*attempt) ``` ### results figure kind value Wave V pairs, automatic against manual measured 54, from 8 subjects median error measured 1.15 ms mean error measured 1.56 ms picks within 0.5 ms measured 41% picks within 1.0 ms measured 48% picks within 2.0 ms measured 74% mean signed difference, automatic minus manual measured +0.93 ms method: the two CSVs in bench/ at f82d762, compared row by row as generate_evaluation_metrics.py does. Rows with no manual pick are left out. The manual picks come from the repo's peak_annotator app. · as of 2025-05-07 ### limits limits: - Only Wave V has a benchmark. Waves I to IV have none. - The benchmark has 8 subjects, all with normal hearing. - The picks come late: on average 0.93 ms after the manual pick. - The SOFA and audio modes have no benchmark. - It is a research prototype, not a clinical tool. ### status and next status: - Done: the ABR, SOFA and audio modes, the tests, and the Wave V benchmark (2025-05-07). - Archived since 2025-05-07. No more work is planned. ### proof - the triplet scoring, peak_finder.py:131-149 at f82d762 - the automatic and manual Wave V picks (CSV) at f82d762 - the metrics script at f82d762 - source -- end of page · this page as text: https://brodymontag.com/machine/projects/peak-finding-toolbox · index: https://brodymontag.com/machine · summary: https://brodymontag.com/llms.txt