Matlab's spline equivalent in Python, three inputs.

前端 未结 2 717
野的像风
野的像风 2021-01-23 23:29

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 input

相关标签:
2条回答
  • 2021-01-23 23:48

    Have you tried the InterpolatedUnivariateSpline within scipy.interpolate? If I understand the MatLab part correctly, then I think this will work.

    import numpy as np
    from scipy.interpolate import InterpolatedUnivariateSpline as ius
    
    a = [1,2,3,4,5,6]
    b = [r * 2 for r in a]
    c = ius(a, b, k=1)
    
    # what values do you want to query?
    targets = [3.4, 2.789]
    
    interpolated_values = c(targets)
    

    It seems this may add one more step to your code than what MatLab provides, but I think it is what you want.

    0 讨论(0)
  • 2021-01-23 23:49

    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.

    0 讨论(0)
提交回复
热议问题