gpt4 book ai didi

python - 使用 numpy 进行傅里叶反卷积

转载 作者:太空宇宙 更新时间:2023-11-04 04:45:02 25 4
gpt4 key购买 nike

我正尝试使用傅立叶反卷积从信号中移除我的探针功能,但我无法通过测试信号获得正确的输出。

t = np.zeros(30)
t = np.append(t, np.arange(0, 20, 0.1))

sigma = 2
mu = 5.
g = 1/np.sqrt(2*np.pi*sigma**2) * np.exp(-(np.arange(mu-3*sigma,mu+3*sigma,0.1)-mu)**2/(2*sigma**2))

def pad_signals(s1, s2):
size = t.size +g.size - 1
size = int(2 ** np.ceil(np.log2(size)))
s1 = np.pad(s1, ((size-s1.size)//2, int(np.ceil((size-s1.size)/2))), 'constant', constant_values=(0, 0))
s2 = np.pad(s2, ((size-s2.size)//2, int(np.ceil((size-s2.size)/2))), 'constant', constant_values=(0, 0))
return s1, s2

def decon_fourier_ratio(signal, removed_signal):
signal, removed_signal = pad_signals(signal, removed_signal)
recovered = np.fft.fftshift(np.fft.ifft(np.fft.fft(signal)/np.fft.fft(removed_signal)))
return np.real(recovered)

gt = (np.convolve(t, g, mode='full') / g.sum())[:230]
tr = decon_fourier_ratio(gt, g)

fig, ax = plt.subplots(nrows=2, ncols=2, sharex=True)
ax[0,0].plot(np.arange(0,np.fft.irfft(np.fft.rfft(t)).size), np.fft.irfft(np.fft.rfft(t)), label='thickness')
ax[0,1].plot(np.arange(0,np.fft.irfft(np.fft.rfft(g)).size), np.fft.irfft(np.fft.rfft(g)), label='probe shape')
ax[1,0].plot(np.arange(0,gt.size),gt, label='recorded signal')
ax[1,1].plot(np.arange(0,tr.size),tr, label='deconvolved signal')
plt.show()

enter image description here

以上脚本创建了一个演示样本 (t) 和一个具有高斯形状的探针 (g)。然后,它将它们卷积为信号 gt,这是样本在被探测时的样子。我使用 pad_signals() 将信号填充到最近的 2^N,以提高效率并修复任何非周期性。然后我尝试使用 decon_fourier_ratio() 移除高斯探针。从图像中可以清楚地看出,我没有恢复初始厚度梯度。解卷积不起作用的任何想法?

注意:我也尝试过 SciPy 的反卷积。但是,此函数仅适用于特定宽度的高斯分布。

非常感谢任何帮助,

埃里克

最佳答案

您有什么理由不进行全卷积?如果我将 gt 的构造更改为:

g /= g.sum()  # so the deconvolved signal has the same amplitude
gt = np.convolve(t, g, mode='full')

然后我得到以下图:

enter image description here

我不能完全告诉你为什么你会看到这种行为,除了部分卷积之外,可能会改变频率内容。或者,如果您想获得相同的行为并使用 same,您可以用零填充输入信号。

关于python - 使用 numpy 进行傅里叶反卷积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49833886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com