How to Fit One Curve to Another in MATLAB?

  • Thread starter Thread starter villiami
  • Start date Start date
  • Tags Tags
    Fitting
AI Thread Summary
The discussion focuses on developing a MATLAB program to transform one curve to best fit another through rotations and shifts, specifically addressing challenges with curves that double back on themselves. The initial approach involved calculating vertical distances, which proved inadequate due to the curves' complexity. Participants highlighted that the data sets are not paired, complicating the distance calculation, which could lead to inefficiencies. A suggested method involves calculating the squared distances between each point in the first curve and all points in the second, summing these to create a total distance measure for minimization. This problem is identified as a registration problem within optimization, and while the area between curves could be a potential measure for minimization, defining it remains uncertain. Ultimately, the original poster reports partial success by rotating curve segments to avoid overlaps, leading to improved fitting results.
villiami
Messages
27
Reaction score
0
I'm currently working on a MATLAB program which, given two sets of data each representing curves, will transform (through rotations about the origin and x-y shifts) the first curve so it fits the second one best (so far in terms of sum of squares).

I have been able to create a program calculating vertical distance between the two curves, but because my curves double back on themselves I don't think this will really work.

Does anyone know how this might be done (in MATLAB or another language)? Or even just what this type of problem is called (I tried "Curve fitting", but this seems to only refer to point-to-curve fitting)

Thanks in advance,
Will
 
Technology news on Phys.org
Is each set of data paired with the other or is there some parameterization that relates a given point on one curve with a unique point on the other?
 
The data is not paired, i.e. one set might be for x-values 10,20,30,40,50 and the other at 11,17,31.46,...etc
In the first version I used spline interpolation when I needed to compare points/curves.
(note these are not actually the data points!)
Thanks
 
OK, if the data is not paired then this may be very slow depending on the size of your data. I think the operation I am going to suggest is O(N²).

For each data point A in the first set calculate the squared distance (x²+y²) with each data point B in the second set. The minimum distance is the distance of point A from set B. Sum that over all points in A to get a total distance measure. Minimize that distance measure.

By the way, this seems like it is a kind of registration problem, which is a type of optimization problem. There are probably people who have solved this much more efficiently than what I am suggesting.
 
Do the functions fit within some sort of boundary box or circle? It seems to me that what you want to minimize is the absolute area between the two curves; however, I'm not sure how well-defined that is.

Are the curves finite? If so, one could define the area by drawing lines between the endpoints of the curves. Still, I'm not sure exactly how to calculate the area in order to minimize it.
 
Thanks for the responses, I think I've solved it (partially) by rotating the parts of the curves so the don't double back on themselves. Works well so I'm happy with it!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top