Create line of best fit from a plot
2 views (last 30 days)
Attached is a plot which comes from an image, the plot represents pixels across various columns(1024) in an image which are less than the pixel value 200 (graycale). Can anyone help me or show me how to create a line of best fit with this data? Ive been trying the polyfit function but can't quite get it working.
Star Strider on 11 Dec 2014
What do you want to fit? A general trend or the most significant of the oscillations?
The polyfit function will do best for a general trend.
For the oscillations, I would start with a fft of it to find one or more of the most significant frequencies. Then use one of the nonlinear curve fitting functions with an objective function:
fs = @(b,x) b(1) + b(2).*sin(b(3).*x + b(4)) + b(5).*sin(b(6).*x + b(7));
I would not use more terms or parameters. Two terms is probably the most you can hope to fit successfully, and that may be optimistic.