clear all
close all
clc

xsig = linspace(28.4490,40,500);
xlinear = linspace(5,28.4490,500);
xconst = linspace(40,60,500);
x3 = linspace(5,55,500);


xsig_2 = linspace(16.89733,28.449,500);
xlinear_2 = linspace(28.449,51.8972,500);
xconst_2 = linspace(0,16.89733,500);

a1 = 0.35;
b1 = 40; % negativo do ponto de centro
c1=1/5;

a2 = 0.5;
b2 = 25;
c2 = 1/3;

a3 = 0.3;
b3 = 30;
c3 = 1/3;

ysig = (1./(c1*(1+exp(-a1*(xsig - b1)))) + 0.5);
ylinear = ((0.025)*xlinear - (0.125));
yconst = linspace(3,3,500);
y3 = 1./(c3*(1+exp(-a3*(x3 - b3))));


a1_2 = 0.35;
b1_2 = 16.89733; % negativo do ponto de centro
c1_2=1/5;

ysig_2 = (1./(c1_2*(1+exp(a1_2*((xsig_2) - b1_2)))) + 0.5);
ylinear_2 = (-(0.025)*(xlinear_2) + (1.29743));
yconst_2 = linspace(3,3,500);

figure('position', [80 80 600 350], 'color', [1 1 1])
plot(xconst, yconst, 'g', 'LineWidth',1)
hold on
plot(xconst_2, yconst_2, 'b', 'LineWidth',1)
hold on
plot(xlinear, ylinear, 'g', 'LineWidth',1)
hold on
plot(xsig, ysig, 'g', 'LineWidth',1)
hold on
plot(xlinear_2, ylinear_2, 'b', 'LineWidth',1)
hold on
plot(xsig_2, ysig_2, 'b', 'LineWidth',1)
hold on

plot(xconst, yconst, 'g', 'LineWidth',1)
hold on
plot(xconst_2, yconst_2, 'b', 'LineWidth',1)
hold on
plot(xlinear, ylinear*4, 'g', 'LineWidth',1)
hold on
plot(xsig, ysig*4, 'g', 'LineWidth',1)
hold on
plot(xlinear_2, ylinear_2*4, 'b', 'LineWidth',1)
hold on
plot(xsig_2, ysig_2*4, 'b', 'LineWidth',1)
hold on
 
grid on
axis ([0 55 0 3.5]);
axis normal

legend('Stability deviation', 'Instability approach')

AxisFontName = 'L M Roman10';
AxisFontSize = 8;

set(gca, 'FontName', AxisFontName, 'FontSize', AxisFontSize)

title('Feedback Generation', 'Fontsize', AxisFontSize, 'FontName', AxisFontName)
xlabel('Distance, s [mm]', 'Fontsize', AxisFontSize, 'FontName', AxisFontName)
ylabel('Force [N]', 'Fontsize', AxisFontSize, 'FontName', AxisFontName)

export_fig force_generation -pdf -transparent
