LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

linear resample of array, iinearly interpolate vectors with a irregular grid

Dear all,
I have a coupled data samples (xi, yi) stored in two arrays, X (indipendent variable) and Y (dependent variable).
X array ha an irregular grid (let's say X={0.5, 0.9, 1.2, 1.6} and corresponding Y={1,2,3,4}) that I would like have regular, with given step (es. 0.5, X={0.5,1,1.5,2} and corresponding linear resampled for Y).
Is there any function in CVI available for this?
 
many thanks
Michele
0 Kudos
Message 1 of 5
(4,234 Views)
One possible solution is to calculate the interpolant between your data and use it to generate the new values at given x values.
 
I generally calculate all interpolants in a certain polinomial degree range and use the one that minimizes the mean squared error.
 
 int  Order;
 double coeffsArray[10], mseArray[10];
 double *x = NULL, *y = NULL, *dummyArray = NULL, *OutputArray = NULL;
 for (Order = 3; Order <= 9; Order++) {
  PolyFit (x, y, NumberOfElements, Order, dummyArray, coeffsArray, &mseArray[g]);
 }
 MaxMin1D (mseArray + 3, 7, &max, &maxidx, &min, &minidx);
 PolyFit (x, y, NumberOfElements, minidx + 3, OutputArray, coeffsArray, mse);
Once obtained the degree of the ploynom and the corresponding array of coefficients, you can use Ramp function to generate the new X array and pass it to PolyEv1D to calculate the new Y values.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(4,232 Views)


Thanks for the suggestion but I am afraid I was not clear.
I want to resample X and Y linearly using just neighborhood elements.

thus, given
X={0.5, 0.9, 1.2, 1.6} and corresponding Y={1,2,3,4},
I would like to resample X according to:
X2={0.5,1,1.5,2}
Y2 is the resampled values for the resampled abscissa X2
if i is the index for X2, j is the index of the closer X smaller than X2[i],
j+1 is the index of the closer X greater than X2[i]

Y2(i) = Y(j)+ X2(i)-X(j) * (Y(j+1)-Y(j))/(x(j+1)-X(j))

thanks for your help,
Michele

0 Kudos
Message 3 of 5
(4,219 Views)

Oho, I see.

Well, I'm afraid the only solution lies in the last equation you wrote: you'll need to apply it to every pair of elements of your arrays in a loop. But I would consider the polynomial interpolation: it can give you brilliant results with a few lines of code and can be easily tested. Supposing the results are not heavily dispersed the resulting intepolated values won't be so far from linear interpolation...

Message Edited by Roberto Bozzolo on 07-11-2006 09:51 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(4,209 Views)

Thanks Roberto,

I am afraid I have to use the linear one anyhow..

regards,

Michele

0 Kudos
Message 5 of 5
(4,195 Views)