激光雷达系统、数据和拟合(2/2 数据集)

生成由高斯曲线拟合的数据图表

plot optimize lidar complex data fit
import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
def model(t, coeffs):
return (
coeffs[0]
+ coeffs[1] * np.exp(-(((t - coeffs[2]) / coeffs[3]) ** 2))
+ coeffs[4] * np.exp(-(((t - coeffs[5]) / coeffs[6]) ** 2))
+ coeffs[7] * np.exp(-(((t - coeffs[8]) / coeffs[9]) ** 2))
)
def residuals(coeffs, y, t):
return y - model(t, coeffs)
waveform_2 = np.load("waveform_2.npy")
t = np.arange(len(waveform_2))
x0 = np.array([3, 30, 20, 1, 12, 25, 1, 8, 28, 1], dtype=float)
x, flag = sp.optimize.leastsq(residuals, x0, args=(waveform_2, t))
fig, ax = plt.subplots(figsize=(8, 6))
plt.plot(t, waveform_2, t, model(t, x))
plt.xlabel("Time [ns]")
plt.ylabel("Amplitude [bins]")
plt.legend(["Waveform", "Model"])
plt.show()

脚本总运行时间:(0 分钟 0.079 秒)

由 Sphinx-Gallery 生成的图库