fit two exponential decays with exponential function with shared time constant. in matlab

To fit two exponential decays with an exponential function that shares a time constant in MATLAB, you can use the curve fitting toolbox. Here's an example of how to do it:

main.m
% Generate data with two decaying exponential functions
t = 0:0.1:10; % Time vector
y1 = 5 * exp(-0.5 * t); % First decay
y2 = 3 * exp(-0.5 * t); % Second decay

% Combine the two decay functions
y = y1 + y2;

% Fit the data to the model
model = @(c, t) c(1) * exp(-0.5 * t) + c(2) * exp(-0.5 * t);
c0 = [1, 1]; % Initial guess for the coefficients
coefficients = lsqcurvefit(model, c0, t, y);

% Plot the results
fit1 = coefficients(1) * exp(-0.5 * t);
fit2 = coefficients(2) * exp(-0.5 * t);
fit = fit1 + fit2;

plot(t, y, 'ko', t, fit, 'r-');
legend('Data', 'Fitted curve');
xlabel('Time');
ylabel('Amplitude');
615 chars
23 lines

In this example, the model function represents the sum of two decaying exponentials, where c(1) and c(2) are the coefficients for the amplitudes of the decays. We use lsqcurvefit to estimate the coefficients that provide the best fit to the data.

Make sure you have the Curve Fitting Toolbox installed in MATLAB, as the lsqcurvefit function is part of this toolbox.

gistlibby LogSnag