【问题标题】:What is the correct number of points to use in a response function for colvolutions?在 colvolutions 的响应函数中使用的正确点数是多少?
【发布时间】:2018-07-19 19:34:33
【问题描述】:

我有一个输入函数/数据 - f(x) - 我想将它与一个响应函数 - g(x) 进行卷积 - 以获得一个输出函数 - h(x)。我已经验证了 g(x) 中使用的点数正在影响 h(x) 的形状。 图 1 显示了我的意思比我能描述的更好: 那么,我的问题是:在 g(x) 中使用的正确点数是多少?

我使用 python 和 numpy 来完成这项工作。我使用的代码是:

#!/usr/bin/python
# -*- coding: utf8 -*-

import numpy as np
import matplotlib.pyplot as plt
import csv

# Full Width at Half Maximum - also known as Instrumental Broadening
FWHM = 0.678

filename = "Input_Data_File.dat"
DataX,DataY = [],[]
with open(filename) as Data:
  reader = csv.reader(Data,delimiter=' ',skipinitialspace=True)
  for row in reader:
    DataX.append(float(row[0]))
    DataY.append(float(row[1]))

# The f(x) data:
DataX = np.array(DataX)
DataY = np.array(DataY)
lx = len(DataX)

x1 = np.linspace(-FWHM*2.0,FWHM*2.0,num=int(lx*(0.1))) #len(x) = 10% of len(DataX)
x2 = np.linspace(-FWHM*2.0,FWHM*2.0,num=int(lx*(0.02))) #len(x) = 2% of len(DataX)
x3 = np.linspace(-FWHM*2.0,FWHM*2.0,num=int(lx*(0.2))) #len(x) = 20% of len(DataX)

# Response function - Gaussian type
G1 = np.exp(-4*np.log(2)*((x1/FWHM)**2))
G2 = np.exp(-4*np.log(2)*((x2/FWHM)**2))
G3 = np.exp(-4*np.log(2)*((x3/FWHM)**2))

# Performing the convolutions
H1 = np.convolve(G1,DataY,'same')
H2 = np.convolve(G2,DataY,'same')
H3 = np.convolve(G3,DataY,'same')

# Normalizing convoluted functions
H1 = H1/max(H1)
H2 = H2/max(H2)
H3 = H3/max(H3)

# Normalizing DataY as Y
Y = DataY/max(DataY)

plt.plot(DataX,Y,'y--', label="Input function / f(x)")
plt.plot(DataX,H1,'r-', label="#points: {}".format(len(x1)))
plt.plot(DataX,H2,'g-', label="#points: {}".format(len(x2)))
plt.plot(DataX,H3,'b-', label="#points: {}".format(len(x3)))
plt.xlabel("x / DataXt")
plt.ylabel("Normalized intensity")
plt.ylim(-0.05,1.05)
plt.title("Influence of #points of 'Response\nfunction' in convoluted curves")
plt.legend(loc='upper left')
plt.savefig("Convoluted_curves.png")
plt.show()

而我用作“Input_Data_File.dat”的数据文件可以在here找到。

【问题讨论】:

    标签: python numpy convolution


    【解决方案1】:

    通过实验验证,我可以得出结论,响应函数 g(x) 中要使用的正确点数是步长最接近输入函数 f(x) 的步长的点。

    所以在问题的python代码中,最好的选择是使用正确的步骤numpy.arange而不是numpy.linspace。

    【讨论】:

    • 不幸的是,我(还)没有在离散/数值卷积理论中找到任何关于这个结论的参考。如果有人知道支持这一点的参考资料,请告诉我。
    猜你喜欢
    • 2021-12-08
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多