Upsample array using spline.

Posted on 2005-05-10
Last Modified: 2010-04-02
I need to create an new array with about 6 times as many elements as the original. The values of the new array need to be calculated from the original array using a spline function.
Question by:evenrik
    LVL 45

    Expert Comment

    1. Declare the array of required size

    #define INPUT_ELEMENTS 10
    double myarray [60];

    2. if you wish to make size modifications at run time, use malloc to create your array and use realloc to adjust the size

    double * myarray;

    myarray = (double *) malloc (sizeof (double) * INPUT_ELEMENTS);
    myarray = (double *) realloc ( (void *) myarray , sizeof (double) * INPUT_ELEMENTS * 6 );
    LVL 55

    Expert Comment

    by:Jaime Olivares
    >need to create an ***new**** array with about 6 times as many elements as the original

    An easy solution to avoid to use malloc:
    #define MAX_ELEMENTS 10
    double myarray [MAX_ELEMENTS];
    double newarray [MAX_ELEMENTS*6];

    A solution with malloc, with not fixed length, doesn't need realloc:

    double *myarray, *newarray;
    int elements;  /* enter the number of elements somewhere and store in this variable */

    myarray = (double *) malloc (sizeof (double) * elements);
    newarray = (double *) malloc (sizeof (double) * elements * 6);

    Of course, you will have to free memory somewhere after using arrays:

    Author Comment

    Thank you for your responses, but I obviously did not describe the problem well.
    The problem is not getting the memory for the new array, it is calculating the values for the elements of the new array. The original array values would have a curve if plotted. The new array must have the same shape with interpolated values for the new points inbetween the original points. The new points must be on a curve, not just a straight line between the original points.
    LVL 45

    Expert Comment

    You still need to refine your question - Are you are looking for an algorithm or are you looking for the code for an algorithm or is it something else?
    LVL 16

    Expert Comment


    The problem is that spline interpolation is actually not a specific algorithm except in certain fields. There are qubic splines, bezier splines, hermite splines etc. The maths guys could give you a longer list. Do you have any idea what sort of spline you are looking for? What field are you working in? Physics, maths, graphics, they all treat splines in differenty ways.

    Give us more details of your needs.

    You could get this question moved to the Maths board or post a link to it there? I can move it if you want.

    LVL 4

    Assisted Solution


    i f u want help on spline and nurbs u could use the following link

    contains useful programs on splines


    Author Comment

    I need source code that does "Cubic Spline Interpolation".
    I am porting code into c that uses a spline function that does "Cubic Spline Interpolation".
    Due to copyright restrictions I cannot just port the existing code.
    LVL 9

    Accepted Solution

    LVL 9

    Expert Comment

    btw what is the nature of your data points? 1D, 2D or 3D?
    LVL 12

    Expert Comment

    Hi evenrik,
    "Cubic Spline Interpolation" is a pretty good search term for Google et al.



    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    scanf and assignment suppression 13 129
    Way to scan the path 41 159
    Difference between struct tm and time_t 5 99
    An API detour question 7 38
    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now