Identifying smoothness on different plots without jumps or kinks
2 views (last 30 days)
Show older comments
Jorge Luis Paredes Estacio
on 28 Dec 2023
Commented: Jorge Luis
on 1 Jan 2024
Hello, I am processing different signals from which I am estimating the Empirical Cumulative Function to find specific trends like the one shown in Figure 1 where some signals show a smooth plot. Meanwhile, other signals can show jumps or kinks in the Empirical Cumulative Function like the figure 2. Is there a function that help to identify these two cases using the F(x) data for each component?. This identification would say that the first case is a proper signal for having an smooth trend. On the other hand, the second case can be identified as an unsuitable signal for having jumps or kinks in Empirical Cumulative Distribution fuunction. I would appreciate the help. I attached an example of the Empirical Cumulative values F(x) for the first case (f1) and second case (f2) as txt as an example that would help identify any of those cases mentioned. I would appreciate the help.
0 Comments
Accepted Answer
Sulaymon Eshkabilov
on 28 Dec 2023
Here is one solution with ftnlm():
D2 = load('f2.txt');
X2 = linspace(-25, 25, numel(D2));
% Data shows that a Nonlinear Sigmoid type nonlinear fit model is the most suitable:
S_model = @(b, x) 1./(1 + exp(-(b(1) + b(2)*x)));
% Initial guess values for b values
b0 = [0, 0.5];
% Fit the model using fitnlm
FModel = fitnlm(X2, D2, S_model, b0);
% Display the results
disp('Model Parameters:');
FModel
% Plot the data and fitted sigmoid curve
figure;
plot(X2, D2, 'bo', 'DisplayName', 'Given Data');
hold on
% Let's compute the values of the fit model to show its performannce
X_vals = linspace(min(X2), max(X2), 100);
D2_fit = predict(FModel, X_vals');
plot(X_vals, D2_fit, 'r','LineWidth', 2, 'DisplayName', 'Fitted Sigmoid Curve');
xlabel('X');
ylabel('Y');
legend('show', 'Location', 'best');
grid on
2 Comments
More Answers (1)
Sulaymon Eshkabilov
on 29 Dec 2023
For f1.txt, the model formulation will be the best fit, e.g.:
D1 = load('f1.txt');
X1 = linspace(-25, 25, numel(D1));
% Data shows that a Nonlinear Sigmoid type nonlinear fit model is the most suitable:
S_model1 = @(b, x) 1./(1 + exp(-(b(1) + b(2)*x)));
% Initial guess values for b values
b0 = [0, 0.5];
% Fit the model using fitnlm
FModel1 = fitnlm(X1, D1, S_model1, b0);
% Display the results
disp('Model Parameters:');
FModel1
% Plot the data and fitted sigmoid curve
figure;
plot(X1, D1, 'bo', 'DisplayName', 'Given Data');
hold on
% Let's compute the values of the fit model to show its performannce
X_vals = linspace(min(X1), max(X1), 100);
D1_fit = predict(FModel1, X_vals');
plot(X_vals, D1_fit, 'r','LineWidth', 2, 'DisplayName', 'Fitted Sigmoid Curve');
xlabel('X');
ylabel('Y');
legend('show', 'Location', 'best');
grid on
4 Comments
Alex Sha
on 31 Dec 2023
Edited: Alex Sha
on 31 Dec 2023
Try the fitting function below:
n=1
Sum Squared Error (SSE): 0.198265382635044
Root of Mean Square Error (RMSE): 0.0213245660245507
Correlation Coef. (R): 0.99903177402219
R-Square: 0.998064485505925
Parameter Best Estimate
--------- -------------
p0 0.987904925538442
a1 -0.976370688703938
b1 5.01866411918097
c1 1.73892866026451
n=2
Sum Squared Error (SSE): 0.0198251724593009
Root of Mean Square Error (RMSE): 0.00674318760195012
Correlation Coef. (R): 0.999903226259401
R-Square: 0.999806461883958
Parameter Best Estimate
--------- -------------
p0 0.340506688986253
a1 -0.33422435435035
b1 1.00705898018223
c1 0.346758083442965
a2 0.652548080384559
b2 -28.7898530254341
c2 -9.96361274247002
n=3
Sum Squared Error (SSE): 0.00665429785589847
Root of Mean Square Error (RMSE): 0.0039066803101404
Correlation Coef. (R): 0.99996751905745
R-Square: 0.999935039169911
Parameter Best Estimate
--------- -------------
p0 0.320693681605882
a1 -0.319481310561844
b1 1.64165756141301
c1 0.575821065083703
a2 0.0732506083073871
b2 -0.224274083494237
c2 -0.0508621405696974
a3 0.604308733522548
b3 -28.7896426138829
c3 -9.95835330008731
Jorge Luis
on 1 Jan 2024
Thank you so much. Happy New year :). n is the number of iterations. How do you set the this n value in the fitnlm function in MATLAB. Thank you for your response.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!