fix: look in a win for ssf rise; cosmetics

This commit is contained in:
2026-04-28 10:10:52 +02:00
parent e506a3e580
commit d10187878d
3 changed files with 19 additions and 11 deletions

6
sqi.py
View File

@@ -28,14 +28,14 @@ class SigQuality:
def __init__(self): pass
def get_snr(self, fs, ssf, ssf_threshold, ssf_zxings):
def get_snr(self, fs, ssf, ssf_threshold, est_zxings):
"""Compute the Signal-to-Noise Ratio of beats, based on SSF function and detected beat locations."""
sigma = fs * self.gauss_beat_template_sigma_sec
W = int(fs * self.gauss_beat_template_win_sec)
gb = gauss(W, W//2, sigma)
# place gaussians on estimated beat locations
ssf_est = np.zeros(ssf.shape[0])
for i in ssf_zxings:
for i in est_zxings:
ssf_est += shift(ssf.shape[0], i, gb)
ssf_est /= gb[W//2] # normalize amplitude to 1.0
ssf_est = np.roll(ssf_est, int(sigma)) # shift to right (beat loc = gauss beginning, not center)
@@ -49,7 +49,7 @@ class SigQuality:
sqi_noise = np.sum(sqi_pen * (ssf**2))
# noise is everywhere, while signal is only around detected peaks - correct for this.
goal_density = np.mean(np.clip(2*sigma / np.diff(ssf_zxings), a_min=0, a_max=1))
goal_density = np.mean(np.clip(2*sigma / np.diff(est_zxings), a_min=0, a_max=1))
sqi_goal /= goal_density
sqi = 10 * (np.log10(sqi_goal) - np.log10(sqi_noise))