-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_amplitudes_hearning_threshold.py
More file actions
63 lines (53 loc) · 2.14 KB
/
generate_amplitudes_hearning_threshold.py
File metadata and controls
63 lines (53 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pickle
import os
import numpy as np
from auditory_model.src.modules.gammatone_filterbank import GammatoneFilterbank
from auditory_model.src.runner import Config
from auditory_model.src.modules.preprocess import PreprocessLoadAudioLibrosa
from auditory_model.src.logs import LogLevel
from auditory_model.src.utils.helpers import center_frequencies_glasberg
# Prerequisites run plot_iso_standard.py before
wavelength = 4000
plot_channels = [2, 6, 7]
plot_channel = 7
center_freqs = center_frequencies_glasberg(20000, 20, 40)
extended_freqs = []
# If more than center freqs should be used
for i in range(len(center_freqs) - 1):
start = center_freqs[i]
end = center_freqs[i + 1]
freqs_between = np.linspace(start, end, 5)[:-1]
extended_freqs.extend(freqs_between)
extended_freqs.append(center_freqs[-1])
for phon in range(0, 91, 10):
max_amplitudes = []
with open(f"ohc_gain_fitting/pchip_phon_{phon}.pkl", "rb") as f:
pchip_db_thresholds = pickle.load(f)
print("Phon Level", phon)
for i in extended_freqs:
wavelength = int(i)
db_level = pchip_db_thresholds(wavelength)
config = Config(
run_name=f"Generate_amplitudes",
pure_tone_frequency=wavelength,
save_plots=False,
log_level=LogLevel.WARNINGS,
pipeline=[
PreprocessLoadAudioLibrosa(
take_only_first_x_ms=300, use_db_spl_scaling=True, db_level=db_level
),
GammatoneFilterbank(
output_path="basilar_membrane_oscillation.png",
plot_channels=plot_channels,
plot_time_window=((1 / wavelength) * 4),
),
],
)
max_amplitudes.append([wavelength, np.max(config.run())])
print(f"Final Result: phon {phon}")
print(max_amplitudes)
output_dir = "ohc_gain_fitting"
os.makedirs(output_dir, exist_ok=True)
output_path = os.path.join(output_dir, f"amplitudes_phon_{phon}.npy")
np.save(output_path, max_amplitudes)
print(f"Saved amplitudes to {output_path}")