相位空间图的圆锥形插值

发布于 2025-01-23 14:20:10 字数 1142 浏览 0 评论 0原文

我正在创建电压的第一衍生物的相空间图:“

我想插入图块平滑。到目前为止,我已经通过时间插值电压和第一个导数,然后随时间分别插入电压,然后生成相空间图。

Python代码(玩具数据示例)

import numpy as np
import scipy.interpolate

interp_factor = 100
n = 12
time = np.linspace(0, 10, n)
voltage = np.array([0, 1, 2, 10, 30, 70, 140, 150, 140, 80, 40, 10])

voltage_diff = np.diff(voltage)
voltage = voltage[:-1]
time = time[:-1]

interp_function_voltage = scipy.interpolate.interp1d(time, voltage, kind="cubic")
interp_function_voltage_diff = scipy.interpolate.interp1d(time, voltage_diff, kind="cubic")

new_sample_num = interp_factor * (n - 1) + 1
new_time = np.linspace(np.min(time), np.max(time), new_sample_num)

interp_voltage = interp_function_voltage(new_time)
interp_voltage_diff = interp_function_voltage_diff(new_time)

我想问的是

: a)该方法是否合理?

b)通过直接在相空间中插值来有更好的方法?例如,用电压插值为x和vytage_diff,为y?我认为这是没有道理的,因为电压值不均匀间隔,并且可能有重复的电压值。我还尝试了Scipy参数插值方法(例如scipy.interpaly.splprep),但这些输入值误差。我希望(澄清一下会很高兴),因为这是原始数据,而不是行为良好的参数函数。

我想更一般地,我想知道在相位上以某种方式进行插值是否有意义,以利用电压和电压_diff之间的直接关系进行插值 /平滑。

非常感谢

I am creating a phase-space plot of first derivative of voltage against voltage: 1

I want to interpolate the plot so so it is smooth. So far, I have approached this by interpolating the voltage and first derivative of the voltage separately with time, then generating phase space plots.

Python Code (toy data example)

import numpy as np
import scipy.interpolate

interp_factor = 100
n = 12
time = np.linspace(0, 10, n)
voltage = np.array([0, 1, 2, 10, 30, 70, 140, 150, 140, 80, 40, 10])

voltage_diff = np.diff(voltage)
voltage = voltage[:-1]
time = time[:-1]

interp_function_voltage = scipy.interpolate.interp1d(time, voltage, kind="cubic")
interp_function_voltage_diff = scipy.interpolate.interp1d(time, voltage_diff, kind="cubic")

new_sample_num = interp_factor * (n - 1) + 1
new_time = np.linspace(np.min(time), np.max(time), new_sample_num)

interp_voltage = interp_function_voltage(new_time)
interp_voltage_diff = interp_function_voltage_diff(new_time)

I would like to ask:

a) is the method as implemented reasonable?

b) is there a better method by interpolating directly in the phase-space? e.g. interpolating with voltage as x and voltage_diff as y? I do not think this makes sense, because the voltage values are not uniformly spaced and there may be repeated voltage values. I also tried the scipy parametric interpolation methods (e.g. scipy.interpolate.splprep) but these threw input value error. I expect (it would be nice to have this clarified) because this is raw data, rather than well behaved parametric functions.

I guess more generally, I am wondering if it makes sense to somehow do the interpolation in the phase-space to make use of the direct relationship between voltage and voltage_diff for interpolating / smoothing.

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2025-01-30 14:20:11

这是合理的,但是您的区别会偏见,也许差异的最佳近似可能是(v [i+1] -v [i -1])/(2*dt)

另一种方法正在使用傅里叶变换平滑

def smoother_phase_space(y, sps=1, T=1):
    Y = np.fft.rfft(y)
    yu = np.fft.irfft(Y, len(y)*sps).real * sps
    dyu = np.fft.irfft(Y * (2j * np.pi * np.fft.rfftfreq(len(y))), len(y)*sps).real
    k = np.arange(len(yu)+2) % len(yu)
    return yu[k], dyu[k] * sps / T

v, dv = smoother_phase_space(voltage, sps=1)
plt.plot(v, dv, '-ob')

v, dv = smoother_phase_space(voltage, sps=4)
plt.plot(v, dv, '-r')
plt.plot(v[::4], dv[::4], 'or')
v, dv = smoother_phase_space(voltage, sps=32)
plt.plot(v, dv, '-g')
plt.plot(v[::32], dv[::32], 'og')

try: # the data computed in the original post
    plt.plot(interp_voltage, interp_voltage_diff, '--')
except:
    pass

“在此处输入图像描述”

It is reasonable, but your difference will be biased, maybe the best approximation for the difference could be (v[i+1] - v[i-1])/(2*dt)

Another approach is using Fourier transform smoothing

def smoother_phase_space(y, sps=1, T=1):
    Y = np.fft.rfft(y)
    yu = np.fft.irfft(Y, len(y)*sps).real * sps
    dyu = np.fft.irfft(Y * (2j * np.pi * np.fft.rfftfreq(len(y))), len(y)*sps).real
    k = np.arange(len(yu)+2) % len(yu)
    return yu[k], dyu[k] * sps / T

v, dv = smoother_phase_space(voltage, sps=1)
plt.plot(v, dv, '-ob')

v, dv = smoother_phase_space(voltage, sps=4)
plt.plot(v, dv, '-r')
plt.plot(v[::4], dv[::4], 'or')
v, dv = smoother_phase_space(voltage, sps=32)
plt.plot(v, dv, '-g')
plt.plot(v[::32], dv[::32], 'og')

try: # the data computed in the original post
    plt.plot(interp_voltage, interp_voltage_diff, '--')
except:
    pass

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文