Fit 2 exponential to a curve

14 views (last 30 days)
Chaitanya Jha
Chaitanya Jha on 21 Apr 2020
Commented: Image Analyst on 23 Apr 2020
Hi,
I am working on fitting algorithm to fit a double exponential to a given curve. These exponentails are RC time constants for two different combinations of R and C, so for R1*C1 the time constant is T1 and for R2*C2 the time constant is T2. Starting from point A in my top image below, the curve follows T1 till Point B, and from Point C (Point C would be much closer to Point B, but for clarity I have shown it to be further away from Point B) till Point D (or even further, but the curve is flat so it doesn't matter) the curve follows T2. The curve is obtained by experiment and I would like to find out Point B, Point C, T1 and T2. I have tried multiple fitting algorithms, nothing works, except for the one where I assume Point B and Point C coinside. The equation that works:
ft = fittype('S + A*((h*(1-exp((T-x)/T1))) + (1-h)*(1-exp((T-x)/T2)))','problem',{'S','A','T'});
fo = fit(x,y,ft,'problem',{Sx,Ax,Tx},'StartPoint',[1,10^-2,10^-2],'Lower',[0,10^-6,10^-6],'Upper',[1,10^-2,10^-2]);
Where:
Sx = Starting Amplitude [Known]
Ax = Final Amplitude [Known]
Tx = Starting Time [Known]
x = Data to fit [Independent Variable]
y = Data to fit [Dependent Variable]
h = coefficient 1 [ Min = 0, Max = 1] = Fraction of amplitude (Ax) that follows time constant T1 [where Point B and Point C are together]
T1 = coefficient 2 [ Min = 10^-6, Max = 10^-2] = Time constant for first combination of RC i.e. R1*C1
T2 = coefficient 3 [ Min = 10^-6, Max = 10^-2] = Time constant for second combination of RC i.e. R2*C2
Original Curve:
Zoomed in image of the fittied Curve, Red curve is Original Signal and Blue curve is the fitted curve. The dashed horizontal line in below image is the value of 'h' in above fitting algorithm that provides the seperation point between the RC time constants.
In the zoomed in image, it is clear that that fitted curve is slightly overestimating the first RC time constant T1 and underestimating the second RC time constant T2. In this particular example of the recorded data, shown above, the fitting algorithm works good and gives me expected values. But, in another example, shown below (again Red curve is original signal, Blue curve is fitted curve and dashed horizontal line is the value of 'h'), the fitting algorithm gives inaccurate results.
If there was a way I could seperate Point B and Point C (shown in first image) in the fitting algorithm, meaning T1 ends at Point B and T2 starts at Point C then I am quite sure I would get exact result in all recorded cases. Any help in this regard is highly aprriciated, thanks in advance!
  12 Comments
darova
darova on 22 Apr 2020
Sorry it was my best shot. I don't have more ideas
Chaitanya Jha
Chaitanya Jha on 22 Apr 2020
Thanks a lot for helping me! Highly appriciated :)

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 22 Apr 2020
Are you sure you're picking the right model? Maybe it's the "rate equation" instead of an exponential decay. I attach demos for each type of equation.
  2 Comments
Chaitanya Jha
Chaitanya Jha on 23 Apr 2020
Thanks! I tried the method but it is not working for me. I do not have any predictor variables and doing this only with x and y is not producing results rather giving me just errors. I will try again soon, it might take some time. I will update you if it works.
Image Analyst
Image Analyst on 23 Apr 2020
If you need me to do it, then attach your x and y in a .mat file with the paper clip icon.
save('answers.mat', 'x', 'y');

Sign in to comment.

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!