Strange form of increasing when derivating sine waves
Mostra commenti meno recenti
Hello everyone, I'm trying to get coordinates for a robot movement from a sine wave. Now when I change the duration of a period, the coordinates seem to drift, as shown in the picture figure 5. Can anyone explain? Or is there a mistake in my code? Thanks for your help, I'm thankful for every idea.
I'm using Matlab R2020b academic use.
clear;
b = 4; %Factor for changing the duration of period
t = 0.05; % Frequenz
A = 50; %Amplitude
x = 0:t:10*pi;
y = A*sin(b*x);
T = (1:length(x))*t;
figure(1)
plot(T,y,'.')
xlabel('time')
ylabel('distance')
%%
vel = gradient(y)./gradient(x);
figure(2)
plot(T,vel,'.')
xlabel('time')
ylabel('velocity')
%%
acc = gradient(vel)./gradient(x);
figure(3)
plot(T,acc,'.')
xlabel('time')
ylabel('acceleration')
acc = acc';
%xlswrite('Acceleration.xlsx',acc);
acc = acc';
%%
%velocity Cosinus Figure
v = zeros(1,length(acc));
v(1,1) = b*A * cos(0);
l_v = 1:length(acc);
for i = 2:length(acc)
v(i) = ((acc(i)+acc(i-1))/2) * t + v(i-1);
end
figure(4)
scatter(T,v,'.')
xlabel('time')
ylabel('velocity')
v = v';
%xlswrite('Velocity.xlsx',v);
v = v';
%%
%distance Sinus Figure
s = zeros(1,length(v));
s(1,1) = b*sin(0);
for i = 2:length(v)
s(i) = ((v(i)+v(i-1))/2) * t + s(i-1);
end
figure(5)
scatter(T,s,'.')
xlabel('time')
ylabel('distance')
%%
s = s';
%xlswrite('idealwaves.xlsx',s)

4 Commenti
Scott MacKenzie
il 9 Giu 2021
I'm not really following the math here, but the drift disappears for the 5th plot if you remove the last term in the calculation for s. That is, by changing
s(i) = ((v(i)+v(i-1))/2) * t + s(i-1);
to
s(i) = ((v(i)+v(i-1))/2) * t;
New Figure 5:

Bruce Rogers
il 10 Giu 2021
Jan
il 10 Giu 2021
The term (v(i)+v(i-1)) / 2 cannot be the maximum value of v. It is likely that this has more influence on the positive part than on the negative part (or vice versa). Therefore such drifts are typical for numerical integrations of accelerations or velocities. You are not the first person, who observes this.
There is no magic solution. To reduce the influence of drifting, you need absolute position values as a calibration.
J. Alex Lee
il 10 Giu 2021
by the way you should be able to accomplish your numerical integration with cumtrapz, instead of manually summing
s = b*sin(0) + cumtrapz(T,v)
If you want to understand the "drift" you can systematically reduce your value of t (sample faster) to see how well your integrated position matches the analytical expectation.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!