#python #fft #convolution #numerical-integration
Вопрос:
У меня есть некоторая числовая ошибка в моем коде, которая постоянно распространяется и связана с реализацией сверток в Python; это своего рода борьба за мой прогресс, и я был бы очень признателен за некоторые советы здесь.
ПРОБЛЕМА: Я хочу численно оценить интеграл свертки двух (сложных) сигналов $f,g$, используя алгоритм быстрого преобразования Фурье, поэтому я использую scipy.signal.fftconvolve
. Два сигнала определены по сетке из равноудаленных точек «x», и их реальная и мнимая части выглядят примерно так:
где синяя линия соответствует $f[x]$, а пунктирная линия — $g[x]$, а первая цифра представляет реальные части. Проблема в том, что я хочу получить y[x] = ( f*g )[x], чтобы функция $y[x]$, полученная в результате интеграла, оценивалась точно в тех же точках x-сетки, что и f и g. Тогда я использую:
y = dx*scipy.signal.fftconvolve( f, g, mode="same" )
and I get the following:
with the real part of $y[x]$ in blue and the orange being the imaginary part. If I understand correctly, using the mode="same"
on fftconvolve
should provide precisely the value of the convolution integral on the original grid of points x.
The problem has to do with the edges; it seems to me these values are some sort of error due to the zero-padding or something similar here. The functions f and g are supposed to decay to 0 at infinity ( actually, f is supposed to decay to 0, and g to a constant value ), however the support of both f and g seems to be much larger than the used grid for this integration. Analytically, one has an infinite range of integration (the limits of the integral are — infinity), but here, the largest value of $x$ serves as the limit of integration. As a result, this error propagates in my code leading to instabilities of the solutions at the edges. Can anyone give some advice or method on how to solve these issues?