PlantLeaf — click detection algorithm v6
Four-stage cascade · 200 kHz ultrasonic stream → confirmed plant clicks
Adaptive noise estimator
W = 750 frames ≈ 1.92 s · gated on silence
B1 · FFT energy
min-statistics · M = 10 × 75
Ê_floor = β · median(mⱼ) · β = 1.3
B2 · Hilbert envelope
noise_floor · std_noise
LEVEL = noise_floor + std_noise
B3 · per-bin PSD
rolling mean · 154 bins
min-statistics measures 82× low per bin
Burst gate α = 4
Eᵢ > α · Ê_floor → no buffer updates
a candidate cannot pollute its own floor
→ Ê_floor (Stage 1)
→ noise_floor · std_noise (Stage 3)
→ P_noise[k] (excess spectrum, Stage 3)
What changed from v5
Removed: run-length filter (MAX_RUN = 3) — it dropped 45–53 % of above-threshold frames in stimulus recordings and 0 % in the empty room.

Removed: the decay-fit rejection — it cost 12.2 % of clicks before the classifier ever saw them.

Added: local_crest, per-bin noise PSD, the excess-spectrum family, and hard-negative mining switched off.
Raw FFT frame
154 bins · 20–80 kHz · 390.625 FPS · magnitudes + int8 phase
Microphone normalisation
50 % frequency-response correction · applied on both sides of every subtraction
Per-frame quantities
Eᵢ = (1/K)·Σ|A[k]|² · env_mean · env_std · P_frame[k] — computed every frame
Stage 1 — above floor?
Eᵢ > k · Ê_floor(i) · k = 1.5
Discard
below the adaptive floor
yes
Local maximum?
R = 1 frame · strict left, non-strict right
Not a peak
a louder neighbour owns this excursion
yes
Stage 1 candidate
exactly one per plateau · local_crest and k_ratio computed · +32 % candidate volume over v5
Stage 2 — hard gates
every threshold sits strictly outside the labelled click distribution
peak_SNR ≥ 4.5
76.8 % noise cut
n_seg ≥ 10
45.2 % noise cut
local_crest ≥ 1.2
33.6 % noise cut
harm_conf ≤ 1.6
3.2 % indoor
SPR < 100 · peak_SNR ≤ 10⁴ — out-of-distribution bounds, not discriminators: they reject values that cannot be measurements
All gates combined — 0.0 % of clicks lost · 83.6 % of noise removed · class balance 1 : 30 → 1 : 4.7
Stage 3 — reconstruction, features, classification
Reconstruction
zero-pad → Tukey taper on the complex spectrum → iFFT, 512 samples → Gibbs suppression → Hilbert envelope
Stitched click context
[ prev | curr | next ], ≤ 1536 samples · onset → re-maximise → peak_abs, a frame-grid-independent event identity
Envelope & iFFT
peak/pre/post_SNR · rise · fall · asymmetry · kurtosis · ZCR · temporal_concentration
Decay fit — demoted
log-linear OLS → fit_valid · R2 · tau_ms · coverage. Now features, no longer a gate.
Excess spectrum
E[m] = max(0, P_region − P_noise) · 12 bands × 5 kHz · entropy · tilt · novelty · f_50
~26 quantities computed · 57 CSV columns exported · 7 read by the deployed model
SimpleImputer(median) → PowerTransformer(yeo-johnson) → SVC(rbf)
C = 50 · γ = 0.01 · class_weight balanced · 7 features: peak_SNR, pre_SNR, post_SNR, rise_time_ms, fall_time_ms, fit_valid, R2
Click?
Discard
scored, below threshold
yes
Stage 4 — deduplication by peak_abs
Δpeak_abs ≤ 8 samples (≈ 40 µs jitter) · keep the canonical frame, then highest p
Duplicate
same acoustic event
Confirmed click event
timestamp · peak_abs · svm_probability · τ · R² · full 57-column row, SCHEMA_VERSION = v6
Training protocol & results
Corpus
402 861 exported rows
32 recordings exhaustively labelled
189 clicks · 99 ambiguous · 5 786 noise
Set A — training
905 rows · 158 clicks · 28 sessions
the Stage 2 survivor set itself
hard-negative mining off
Set B — held out
231 rows · 31 clicks · 2 sessions
one Aloe, one cactus
held out across species
0.929
CV AUC-ROC
0.905
CV recall @ 0.121
0.958
Set B AUC
0.0 %
clicks lost to Stage 2
Precision at the operating threshold (0.505 CV) is the deliberate cost of the recall target, not a defect: one lost click is a large fraction of the evidence in an experiment with a few dozen real events. Feature importance is always reported on both Set A and Set B permutation — in the v5 control run, the top training feature fell to rank 16 of 17 held out.
Legend
Signal & flow step
Pre-processing
Noise estimator / features
Gate / classifier
Discarded
Caveat / measured limit
Confirmed / output
Grouped sub-system
v5: adaptive floor · run-length filter · decay-fit gate · 17 features · RBF-SVM on hard-negative-mined data · threshold 0.220
v6: local peak picking at R = 1 · per-bin noise PSD · excess spectrum · gates measured against labels · 7 features · threshold 0.1207 · recall 0.905