Link to home
Start Free TrialLog in
Avatar of evenrik
evenrik

asked on

Upsample array using spline.

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.
Avatar of sunnycoder
sunnycoder
Flag of India image

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
e.g.

double * myarray;

myarray = (double *) malloc (sizeof (double) * INPUT_ELEMENTS);
...
myarray = (double *) realloc ( (void *) myarray , sizeof (double) * INPUT_ELEMENTS * 6 );
>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:
free(myarray);
free(newarray);
Avatar of evenrik
evenrik

ASKER

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.
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?
evenrik,

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.

Paul
SOLUTION
Avatar of furqanchandio
furqanchandio

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of evenrik

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
btw what is the nature of your data points? 1D, 2D or 3D?
Hi evenrik,
"Cubic Spline Interpolation" is a pretty good search term for Google et al.

Cheers!

Stefan