From 1bc88be12da09cf7c4618d133bfe29dc98132ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=B6necke?= Date: Tue, 30 Jun 2026 09:07:35 +0200 Subject: [PATCH] Fix lower amplitude bound: use nearest-edge distance, not nearest vertex --- fourier/transform/transform.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fourier/transform/transform.py b/fourier/transform/transform.py index 9d0fb6e..b18ecd8 100644 --- a/fourier/transform/transform.py +++ b/fourier/transform/transform.py @@ -128,9 +128,21 @@ def in_complex_hull(chull,point=(0,0)): # default check the origin of the comple if in_complex_hull(convhull): boundC = Interval(0,abs(convhull[ch_max])) else: - boundC = Interval(abs(convhull[ch_min]),abs(convhull[ch_max])) + boundC = Interval(dist_origin_to_hull(convhull),abs(convhull[ch_max])) return boundI, boundC, (convhull[ch_min], convhull[ch_max]) +def dist_origin_to_hull(chull): # min |z| over the hull = distance to the nearest edge, not the nearest vertex + pts = [(c.real, c.imag) for c in chull] + dmin = float('inf') + for i in range(len(pts)): + ax,ay = pts[i]; bx,by = pts[(i+1) % len(pts)] + dx,dy = bx-ax, by-ay + denom = dx*dx + dy*dy + t = 0.0 if denom == 0 else min(1.0, max(0.0, -(ax*dx + ay*dy) / denom)) + px,py = ax + t*dx, ay + t*dy + dmin = min(dmin, (px*px + py*py)**0.5) + return dmin + def compute_amplitude_bounds(intervalsignal): N = len(intervalsignal) BOUNDS_I = []