How to fit 6 curves simultaneously to solve for 2 unknowns?

8 views (last 30 days)
y=(1-exp(-0.5*Phi*Gain*(x-TimeDelay)^2))*Amax
Gain and TimeDelay are unknown. x is time (T1-T6) and y is response (F1-F6)(source of noise). Phi is different for each curve, and Amax is constant.
Attached is a sample dataset. The values for Phi and the Amax for this dataset are found to the right of the data.
I tried the Curve Fitting Toolbox, but it seems to be designed for one trace at a time. I can get the curves to fit for the first 4 traces but not the last 2. However, I need to get one gain value and one TimeDelay that is the best (or least bad) fit across all traces. I don't know what function to use.
Thank you! Any help is appreciated.
***note: I am editing the question with the comments from Walter taken into consideration. I initially typed the equation incorrectly (wrote Amax was negative and it isn't) and I also thought TimeDelay was constant and it isn't.
  2 Comments
Delores Davis
Delores Davis on 7 Jun 2015
My bad. I copied the data to an excel file and then forgot to attach it. It's here now.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 7 Jun 2015
Solve for Gain to get
Gain = -2*ln((Amax+y)/Amax)/(Phi*(x-TimeDelay)^2)
then make a single table of all of the values over all of the datasets, and run a least-squared fit. Looks like the solution to that would just be the mean of those values.
Per-variable confidence bounds is not as easy to compute. If I understand your setup correctly, "y" should be treated as having noise, but not the others?
  46 Comments
Delores Davis
Delores Davis on 29 Jun 2015
I am sucking at writing the code to add jitter to the other parameters. Need your help.
jitterx = linspace(-5E-5,5E-5, 10001);
r = zeros(length(jitterx),2); s = zeros(length(jitterx),1);
for K = 1 : length(jitterx); [r(K,:), s(K,:)] = fminsearch(@(x) Fn2(x(1), x(2), jitterx(K)), bestp); end
plot(jitterx,r(:,1))
plot(jitterx,r(:,2))
c = polyfit(jitterx(:), r(:,2), 1)
jittery = linspace(-5E-5,5E-5, 10001);
u = zeros(length(jittery),2); v = zeros(length(jittery),1);
for L = 1 : length(jittery); [u(L,:), v(L,:)] = fminsearch(@(y) Fn2(y(1), y(2), jittery(L)), bestp); end
plot(jittery,u(:,1))
plot(jittery,u(:,2))
d = polyfit(jittery(:), u(:,2), 1)
jitterz = linspace(-5E-5,5E-5, 10001);
p = zeros(length(jitterz),2); q = zeros(length(jitterz),1);
for M = 1 : length(jitterz); [p(M,:), q(M,:)] = fminsearch(@(z) Fn2(z(1), z(2), jitterz(M)), bestp); end
plot(jitterz,p(:,1))
plot(jitterz,p(:,2))
e = polyfit(jitterz(:), p(:,2), 1)
Essentially, I am learning how to make Matlab stay 'busy' and not learning much else.
Delores Davis
Delores Davis on 30 Jun 2015
Step #1, minimum value 918155 near (Gain = 0, TimeDelay = 0)
Step #1: widening Gain search lower
Step #1: widening TimeDelay search lower
Step #2, minimum value 2.05049e+07 near (Gain = 0.003, TimeDelay = 0.0001)
Step #2: widening TimeDelay search higher
Step #3, minimum value 6.31486e+06 near (Gain = 0.00012, TimeDelay = 0.000106)
Step #3: widening TimeDelay search higher
Step #4, minimum value 498239 near (Gain = 4.8e-06, TimeDelay = 0.00010618)
Step #4: widening TimeDelay search higher
Step #5, minimum value 489409 near (Gain = 5.808e-06, TimeDelay = 0.000106185)
Step #5: widening TimeDelay search higher
Tried to test the reproducibility of this test on another animal, and it is obviously horrible, for un-obvious reasons. Do you have any idea why? I have attached the data for this other animal (wildtype so should fall into range with the data we've been working on).

Sign in to comment.

Categories

Find more on Audio Processing Algorithm Design 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!