-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaling.jl
42 lines (35 loc) · 1.26 KB
/
scaling.jl
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
# Compute the scaling factors for each measurement technique to ensure that
# analog signal is 99.9% below -1dBFS. Random gaussian noise is technically
# unbounded, so it's not useful to find a normalization level that will ensure
# we never clip, but we can at least find a reasonable level where any clipping
# should have a minimal impact.
"""
percentilethresh(x, p)
Find the threshold where `p` percent of `x` will be below it.
"""
function percentilethresh(x, p)
xs = sort(abs.(x))
xs[ceil(Int, p/100*length(x))]
end
# expsweep and impulse are naturally limited, so no need to compute a scaling
# factor for them
using MeasureIR
rawsig(g::MeasureIR.GolaySequence) = [g.A; g.B]
rawsig(g::MeasureIR.IRMeasurement) = g.sig
data = Dict()
for f in [expsweep, golay, mls, rpms]
fname = split(string(f),".")[2]
m = f(2^24)
thresh = percentilethresh(resample(rawsig(m), 8//1), 99.99)
data[f] = thresh
print(".")
end
println()
ref = db2amp(-1)
println("===================")
println("Impulse Gain: ", ref)
println("ExpSweep Gain: ", ref / data[expsweep])
println("Golay Gain: ", ref / data[golay])
println("MLS Gain: ", ref / data[mls])
println("RPMS Gain: ", ref / data[rpms])
println("===================")