我正试图围绕scipy.optimize.minimize
. 我一遍又一遍地阅读文档并用谷歌搜索,但我根本不明白如何做到这一点。希望有人能指出我正确的方向:
我有一个信号numpy array
(我想我需要做一些最小化的事情
(基线调整 + 幅度因子 * 模板阵列 - 信号阵列)**2
我想使用baselineadjust和amplitudefactor随后修改信号,减去修改后的模板,即
新信号 = 基线调整 + 幅度因子 * 模板阵列 - 信号阵列
这种操作的目的是有效地从实际信号中去除模板信号,留下剩余的信号/噪声。
不确定这是否有意义并且很乐意详细说明。
#data is a (very) long list of floats, that contains a noisy signal and a repetitive signal of a specific length but with slight variations in amplitude, partially due to the noisy signal and partially because it inherently varies a bit. I wish to remove the repetitive signal from the data.
#Prior to this, I detect signals in data:
sigwindows = []
#Gather signals
for sig in signals:
sigwindow = list(data[sig-200:sig+200])
sigwindows += [sigwindow]
#Construct an averaged signal
avgsig = np.mean(sigwindows, axis=0)
for sig in signals:
sigwindow = list(data[sig-200:sig+200])
#First, I subtract the average signal
data[sig-200:sig+200] = list(np.array(sigavg) - np.array(sigwindow))
#This removes some of the signal, but due to the inherent variation in amplitude, some of it remains.
#Instead would like to do this:
data[sig-200:sig+200] = list(np.array(sigavg) - baselineadjust - amplitudefactor * np.array(sigwindow))
#... having obtained 'baselineadjust' and 'amplitudefactor' as described above, by minimizing chi-square.