Matlab的样条曲线等效于Python,三个输入. [英] Matlab's spline equivalent in Python, three inputs.

查看:96
本文介绍了Matlab的样条曲线等效于Python,三个输入.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将matlab脚本转换为python,但遇到了障碍. 为了在信号上使用三次样条插值.脚本使用带有三个输入的命令样条线. f_o,c_signal和频率.因此如下所示.

I'm converting a matlab script to python and I have it a roadblock. In order to use cubic spline interpolation on a signal. The script uses the command spline with three inputs. f_o, c_signal and freq. so it looks like the following.

cav_sig_freq = spline(f_o, c_signal, freq)
f_o = 1x264, c_signal = 1x264 and freq = 1x264

从matlab的文档中读取到:"s = spline(x,y,xq)返回与xq中的查询点相对应的插值s的向量.s的值由x和c的三次样条插值确定y."

From the documentation in matlab it reads that "s = spline(x,y,xq) returns a vector of interpolated values s corresponding to the query points in xq. The values of s are determined by cubic spline interpolation of x and y."

在python中,我正在努力寻找正确的python等效项.我在numpy和Scipy文档中发现了不同的插值函数,让我们像在Matlab中一样使用第三个输入.

In python i'm struggling to find the correct python equivalent. Non of different interpolation functions I have found in the numpy and Scipy documentation let's use the third input like in Matlab.

感谢您抽出宝贵的时间阅读本文档.如果我对如何使其更清晰有任何建议,我将很乐意这样做.

Thanks for taking the time to read this. If there are any suggestion to how I can make it more clear, I'll be happy to do so.

推荐答案

基本上,您首先需要生成类似插值函数的内容,然后给出要点.像这样使用变量名:

Basically you will first need to generate something like an interpolant function, then give it your points. Using your variable names like this:

from scipy import interpolate
tck = interpolate.splrep(f_o, c_signal, s=0)

,然后将此点应用于您的观点:

and then apply this tck to your points:

c_interp = interpolate.splev(freq, tck, der=0)

有关此的更多信息,您可以阅读

For more on this your can read this post.

这篇关于Matlab的样条曲线等效于Python,三个输入.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆