具有复杂信号的Scipy fftconvolve输出

2024-09-29 23:32:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个项目,复杂阵列的卷积积分需要通过数值计算来确定。为此,我使用scipy.signal模块,更具体地说,是通过调用“fftconvolve”来使用FFT算法。与所涉及的两个函数的解析解相比,我无法理解从数值上获得的结果,以下是研究案例,其中解析解是从WolframAlpha online integrator获得的:

import numpy as np
from scipy.signal import fftconvolve

boundary_limit = 100
total_points   = 10000 

x = np.linspace( -boundary_limit, boundary_limit, total_points )

f = np.exp( - ( x**2 ) ) + 1j*np.exp( -0.5*( x**2 ) ) # the f, g functions entering the 
                                                      # integral
g = np.exp( -0.2*(x**2) )

f.astype( np.complex128 )  #complex128 data types
g.astype( np.complex128 )

analytic_solution = ( np.sqrt( 5*np.pi/6 ) )*np.exp(  -( ( x**2 ) / 6) ) + 1j*np.sqrt( 
                      10*np.pi/7 )*np.exp( -( x**2 )/7 )

dx = np.abs( x[0] - x[1] ) # step differential to evaluate the integral

numsol2 = dx*fftconvolve( f, g, mode="same")

error_real = np.abs( np.real( analytic_solution ) - np.real( numsol2 ) )
error_imag = np.abs( np.imag( analytic_solution ) - np.imag( numsol2 ) )

print( np.max( error_real ) )
print( np.max( error_imag ) )

此外,如果这些错误被表示出来,人们会看到与分析结果的严重偏差。这里怎么了?这是否与所使用的数据类型、“相同”模式或卷积的边界效应等有关

我需要以非常高的精度评估这些卷积,因为所涉及的数字有时非常小(在代码的某些部分为<;1e-16),并且请注意,在定义阵列的同一组点“x”(即它们的支持范围)上评估解决方案,因此使用“相同”调用fftconvolve中的选项。了解Python中的其他实现也很好,即尽可能最好地评估此类积分


Tags: thenperrorabsreal卷积analytic数值

热门问题