-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFRD_merge.py
75 lines (52 loc) · 1.61 KB
/
FRD_merge.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""
Merge two .frd files 'frd_LOW' , 'frd_HIGH'
Takes LOW magnitudes below 'freq', and HIGH magnitudes above.
Usage:
FRD_merge.py path/to/frd_LO path/to/frd_HI scale_LO scale_HI freq
(scales in dB)
You can try
FRD_tool.py frd_LOW frd_HIGH -auto
as a start point to estimate scales and merging frequency.
"""
# v0.1
import sys
import tools
import numpy as np
if __name__ == '__main__':
try:
fnameLO = sys.argv[1]
fnameHI = sys.argv[2]
cLO, fsLO = tools.readFRD(fnameLO)
cHI, fsHI = tools.readFRD(fnameHI)
except:
print(__doc__)
print( 'Error in path/to/frds' )
sys.exit()
# Ensure that frequency bands are identical
if np.sum(cLO[:,0] - cHI[:,0]) != 0:
print( 'Error: frds bands differs' )
sys.exit()
try:
sLO = float(sys.argv[3])
sHI = float(sys.argv[4])
except:
print(__doc__)
print( 'Error parsing scale_LO and scale_HI (mandatories)' )
sys.exit()
try:
f = float(sys.argv[5])
if f < 20.0 or f > 20e3:
raise
except:
print(__doc__)
print( 'Error freq must be in 20....20000 Hz' )
sys.exit()
# Scale curves with the given dBs, then it is expected
# both to have the same magnitude at the provided 'freq'
cLO = cLO + [0, sLO]
cHI = cHI + [0, sHI]
# Merged mag takes from curveLOW until reached 'freq' then takes from curveHIGH
freq = cLO[:,0]
mag = np.where( freq < f, cLO[:,1], cHI[:,1] )
tools.saveFRD( 'merged.frd', freq, mag )