FInding the breakpoint of a frequency spectra and its associated error
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I was wondering whether somebody could help me in finding the first breakpoint of a frequency spectra and its associated error. The spectra is as shown in the attached figure (spectrum.jpg). The spectrum should be fitted as shown in spectrum_fitted.jpg inorder to find the first breakpoint (labelled as A) so as to get the corresponding frequency which is about 1.2Hz (in figure spectrum_fitted.jpg). The fit might not be accurate and hence there would be an associated error in the value obtained for the frequency at A. So I would need both the value for frequency at A( first breakpoint) as well as its associated error. Wondering if that is possible.
The data used to get the frequency plot has been attached as data.mat
Thank you.
0 个评论
采纳的回答
Mathieu NOE
2021-2-1
hello
I combinde this
and fminsearch to create that code - seems to work finding the optimal values for break points
% load x and y data
load('data.mat');
xdata = xdata(:);
ydata = ydata(:);
% Init of fminsearch
a = max(xdata)/4;
b = max(xdata)*3/4;
global xdata ydata
x0 = [a,b];
x = fminsearch(@obj_fun, x0);
a_sol = x(1);
b_sol = x(2);
XI = [min(xdata),a_sol,b_sol,max(xdata)]; % vector of 1-D look-up table "x" points
YI = lsq_lut_piecewise( xdata, ydata, XI ); % obtain vector of 1-D look-up table "y" points
% plot fit
plot(xdata,ydata,'.',XI,YI,'+-')
legend('experimental data (x,y(x))','LUT points (XI,YI)')
title('Piecewise 1-D look-up table least square estimation')
function err = obj_fun(x)
global xdata ydata
XI = [min(xdata),x(1),x(2),max(xdata)]; % vector of 1-D look-up table "x" points
YI = lsq_lut_piecewise( xdata, ydata, XI ); % obtain vector of 1-D look-up table "y" points
Yint = interp1(XI,YI,xdata);
err = sum((Yint-ydata).^2);
end
0 个评论
更多回答(1 个)
Mahith Madhana Kumar
2021-2-1
2 个评论
Mathieu NOE
2021-2-1
hello again
well, there is no "reference" value for a , so I cannot say the error is the norm of a_ref-a_sol , because a_ref cannot be defined (or ?)
the only error we can define is : err = sum((Yint-ydata).^2); used in the function
but that is not specific to a but to the entire fit model
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!