How do I correctly find parameters using the fittype function without it just using my initial guesses?
Show older comments
I am brand new to MatLab, and I am trying to fit a Power Spectral Density of the brownian motion in an optical trap with a Lorenzian function. I need to find the variables f0 and r. Everytime I guess a value, the function just spits out the guess I gave it. The guesses I have here for r and f0 (300,000 and 200) are around what the actual values should be. Does anyone have suggestions on how to fix my code so the fit it produces is finding the best values of r and f0 without just using the values I fed it?
data = readtable("PSmeas2 6.26.25.csv")
fs = 32000
N = height(data)
t = data.Time_s_
xdiff = data.XDIFF_V_
ydiff = data.YDIFF_V_
[pxx,f] = periodogram(xdiff,hann(height(data)),height(data),fs)
k = 1.380649 * 10^(-23);
T = 297.95;
b = 3 * pi * 0.91*10^-3 * 2*10^-6;
ft = fittype(@(r,f0,f) r^2 * k * T ./ (pi^2 * b * (f0^2 + f.^2)),...
'independent', {'f'}, 'dependent', {'pxx'});
result = fit(f(4:end),pxx(4:end),ft,'StartPoint', [300000,200])
%plot(result,f(4:end),pxx(4:end), 'fit')
Yresults = result(f);
loglog(f,pxx, ".")
hold on
loglog(f,Yresults)
Accepted Answer
More Answers (0)
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!