• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 999
  • Last Modified:

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.
0
evenrik
Asked:
evenrik
  • 2
  • 2
  • 2
  • +4
2 Solutions
 
sunnycoderCommented:
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 );
0
 
Jaime OlivaresCommented:
>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);
0
 
evenrikAuthor Commented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
sunnycoderCommented:
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?
0
 
PaulCaswellCommented:
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
0
 
furqanchandioCommented:
hi

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

contains useful programs on splines

http://www.nar-associates.com/nurbs/c_code.html


cheers
0
 
evenrikAuthor Commented:
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.
0
 
jhshuklaCommented:
btw what is the nature of your data points? 1D, 2D or 3D?
0
 
stefan73Commented:
Hi evenrik,
"Cubic Spline Interpolation" is a pretty good search term for Google et al.

Cheers!

Stefan
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now