简体   繁体   English

数值拉普拉斯变换python

[英]Numerical Laplace transform python

I have a time series of experimental data x = x(t) in two numpy arrays, x for the observable and t for the time values of the observations. 我在两个numpy数组中有一个实验数据x = x(t)的时间序列,x表示可观测值,t表示观测值的时间值。 Is there a numpy function or a way that can evaluate the laplace transform of the timeseries? 是否有一个numpy函数或一种可以评估时间序列的拉普拉斯变换的方法? Thank you in advance. 先感谢您。

I think you should have to consider the Laplace Transform of f(x) as the Fourier Transform of Gamma(x)f(x)e^(bx), in which Gamma is a step function that delete the negative part of the integral and e^(bx) constitute the real part of the complex exponential. 我认为您应该将f(x)的拉普拉斯变换视为Gamma(x)f(x)e ^(bx)的傅立叶变换,其中Gamma是一个阶跃函数,它删除了积分的负部分并e ^(bx)构成复指数的实部。 There is a well known algorithm for Fourier Transform known as "Fast Fourier Transform" (FFT), for which you can find a lot of tutorials on both Python and Matlab websites. 有一种众所周知的傅里叶变换算法,称为“快速傅里叶变换”(FFT),在Python和Matlab网站上都可以找到很多教程。

Here I give you a short code that calculate the Fourier transform of a step function such as y = 0 for |x| 在这里,我给您一个简短的代码,用于计算阶跃函数的傅立叶变换,例如| x |的y = 0。 > 1 y = 1 for |x| | x |> 1 y = 1 < 1 <1

for which the Fourier Transform can be analitically calculated as sin(pi x) / (pi x). 为此,傅里叶变换可以用sin(pi x)/(pi x)来分析计算。

import matplotlib.pyplot as plt
import scipy
from scipy.fftpack import fftshift
import numpy as np

x = np.arange(-3, 3, 0.01)
y = np.zeros(len(x))
y[150:450] = 1
plt.plot(x, y) # plot of the step function

yShift = fftshift(y) # shift of the step function
Fourier = scipy.fft(yShift) # Fourier transform of y implementing the FFT
Fourier = fftshift(Fourier) # inverse shift of the Fourier Transform
plt.plot(Fourier) # plot of the Fourier transform

Note that before and after applying the Fast Fourier Transform you have to use the fftshift command that provide a shift of the left side of the plot to the right side and viceversa. 请注意,在应用快速傅立叶变换之前和之后,您必须使用fftshift命令,该命令可将图的左侧向右侧移动,反之亦然。 This is not the complete answer to your question, but I believe that is a good start. 这不是您问题的完整答案,但我相信这是一个好的开始。

You may use the Trapezoidal rule to calculate numerically the integral for the Laplace transform. 您可以使用梯形法则以数字方式计算Laplace变换的积分。 One paper which describes this method is Edward H. Hellen: Padé –Laplace analysis of signal averaged voltage decays obtained from a simple circuit (Equation 2) 爱德华·H·海伦Edward H. Hellen)是描述这种方法的一篇论文:Padé–从简单电路获得的信号平均电压衰减的拉普拉斯分析 (公式2)

Notes: 笔记:

1) "The summation approximates the integral in Eq. 1 [in the article] as long as the data are close to zero by the last data point." 1)“只要在最后一个数据点之前数据接近于零,该求和就近似于[条款]中的等式1。”

2) "A good choice for p0 is the inverse of the time it takes for the data to decay to 1/2 its initial value." 2)“ p0的一个好的选择是数据衰减到其初始值的1/2所花费的时间的倒数。”

3) Since your data is not spaced equally, I would use interpolation (from scipy import interpolate) for the data first. 3)由于您的数据分布不均,我将首先对数据使用插值(来自scipy import interpolate)。 The Trepozoidal rule needs equally spaced data. 梯形规则需要等间距的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM