forked from jaakkopasanen/AutoEq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
average.py
48 lines (41 loc) · 1.59 KB
/
average.py
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
# -*- coding: utf-8 -*-
import os
import re
from glob import glob
import numpy as np
from frequency_response import FrequencyResponse
DIR = 'innerfidelity/data/onear'
DIR = os.path.abspath(DIR)
OUT_DIR = os.path.join('innerfidelity/data/avg/onear')
def main():
models = {}
for file_path in glob(os.path.join(DIR, '*')):
model = os.path.split(file_path)[-1]
if not (re.search(' sample [a-zA-Z0-9]$', model, re.IGNORECASE) or re.search(' sn[a-zA-Z0-9]+$', model, re.IGNORECASE)):
# Skip measurements with sample or serial number, those have averaged results
continue
norm = re.sub(' sample [a-zA-Z0-9]$', '', model, 0, re.IGNORECASE)
norm = re.sub(' sn[a-zA-Z0-9]+$', '', norm, 0, re.IGNORECASE)
try:
models[norm].append(model)
except KeyError as err:
models[norm] = [model]
for norm, origs in models.items():
if len(origs) > 1:
print(norm, origs)
avg = np.zeros(613)
f = FrequencyResponse.generate_frequencies()
for model in origs:
fr = FrequencyResponse.read_from_csv(os.path.join(DIR, model, model + '.csv'))
fr.interpolate()
fr.center()
avg += fr.raw
avg /= len(origs)
fr = FrequencyResponse(name=norm, frequency=f, raw=avg)
d = os.path.join(OUT_DIR, norm)
if not os.path.isdir(d):
os.makedirs(d)
fr.write_to_csv(os.path.join(d, norm + '.csv'))
#fr.plot_graph()
if __name__ == '__main__':
main()