From 4756013c1736adcce1145a9a7345621b2dd44bfd Mon Sep 17 00:00:00 2001 From: CroneKorkN Date: Fri, 30 May 2025 19:18:22 +0200 Subject: [PATCH] wip --- process_chunks.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/process_chunks.py b/process_chunks.py index 26c8a9b..ab431cb 100755 --- a/process_chunks.py +++ b/process_chunks.py @@ -22,17 +22,6 @@ OVERTONE_FREQ = TARGET_FREQ * 2 NFFT = 32768 SKIP_SECONDS = 10 -def detect_event(chunk): - freqs, times, Sxx = scipy.signal.spectrogram(chunk, samplerate, nperseg=NFFT) - idx_base = np.where((freqs >= TARGET_FREQ - TOLERANCE) & (freqs <= TARGET_FREQ + TOLERANCE))[0] - idx_oct = np.where((freqs >= OVERTONE_FREQ - OVERTONE_TOLERANCE) & (freqs <= OVERTONE_FREQ + OVERTONE_TOLERANCE))[0] - if len(idx_base) == 0 or len(idx_oct) == 0: - return False - base_energy = np.mean(Sxx[idx_base]) - oct_energy = np.mean(Sxx[idx_oct]) - total_energy = np.mean(Sxx, axis=0).max() - return base_energy > THRESHOLD_BASE * total_energy and oct_energy > THRESHOLD_OCT * total_energy - def process_chunk(filename): input_path = os.path.join(OUTDIR, filename) print(f"🔍 Verarbeite {input_path}...") @@ -47,6 +36,17 @@ def process_chunk(filename): padding_before = int(CLIP_PADDING_BEFORE * samplerate) padding_after = int(CLIP_PADDING_AFTER * samplerate) + def detect_event(chunk): + freqs, times, Sxx = scipy.signal.spectrogram(chunk, samplerate, nperseg=NFFT) + idx_base = np.where((freqs >= TARGET_FREQ - TOLERANCE) & (freqs <= TARGET_FREQ + TOLERANCE))[0] + idx_oct = np.where((freqs >= OVERTONE_FREQ - OVERTONE_TOLERANCE) & (freqs <= OVERTONE_FREQ + OVERTONE_TOLERANCE))[0] + if len(idx_base) == 0 or len(idx_oct) == 0: + return False + base_energy = np.mean(Sxx[idx_base]) + oct_energy = np.mean(Sxx[idx_oct]) + total_energy = np.mean(Sxx, axis=0).max() + return base_energy > THRESHOLD_BASE * total_energy and oct_energy > THRESHOLD_OCT * total_energy + i = 0 last_event = -skip_samples while i + chunk_samples <= len(data):