How to smooth the plot graph?
Mostrar comentarios más antiguos
Hello everyone,
i need help on how to smoothen the ouput graph
here is the code :
i=0;
thetaf = -0.005054045; % final angle
for t = 0:0.01:0.1 % 1 phase
tf=0.1; % final time
theta0 = 0.00885953175658278; %initial angle
a0 = theta0;
i = i+1;
a1 = 0; % velocity value
a2 = (3/tf^2)*(thetaf-theta0); % cubic coefficient
a3 = (-2/tf^3)*(thetaf-theta0); %cubic coefficient
time(i,1) = t;
theta(i,1) = a0 + a1*t + a2*t^2 + a3*t^3; %position
% thetadot(i,1) = a1 + 2*a2*t + 3*a3*t^2; % velocity
% thetaddot(i,1) = 2*a2 + 6*a3*t; % acceleration
end
for t = 0.2:0.01:0.3 % 2 phase
tf=0.3;
theta0 = 0.105469202; %initial angle
a4 = theta0;
a5 = 0.966096702; %velocity
a6 = (3/tf^2)*(thetaf-theta0);
a7 = (-2/tf^3)*(thetaf-theta0);
i = i+1;
time(i,1) = t;
theta(i,1) = a4 + a5*t + a6*t^2 + a7*t^3; %position
% thetadot(i,1) = a5 + 2*a6*t + 3*a7*t^2; % velocity
% thetaddot(i,1) = 2*a6 + 6*a7*t; % acceleration
end
for t = 0.4:0.01:0.5 % 3 phase
tf=0.5;
theta0 = 0.079567522; %initial angle
a8 = theta0;
a9 = -0.1295084;
a10 = (3/tf^2)*(thetaf-theta0);
a11 = (-2/tf^3)*(thetaf-theta0);
i = i+1;
time(i,1) = t;
theta(i,1) = a8 + a9*t + a10*t^2 + a11*t^3; %position
% thetadot(i,1) = a9 + 2*a10*t + 3*a11*t^2; % velocity
% thetaddot(i,1) = 2*a10 + 6*a11*t; % acceleration
end
for t = 0.6:0.01:0.65 % 4 phase
tf=0.6;
theta0 = 0.040306469; %initial angle
a12 = theta0;
a13 = -0.196305266; % velocity value
a14 = (3/tf^2)*(thetaf-theta0);
a15 = (-2/tf^3)*(thetaf-theta0);
i = i+1;
time(i,1) = t;
theta(i,1) = a12 + a13*t + a14*t^2 + a15*t^3; %position
% thetadot(i,1) = a13 + 2*a14*t + 3*a15*t^2; % velocity
% thetaddot(i,1) = 2*a14 + 6*a15*t; % acceleration
end
for t = 0.70:0.01:0.73 % 5 phase
tf=0.73;
theta0 = -0.074996897; %initial angle
a16 = theta0;
a17 = -1.153033654; % velocity value
a18 = (3/tf^2)*(thetaf-theta0);
a19 = (-2/tf^3)*(thetaf-theta0);
i = i+1;
time(i,1) = t;
theta(i,1) = a16 + a17*t + a18*t^2 + a19*t^3; %position
% thetadot(i,1) = a17 + 2*a18*t + 3*a19*t^2; % velocity
% thetaddot(i,1) = 2*a18 + 6*a19*t; % acceleration
end
for t = 0.80:0.01:0.87 % 6 phase
tf=0.87;
theta0 = -0.043367639; %initial angle
a20 = theta0;
a21 = 0.24330198; % velocity value
a22 = (3/tf^2)*(thetaf-theta0);
a23 = (-2/tf^3)*(thetaf-theta0);
i = i+1;
time(i,1) = t;
theta(i,1) = a20 + a21*t + a22*t^2 + a23*t^3; %position
% thetadot(i,1) = a21 + 2*a22*t + 3*a23*t^2; % velocity
% thetaddot(i,1) = 2*a22 + 6*a23*t; % acceleration
end
for t = 0.9:0.01:1 % 7 phase
tf=1;
theta0 = 0.002141521; %initial angle
a24 = theta0;
a25 = 0.325065431; % velocity value
a26 = (3/tf^2)*(thetaf-theta0);
a27 = (-2/tf^3)*(thetaf-theta0);
i = i+1;
time(i,1) = t;
theta(i,1) = a24 + a25*t + a26*t^2 + a27*t^3; %position
% thetadot(i,1) = a25 + 2*a26*t + 3*a27*t^2; % velocity
% thetaddot(i,1) = 2*a26 + 6*a27*t; % acceleration
end
figure(1)
plot(time,theta)
xlabel('Time(t,sec)','FontSize',14)
ylabel('Angle(degrees)','FontSize',14)
title('\it{Position Profile for Hip}','FontSize',16)
Respuestas (1)
Erivelton Gualter
el 10 de Mayo de 2019
0 votos
After you plot the position profile add the following code:
for i=5:30;
p = polyfit(time, theta,i);
y1 = polyval(p,time);
cla;
plot(time,theta, time, y1)
pause;
end
This is basic a polynomial fit data function.
So for each iteration it will fit a polynomial of degree i. (You need to press enter to continue). Then you can select the best polynomial order.
For example, if you chose 30th, you can add the following code:
p = polyfit(time, theta,30);
y1 = polyval(p,time);
figure;
plot(time,theta, time, y1)
Categorías
Más información sobre Polynomials en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!