wip
This commit is contained in:
parent
7a7059f5c7
commit
fc15d794a6
1 changed files with 13 additions and 9 deletions
22
process
22
process
|
@ -41,7 +41,10 @@ def process_recording(filename):
|
||||||
current_event = None
|
current_event = None
|
||||||
|
|
||||||
# read blocks of audio data with overlap from sound variable
|
# read blocks of audio data with overlap from sound variable
|
||||||
for block_num, block in enumerate(soundfile.blocks(path, blocksize=samples_per_block, overlap=overlapping_samples)):
|
block_num = 0
|
||||||
|
for block in soundfile.blocks(path, blocksize=samples_per_block, overlap=overlapping_samples):
|
||||||
|
block_num += 1
|
||||||
|
|
||||||
# get block date and calculate FFT
|
# get block date and calculate FFT
|
||||||
block_date = recording_date + datetime.timedelta(seconds=block_num * (samples_per_block - overlapping_samples) / samplerate)
|
block_date = recording_date + datetime.timedelta(seconds=block_num * (samples_per_block - overlapping_samples) / samplerate)
|
||||||
labels = rfftfreq(len(block), d=1/samplerate)
|
labels = rfftfreq(len(block), d=1/samplerate)
|
||||||
|
@ -49,15 +52,16 @@ def process_recording(filename):
|
||||||
amplitudes = np.abs(complex_amplitudes)
|
amplitudes = np.abs(complex_amplitudes)
|
||||||
|
|
||||||
# get amplitudes only between 100 and 1000 Hz
|
# get amplitudes only between 100 and 1000 Hz
|
||||||
adjacent_amplitudes = amplitudes[(labels >= DETECT_FREQUENCY_FROM/ADJACENCY_FACTOR) & (labels <= DETECT_FREQUENCY_TO*ADJACENCY_FACTOR)]
|
search_amplitudes = amplitudes[(labels >= DETECT_FREQUENCY_FROM/ADJACENCY_FACTOR) & (labels <= DETECT_FREQUENCY_TO*ADJACENCY_FACTOR)]
|
||||||
adjacent_labels = labels[(labels >= DETECT_FREQUENCY_FROM/ADJACENCY_FACTOR) & (labels <= DETECT_FREQUENCY_TO*ADJACENCY_FACTOR)]
|
search_labels = labels[(labels >= DETECT_FREQUENCY_FROM/ADJACENCY_FACTOR) & (labels <= DETECT_FREQUENCY_TO*ADJACENCY_FACTOR)]
|
||||||
|
|
||||||
# get the frequency with the highest amplitude
|
# get the frequency with the highest amplitude
|
||||||
max_amplitude = max(adjacent_amplitudes)
|
max_amplitude = max(search_amplitudes)
|
||||||
max_amplitude_index = np.argmax(adjacent_amplitudes)
|
max_amplitude_index = np.argmax(search_amplitudes)
|
||||||
max_freq = adjacent_labels[max_amplitude_index]
|
max_freq = search_labels[max_amplitude_index]
|
||||||
|
|
||||||
# get the average amplitude of the adjacent frequencies
|
# get the average amplitude of the search frequencies
|
||||||
|
adjacent_amplitudes = search_amplitudes[(search_labels < DETECT_FREQUENCY_FROM) | (search_labels > DETECT_FREQUENCY_TO)]
|
||||||
noise = np.mean(adjacent_amplitudes)/max_amplitude
|
noise = np.mean(adjacent_amplitudes)/max_amplitude
|
||||||
|
|
||||||
# check for detection criteria
|
# check for detection criteria
|
||||||
|
@ -97,7 +101,7 @@ def process_recording(filename):
|
||||||
write_plot()
|
write_plot()
|
||||||
|
|
||||||
current_event = None
|
current_event = None
|
||||||
block_num += DETECTION_DISTANCE // BLOCK_SECONDS
|
block_num += (DETECTION_DISTANCE // BLOCK_SECONDS) * samples_per_block
|
||||||
|
|
||||||
block_num += 1
|
block_num += 1
|
||||||
|
|
||||||
|
@ -114,7 +118,7 @@ def main():
|
||||||
os.makedirs(RECORDINGS_DIR, exist_ok=True)
|
os.makedirs(RECORDINGS_DIR, exist_ok=True)
|
||||||
os.makedirs(PROCESSED_RECORDINGS_DIR, exist_ok=True)
|
os.makedirs(PROCESSED_RECORDINGS_DIR, exist_ok=True)
|
||||||
|
|
||||||
for filename in os.listdir(RECORDINGS_DIR):
|
for filename in sorted(os.listdir(RECORDINGS_DIR)):
|
||||||
if filename.endswith(".flac"):
|
if filename.endswith(".flac"):
|
||||||
process_recording(filename)
|
process_recording(filename)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue