From ec40a745f5ac32db7ea702d044e075a8a962305e Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 19 Feb 2018 04:04:28 -0800 Subject: [PATCH] update 38 --- lib/smoothfft.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/smoothfft.py b/lib/smoothfft.py index e670cf0..70b9b96 100644 --- a/lib/smoothfft.py +++ b/lib/smoothfft.py @@ -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 dist = np.abs(log2_xs2 - np.log2(x + 1e-35))/bw # 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 if compensate: _, temp = smoothfft2(xs, np.ones(len(xs)), bw=bw, precision=precision, compensate=False) ys2 /= temp 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