-
Notifications
You must be signed in to change notification settings - Fork 0
/
createFit5.m
55 lines (49 loc) · 1.53 KB
/
createFit5.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function [ir] = createFit5(ltex,ms, nmod, ws, mp, h )
% JAH 9/2020 make a fit between Noise Model and Real Data
% ms = wspeed for noise model
% nmod = dB noise for model
% ws = windspeed for real data
% mp = noiseleve for real data
%CREATEFIT4(XDATA,YDATA)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : ms
% Y Output: nmod
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 19-Sep-2020 13:29:43
%% Fit: 'fir to noise model'.
[xData, yData] = prepareCurveData( ms, nmod );
% fit the Noise Model
ft = fittype( 'poly5' );
opts = fitoptions( 'Method', 'LinearLeastSquares' );
opts.Normalize = 'on';
opts.Robust = 'LAR';
[fitresult, gof] = fit( xData, yData, ft, opts );
% find residual between model fit and real data
resid = [];
for i = 1 : length(mp)
resid(i) = mp(i) - fitresult(ws(i));
end
std95 = 2*std(resid);
ir1 = find(abs(resid) < std95);
irhigh = find(resid < std95);
resid2 = resid(ir1);
std952 = 2*std(resid2);
ir2 = find(abs(resid2) < std952);
ir = ir1(ir2);
% Plot fit with data.
plot(h,ws(ir),mp(ir),'bo')
plot(fitresult,'k');
% plot(fitresult, xData, yData );
xlim([0 1.05*max(ws)]);
xlabel( 'wind speed', 'Interpreter', 'none' );
ylabel( ltex, 'Interpreter', 'none' ); grid on
% figure;
% histogram(resid(ir(ir2)),1000)
% legend( h, 'ydata vs. xdata', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% abel axes