resampling, interpolating matrix

前端 未结 8 1441
-上瘾入骨i
-上瘾入骨i 2020-12-17 22:02

I\'m trying to interpolate some data for the purpose of plotting. For instance, given N data points, I\'d like to be able to generate a \"smooth\" plot, made up of 10*N or s

相关标签:
8条回答
  • I recommend that you check your algorithm, as it is a non-trivial problem. Specifically, I suggest you gain access to the article "Function Plotting Using Conic Splines" (IEEE Computer Graphics and Applications) by Hu and Pavlidis (1991). Their algorithm implementation allows for adaptive sampling of the function, such that the rendering time is smaller than with regularly spaced approaches.

    The abstract follows:

    A method is presented whereby, given a mathematical description of a function, a conic spline approximating the plot of the function is produced. Conic arcs were selected as the primitive curves because there are simple incremental plotting algorithms for conics already included in some device drivers, and there are simple algorithms for local approximations by conics. A split-and-merge algorithm for choosing the knots adaptively, according to shape analysis of the original function based on its first-order derivatives, is introduced.

    0 讨论(0)
  • 2020-12-17 22:25

    Here's a minimal example of 1d interpolation with scipy -- not as much fun as reinventing, but.
    The plot looks like sinc, which is no coincidence: try google spline resample "approximate sinc".
    (Presumably less local / more taps ⇒ better approximation, but I have no idea how local UnivariateSplines are.)

    """ interpolate with scipy.interpolate.UnivariateSpline """
    from __future__ import division
    import numpy as np
    from scipy.interpolate import UnivariateSpline
    import pylab as pl
    
    N = 10 
    H = 8
    x = np.arange(N+1)
    xup = np.arange( 0, N, 1/H )
    y = np.zeros(N+1);  y[N//2] = 100
    
    interpolator = UnivariateSpline( x, y, k=3, s=0 )  # s=0 interpolates
    yup = interpolator( xup )
    np.set_printoptions( 1, threshold=100, suppress=True )  # .1f
    print "yup:", yup
    
    pl.plot( x, y, "green",  xup, yup, "blue" )
    pl.show()
    

    Added feb 2010: see also basic-spline-interpolation-in-a-few-lines-of-numpy

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