wip
This commit is contained in:
parent
008789755d
commit
0c4c5dda14
1 changed files with 9 additions and 8 deletions
17
process
17
process
|
@ -37,10 +37,10 @@ def process_recording(filename):
|
|||
samples_per_block = int(BLOCK_SECONDS * samplerate)
|
||||
overlapping_samples = int(samples_per_block * BLOCK_OVERLAP_FACTOR)
|
||||
|
||||
# get median amplitude for normalization
|
||||
# calculate a base amplitude for normalization
|
||||
complex_amplitudes_global = rfft(sound)
|
||||
median_amplitude = np.median(np.abs(complex_amplitudes_global))
|
||||
print(f'median amplitude: {median_amplitude:.5f}rDB')
|
||||
base_amplitude = np.mean(np.abs(complex_amplitudes_global))
|
||||
print(f'base amplitude: {base_amplitude:.5f}rDB')
|
||||
|
||||
# initialize to a very old date
|
||||
|
||||
|
@ -55,11 +55,11 @@ def process_recording(filename):
|
|||
block = sound[start_sample:end_sample]
|
||||
|
||||
# get block date and calculate FFT
|
||||
block_date = recording_date + datetime.timedelta(seconds=block_num * BLOCK_SECONDS)
|
||||
block_date = recording_date + datetime.timedelta(seconds=block_num * (samples_per_block - overlapping_samples) / samplerate)
|
||||
labels = rfftfreq(len(block), d=1/samplerate)
|
||||
complex_amplitudes = rfft(block)
|
||||
absolute_amplitudes = np.abs(complex_amplitudes)
|
||||
amplitudes = absolute_amplitudes / median_amplitude
|
||||
amplitudes = absolute_amplitudes / base_amplitude
|
||||
|
||||
# get amplitudes only between 100 and 1000 Hz
|
||||
adjacent_amplitudes = amplitudes[(labels >= DETECT_FREQUENCY_FROM/ADJACENCY_FACTOR) & (labels <= DETECT_FREQUENCY_TO*ADJACENCY_FACTOR)]
|
||||
|
@ -103,12 +103,13 @@ def process_recording(filename):
|
|||
else:
|
||||
# not detecting an event
|
||||
if current_event:
|
||||
# conclude current event
|
||||
print(f'🔊 {current_event["start_at"]}: {current_event["start_freq"]:.1f}Hz -> {current_event["end_freq"]:.1f}Hz @{current_event["max_amplitude"]:.0f}rDB')
|
||||
current_event = None
|
||||
duration = (current_event['end_at'] - current_event['start_at']).total_seconds()
|
||||
print(f'🔊 {current_event['start_at'].strftime('%Y-%m-%d %H:%M:%S')} ({duration:.1f}s): {current_event['start_freq']:.1f}Hz->{current_event['end_freq']:.1f}Hz @{current_event['max_amplitude']:.0f}rDB')
|
||||
|
||||
write_clip()
|
||||
write_plot()
|
||||
|
||||
current_event = None
|
||||
block_num += DETECTION_DISTANCE // BLOCK_SECONDS
|
||||
|
||||
block_num += 1
|
||||
|
|
Loading…
Reference in a new issue