From: nesco on
Hi all,

I'm trying to fit some data with a double exponential function delayed
on the x-axis. That is, the double exponential should be zero for x<x0
and then rise (and later decay) with double exponential behaviour.
Thus, besides fitting the amplitude and the rise and decay time
constants of the exponentials, the other parameter I want to fit is
the position on the x-axis where the function rises. And there is also
my problem!

I wrote a simple function which looks like this:

--------------------------------------------------------------------
function SE = singlexp_embeddelay(pars,t)
% pars = [P t_delay]
% P parameter vectors containing [Amplitude tau_rise tau_decay]

P = pars(1:3);
t_delay = pars(4);
t0 = t(1);
tend = t(end);
SamplIntMS = t(2)-t(1);

timeMS = (0:SamplIntMS:tend)';
idx_delay = find(timeMS==t_delay);

E = zeros(length(timeMS),1);
SE = zeros(length(timeMS),1);

E = (P(1)*(exp(-(timeMS-t_delay)/P(3))-exp(-(timeMS-t_delay)/
P(2)))); % first exponential

SE = cat(1,zeros(idx_delay-1,1),E(idx_delay:end));
----------------------------------------------------------------------------------------

What I do is then defining a function handle:

> fun = @(beta,t) singlexp_embeddelay(beta0,t)

defining the vector of parameters beta0, and finally trying to fit the
data:

> beta = nlinfit(time,avgsweep,fun,beta0)

But what I get is:

Warning: Rank deficient, rank = 0, tol =0.0000e+000.
> In nlinfit>LMfit at 294
In nlinfit at 166
Warning: The Jacobian at the solution is ill-conditioned, and some
model parameters may not be estimated well (they are not
identifiable).
Use caution in making predictions.

And beta, the vector of fitted parameters looks exactly the same as
beta0. Under some circumstances (by fitting the sum of two delayed
double-exponentials, which is my final goal) I managed to make nlinfit
fitting the amplitude, rise and decay time constants, but I definitely
do NOT managae to make matlab estimate the delay on the x-axis.

What do I do wrong?

Sorry for the long post, any help is appreciated.

Have a nice day
antonio.