To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
jctheman15
New to the neighborhood
jctheman15
4 Posts

Question Help w/Matlab Interpolation Algorithms

I have an experimental dataset made up of 2D position coordinances. When plotted, the dataponts take on the shape of a circle or ellipse, with small sections where the data crosses back over its previous path. To aid in data analysis I am trying to interpolate between the datapoints so that there will be an even distribution of points along the entire trace.

In doing this I have converted the cartesian coordinances to polar coordinances, interpolating at a standard angle intervall (angle created by distance segment from datapoint to center, and horizontal axis) using the algorithm 'interp1'.

It seems during the instances where there may be more than one radius to an angle, the interpolated values begin jumping all over the place, not producing points indicative of the original trace. I'm wondering if there is an interpolation algorithm that lets me specify which radius to base the interpolation off of when there are more than one corresponding to an angle, or some other way I can interpolate that will eliminate the non-conformance at the points where the trace crosses over itself.
shwaip
elaborate bot
shwaip
5,732 Posts
can you post your code (and the data) to give a better idea of what's wrong?
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
jctheman15
New to the neighborhood
jctheman15
4 Posts
can you post your code (and the data) to give a better idea of what's wrong?
Below is my code. Since the sampling rate at the time the data was taken was high, there is too much data to send though icrontic. Send me your email and I will send them to you. There are over 2700 datapoints for the x coordintate array (Centered_ML) and the y coordinate array (Centered_AP). They are shown at the end of the code. If this code is run with this data, you will see that at four points along the circula data trace the data crosses back over itself. The interpolated trace seems not to be interpolating at all at these points!
Again, the input datasets are called Centered_ML and Centered_AP.

Thanks for your help!
jctheman15




%Center is at (0,0) ML is x axis, AP is y axis
Centered_ML; %x coordinate of all input datapoints
Centered_AP; %y coordinate of all input datapoints



theta1=atan(Centered_AP./Centered_ML);
%theta1 = angle of datapoint with respect to the x axis and the center



Range1=find(diff(theta1)>3,2,'first'); %Point at which angle goes from -pi/2 to pi/2
%Range1 = array that specifies the index of which theta values are for which half of the circle.
%Since arctan only has an interval of (-pi/2 to pi/2) Up to Range1(1) is
%right half of circle. Range1(2)-Range1(1) describes the left half of the circle

for i=1:Range1(1)
theta1_range1(i)=theta1(i); %The values of theta1 from the first pi/2 to -pi/2
Centered_ML_1(i)=Centered_ML(i);
Centered_AP_1(i)=Centered_AP(i);
end


for b=1:Range1(2)-Range1(1)
theta1_range2(b)=theta1(b+Range1(1));%The values of theta1 from the second pi/2 to -pi/2
Centered_ML_2(b)=Centered_ML(b+Range1(1));
Centered_AP_2(b)=Centered_AP(b+Range1(1));
end



%Calculating Radius from 'theta1' values
Limit1_radius1=Centered_ML_1./(cos(theta1_range1));
Limit1_radius2=Centered_ML_2./(cos(theta1_range2));


%Creating arrays of evenly spaced theta1 values
even_theta1=linspace(theta1_range1(1),theta1_range1(Range1(1)),1000); %Within Range of
even_theta2=linspace(theta1_range2(1),theta1_range2(Range1(2)-Range1(1)),1000);

%Interpolating between evenly spaced theta1 values
newint1=interp1(theta1_range1,Limit1_radius1,even_theta1);
newint2=interp1(theta1_range2,Limit1_radius2,even_theta2);

%Calculating the coordinates of every interpolated point
Int_ML_Limit_a=newint1.*cos(even_theta1);
Int_ML_Limit_b=newint2.*cos(even_theta2);
Int_AP_Limit_a=newint1.*sin(even_theta1);
Int_AP_Limit_b=newint2.*sin(even_theta2);

%Combining the right and left parts of the trace of interpolated data for
%the y coordinates, and the x coordinates
Int_AP_Limit_Fin = [Int_AP_Limit_a Int_AP_Limit_b];
Int_ML_Limit_Fin = [Int_ML_Limit_a Int_ML_Limit_b];

%Plotting input data against interpolated data
plot(Int_ML_Limit_Fin,Int_AP_Limit_Fin,'r*'), hold on%Interpolated Data
plot(Centered_ML,Centered_AP,'-') %Input Data
primesuspect
The Icrontic Guy
primesuspect
27,806 Posts
Jared, thanks for coming to icrontic. You've come to the right place for help - these guys know what they're talking about.

I'm actually very impressed to see someone from NASA visiting our site

I wanted to let you know that I removed your email address from your post since it is an open invitation for spam harvesters to grab it. I've PMed it to Evan (Shwaip) so that he has it.

Have a great day!

--Brian
__________________ "I offer my genius to the world, all I ask is you pick up my expenses"
shwaip
elaborate bot
shwaip
5,732 Posts
I sent you an email, just a heads-up.
shwaip
elaborate bot
shwaip
5,732 Posts
Just so that i make sure we're on the same page, this is one of the places where you're having the problem, and you'd want something vaguely like the green dots that I've drawn on the image in green?

I think the problem is that you'll need to do this in two steps. Interpolation alone will always give you the results that you're getting, simply because there can be very different values of the radius for small differences in theta (due to having the path go backward). I'd consider doing some sort of smart averaging/filtering/downsampling in areas where the data loops back on itself. The easiest way to see this is to look to see if there are a couple very different values of r in a small dTheta. If there are, then you can use a simple filter (i'd consider either looking at the average or the median of all the values of r in that dTheta) to replace all those values with only one value of r for that theta.

One final note is that in your code, you're ignoring the last part of the circle. There is more data after Range1(2). I don't know if that was on purpose or not.

I'll try a couple things tonight/tomorrow, but that should also give you an idea of some things to try.
Attached Thumbnails
Click image for larger version

Name:	blah.png
Views:	101
Size:	11.9 KB
ID:	23596  
jctheman15
New to the neighborhood
jctheman15
4 Posts
Just so that i make sure we're on the same page, this is one of the places where you're having the problem, and you'd want something vaguely like the green dots that I've drawn on the image in green?

I think the problem is that you'll need to do this in two steps. Interpolation alone will always give you the results that you're getting, simply because there can be very different values of the radius for small differences in theta (due to having the path go backward). I'd consider doing some sort of smart averaging/filtering/downsampling in areas where the data loops back on itself. The easiest way to see this is to look to see if there are a couple very different values of r in a small dTheta. If there are, then you can use a simple filter (i'd consider either looking at the average or the median of all the values of r in that dTheta) to replace all those values with only one value of r for that theta.

One final note is that in your code, you're ignoring the last part of the circle. There is more data after Range1(2). I don't know if that was on purpose or not.

I'll try a couple things tonight/tomorrow, but that should also give you an idea of some things to try.
jctheman15
New to the neighborhood
jctheman15
4 Posts
Thanks for the advice! I'll look into filtering by taking the mean of the radius values for every angle interval that has several radius values. As far as the data, yes I have ignored data after Range1(2) on purpose since it is data that we would like not to include because of the testing protocol. Let me know if you have any more ideas!
Similar Threads
Thread Thread Starter Forum Replies Last Post
MATLAB help, LaGrange interpolation. hallaballooo Matlab Help 5 10 Aug 2007 10:05pm
New algorithms and short retry deadlines mmonnin Folding@Home 0 26 Mar 2004 5:09am

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 3:13am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.