Help with fitting a exp function

1 view (last 30 days)
simon
simon on 28 Apr 2014
Commented: Star Strider on 28 Apr 2014
Hi,
I'm trying to fit my data with an exp equation.
Since data gives some noise before the initial (max) value, i was trying to make a filter to cut the data before this max value out with the following code:
function test_amplitude
close all; clc
data = load('enkelt_linie_str.csv');
depth = data(:,1);
amplitude = data(:,2);
k = amplitude==max(amplitude);
filter = depth>depth(k);
amplitude = amplitude(filter)
depth = depth(filter)
% initial values
lambda0 = 1;
A0 = max(amplitude);
p0 = [A0 lambda0];
error = (@(p) sum(power(amplitude-p(1).*exp(-p(2)*depth),2)));
p = fminsearch(error,p0)
A = p(1);
lambda = p(2);
plot(amplitude,depth,'b-'); hold on; axis ij
plot(A*exp(-lambda*depth),depth,'r-')
The fit works without the filter (line 7 to 11) but its a aweful fit and with the filter it gives very small values in return.
I hope you guys can help.
And thanks in advance
/Simon
  2 Comments
Image Analyst
Image Analyst on 28 Apr 2014
You forgot to attach your csv file, so probably no one will try anything until you attach it.
Star Strider
Star Strider on 28 Apr 2014
With simulated data and added noise, it works fine for me. How large are your data sets? How large are they after filter?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!