How do I perform a segmented regression for linear and exponential piecewise curve

15 次查看(过去 30 天)
Hi, everyone! I simulated this signal where the first segment is linear (constant), second segment is linear (positive gradient) and the third segment is an exponential decay. Is there a way for me to do a piecewise regression with 3 line segments - linear, linear and exponential? Thank you very much.
p/s: I think this is my first ever post, so I might not know the rules on how to ask a question proper, so if more information is needed, please let me know what other info I should provide! Thanks!

回答(2 个)

Saksham Gupta
Saksham Gupta 2022-7-5
编辑:Saksham Gupta 2022-7-5
As per my understanding , you wish to know how to perform segmented regression in MATLAB.
You should try Curve Fitter App of MATLAB with your data set, using 'Interpolant' or 'Smoothing Spline' as fit type might be helpful with the dataset of your kind.
Here are a few file exchanges that you might find helpful as well:
You may also checkout this answer to a previously asked similar question

Sam Chak
Sam Chak 2022-7-5
编辑:Sam Chak 2022-7-5
There are 3 segments defined over certain intervals of t:
a constant
a straight line
and an exponential decay
So, the piecewise model probably look something like this:
t = linspace(0, 520, 52001);
x1 = 100*((0 <= t) & (t < 80));
x2 = (((600 - 100)/(120 - 80))*t - 900).*((80 <= t) & (t < 120));
x3 = 600*exp(-0.0025*1.7918*(t - 120)).*((120 <= t) & (t < 520));
x = x1 + x2 + x3;
plot(t, x, 'linewidth', 2), grid on,
xlim([0 520]), ylim([0 700])
  2 个评论
Luqman
Luqman 2022-7-5
Yes, when I simulated the signal, I used 3 piecewise functions much like in your model.
Let's say I received a dataset just like that. The only thing I know for sure, is that there are 3 segments. 2 linear and 1 exponential. How do I do a least squares fit, for example, to obtain the coefficients in the (a) contant function, (b) order 1 function and (c) an exponential decay?
Sam Chak
Sam Chak 2022-7-5
Hi @Luqman, this is probably just one way of doing it:
  • Isolate the data into 3 intervals,
  • Fit them separately using what you learned about LS fitting in MATLAB, and
  • Combine the fitted models as a whole.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by