I have several large data sets which follow the following pattern: A position is measured, a force is applied until a new equilibrium is found.
I'd like to find a fit for the position, at least at the plateaus, and preferably of the inter lying section, which in this case approaches a line.
I tried fitting the data with Clip, and with Piecewise.
nlm = NonlinearModelFit[v40s1000h,Piecewise[{{a, x < A}, {b, x > B}}], {a, b, A, B, c, d}, x]
This creates a decent fit only if I specify the values for A and B, but then I have to estimate those values for each data set manually. It also doesn't really work to just add NMinimize, or add the piecewise part for the middle bit.
Is There anything else I can try?

http://s000.tinyupload.com/?file_id=35616536027018518052 << file


v40s1000h. An idea would be to create the first few terms of a Fourier expansion and fit that within the domain of interest. – gpap Apr 10 '14 at 10:08NonlinearModelFitworks my minimizing some cost function (e.g. total squared error), but the cost function can't be evaluated if your piecewise function doesn't return a value for some values of x. Have you tried using something like{(a+b)/2,A<x<B}as a fallback? Alternatively, you could come up with your own cost function and just optimize that. – Niki Estner Apr 10 '14 at 11:06gpap, Peltio I haven't had too much maths yet, I know basic Fourier series and transforms, but that's it. Could you give more of an idea (or a link) on how to try this in Mathematica?
– Feyre Apr 10 '14 at 11:10The original was:
Piecewise[{{a, x < A}, {c x + d, A < x < B}, {b, x > B}}], which yields a single straight line. – Feyre Apr 10 '14 at 11:15