-
Notifications
You must be signed in to change notification settings - Fork 1
/
thd_analyzer.py
50 lines (38 loc) · 1.28 KB
/
thd_analyzer.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
from common import analyze_function
#from waveform_analysis.thd import THDN, THD
from thd import THDN, THD
def thd_analyzer(files):
import sys
if files:
for filename in files:
try:
analyze_function(filename, THDN)
except IOError:
print('Couldn\'t analyze "' + filename + '"\n')
print('')
else:
sys.exit("You must provide at least one file to analyze:\n"
"python wave_analyzer.py filename.wav")
'''
if __name__ == '__main__':
try:
if files:
for filename in files:
try:
analyze_channels(filename, THDN)
except IOError:
print('Couldn\'t analyze "' + filename + '"\n')
print('')
else:
sys.exit("You must provide at least one file to analyze")
except BaseException as e:
print('Error:')
print(e)
raise
finally:
# Otherwise Windows closes the window too quickly to read
input('(Press <Enter> to close)')
print('Frequency: %f Hz' % (fs * (true_i / len(windowed))))
print("THD+N: %.4f%% or %.1f dB" % (THDN * 100, 20 * log10(THDN)))
print("A-weighted: %.4f%% or %.1f dB(A)" % (THDNA * 100, 20 * log10(THDNA)))
'''