本文介绍了使用scipy.signal.resample重新采样的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个信号不是等距采样的;进行进一步处理.我以为scipy.signal.resample可以做到,但我不了解它的行为.

I have a signal that is not sampled equidistant; for further processing it needs to be. I thought that scipy.signal.resample would do it, but I do not understand its behavior.

信号在y中,对应的时间在x中.预计将在yy进行重新采样,所有相应的时间在xx中.有人知道我做错了什么或如何实现我所需要的吗?

The signal is in y, corresponding time in x.The resampled is expected in yy, with all corresponding time in xx. Does anyone know what I do wrong or how to achieve what I need?

此代码不起作用:xx不是时间:

This code does not work: xx is not time:

import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

x = np.array([0,1,2,3,4,5,6,6.5,7,7.5,8,8.5,9])
y = np.cos(-x**2/4.0)
num=50
z=signal.resample(y, num, x, axis=0, window=None)
yy=z[0]
xx=z[1]
plt.plot(x,y)
plt.plot(xx,yy)
plt.show()

推荐答案

即使您提供x坐标(与t参数相对应),也会 resample 假定采样是统一的.

Even when you give the x coordinates (which corresponds to the t argument), resample assumes that the sampling is uniform.

请考虑在 scipy.interpolate 中使用单变量插值器之一.

Consider using one of the univariate interpolators in scipy.interpolate.

例如,此脚本:

import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt

x = np.array([0,1,2,3,4,5,6,6.5,7,7.5,8,8.5,9])
y = np.cos(-x**2/4.0)

f = interpolate.interp1d(x, y)

num = 50
xx = np.linspace(x[0], x[-1], num)
yy = f(xx)

plt.plot(x,y, 'bo-')
plt.plot(xx,yy, 'g.-')
plt.show()

生成此图:

检查 interp1d 用于控制插值的选项,并查看其他插值类.

Check the docstring of interp1d for options to control the interpolation, and also check out the other interpolation classes.

这篇关于使用scipy.signal.resample重新采样的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!