From cfd60f28261791c61101a69450953cfa1e85c3bf Mon Sep 17 00:00:00 2001 From: Casper Date: Mon, 18 Oct 2021 10:02:23 +0200 Subject: [PATCH] fixed bug in new octave smoothing --- lasp/tools/tools.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lasp/tools/tools.py b/lasp/tools/tools.py index 752ed7b..ef720f8 100644 --- a/lasp/tools/tools.py +++ b/lasp/tools/tools.py @@ -161,8 +161,8 @@ def smoothSpectralData(freq, M, sw: SmoothingWidth, fu = fNq # no data beyond fNq fl = fc**2 / fu # keep window symmetric - xl = bisect.bisect_left(f, fl) # index corresponding to fl - xu = bisect.bisect_left(f, fu) + xl = bisect.bisect_left(freq, fl) # index corresponding to fl + xu = bisect.bisect_left(freq, fu) # Calculate window g = np.zeros(xu-xl) @@ -307,7 +307,7 @@ if __name__ == "__main__": fmin = 3e3 # [Hz] min freq fmax = 24e3 # [Hz] max freq Ndata = 200 # number of data points - f = np.linspace(fmin, fmax, Ndata) # frequency points + freq = np.linspace(fmin, fmax, Ndata) # frequency points M = abs(0.4*np.random.normal(size=(Ndata,)))+0.01 # M = 20*np.log10(M) @@ -315,7 +315,7 @@ if __name__ == "__main__": # fmin = 3e3 # [Hz] min freq # fmax = 24e3 # [Hz] max freq # Ndata = 200 # number of data points -# f = np.linspace(fmin, fmax, Ndata) # frequency points +# freq = np.linspace(fmin, fmax, Ndata) # frequency points # M = 0 * abs(1+0.4*np.random.normal(size=(Ndata,))) + 0.01 # # M[int(100)] = 1 # M = 20*np.log10(M) @@ -325,12 +325,12 @@ if __name__ == "__main__": value = [Noct] st = SmoothingType.levels # so data is given in dB - Msm = smoothSpectralData(f, M, sw, st) - fsm = f + Msm = smoothSpectralData(freq, M, sw, st) + fsm = freq # Plot - lin frequency plt.figure() - plt.plot(f, M, '.b') + plt.plot(freq, M, '.b') plt.plot(fsm, Msm, 'r') plt.xlabel('f (Hz)') plt.ylabel('magnitude') @@ -339,7 +339,7 @@ if __name__ == "__main__": # Plot - log frequency plt.figure() - plt.semilogx(f, M, '.b') + plt.semilogx(freq, M, '.b') plt.semilogx(fsm, Msm, 'r') plt.xlabel('f (Hz)') plt.ylabel('magnitude')