Bad results after curve fitting a spectrum to a lorentzian curve.
3 views (last 30 days)
Show older comments
I am trying to fit a power spectrum to a custom equation of a Lorentzian form using the curve fitting toolbox. I have used the NonLinearLeastSquares and LinearLeastSquares methods with the same results. If I don't specify starting points the values are far off what it is expected, if I specify starting points (with the NonLinearLeastSquares method) the results are the same starting points. Am I missing something? I have tried even fitting just one variable with no success.
I have attached two variables with the type of signal to fit and below is my code:
if true
%Fitting the curve to a lorentzian curve
f = FitFreq;
Sx = fittype('((1.3806488e-23*300/k)/(pi*Q*fo))/((1-(f/fo)^2)^2+(f/(Q*fo))^2)',...
'indep','f');
options = fitoptions('Method','NonlinearLeastSquares');
[fitmodel,goodness,output] = fit(f,FitData,Sx,options);
Qf = fitmodel.Q
kf = fitmodel.k
fof = fitmodel.fo
FittedTo = ((1.3806488e-23*300/kf)/(pi*Qf*fof))./((1-(f/fof).^2).^2.+(f/(Qf*fof)).^2);
%Plotting of the curves
plot(FitFreq,FitData,'b','LineWidth',0.5)
hold on
plot(FitFreq,FittedTo, 'r','LineWidth',0.5)
ylabel('Magnitude (AU)')
xlabel('frequency (Hz)')
hold off
end
0 Comments
Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!