update 38
This commit is contained in:
parent
1ceab58844
commit
ec40a745f5
1 changed files with 20 additions and 1 deletions
|
@ -31,10 +31,29 @@ def smoothfft2(xs, ys, bw=1, precision=512, compensate=True):
|
||||||
# before optimizations: dist = np.abs(np.log2(xs2/(x + 1e-35)))/bw
|
# before optimizations: dist = np.abs(np.log2(xs2/(x + 1e-35)))/bw
|
||||||
dist = np.abs(log2_xs2 - np.log2(x + 1e-35))/bw
|
dist = np.abs(log2_xs2 - np.log2(x + 1e-35))/bw
|
||||||
# window = np.maximum(0, 1 - dist) # triangle window
|
# window = np.maximum(0, 1 - dist) # triangle window
|
||||||
window = np.exp(-dist**2/(0.5/2)) # gaussian function (non-truncated)
|
window = np.exp(-dist**2/(0.5/2)) # gaussian window (non-truncated)
|
||||||
ys2 += ys[i]*window
|
ys2 += ys[i]*window
|
||||||
if compensate:
|
if compensate:
|
||||||
_, temp = smoothfft2(xs, np.ones(len(xs)),
|
_, temp = smoothfft2(xs, np.ones(len(xs)),
|
||||||
bw=bw, precision=precision, compensate=False)
|
bw=bw, precision=precision, compensate=False)
|
||||||
ys2 /= temp
|
ys2 /= temp
|
||||||
return xs2, ys2
|
return xs2, ys2
|
||||||
|
|
||||||
|
|
||||||
|
def smoothfft3(ys, bw=1, precision=512):
|
||||||
|
"""performs log-lin smoothing on magnitude data"""
|
||||||
|
size = len(ys)
|
||||||
|
xs = np.arange(0, 1, 1/size)
|
||||||
|
|
||||||
|
xs2 = np.logspace(-np.log2(size), 1, precision, base=2)
|
||||||
|
ys2 = np.zeros(precision)
|
||||||
|
comp = np.zeros(precision)
|
||||||
|
|
||||||
|
log2_xs2 = np.log2(xs2)
|
||||||
|
for i, x in enumerate(xs):
|
||||||
|
dist = np.abs(log2_xs2 - np.log2(x + 1e-35)) / bw
|
||||||
|
window = np.exp(-dist**2 * 4) # gaussian window (non-truncated)
|
||||||
|
comp += window
|
||||||
|
ys2 += ys[i] * window
|
||||||
|
|
||||||
|
return xs2, ys2 / comp
|
||||||
|
|
Loading…
Add table
Reference in a new issue