Noisy plot after deviation (no sensor)
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello,
i'm trying to get the acceleration from position and time data. (I dont get the data from an accelerometer, this would explain the noise! )The plot seems to be really noisy, is there a good explanation? Shouldn't I be able to see a perfect sine wave? I'm thankful for every idea, thanks!
Here my code and a picture of the result
h = 1:height(z_irl);
for i = 1:height(z_irl)
t(i) = 0.004 * h(i);
end
t = t';
dt = diff(t);
dz_irl = diff(z_irl);
%velocity
vel_irl = dz_irl./dt(1:end);
dvel_irl = diff(vel_irl);
%acceleration
acc_irl = dvel_irl./dt(2:end);
acc_irl(numel(t)) = 0;
figure(4)
plot(t,acc_irl,'-b')
xlabel('time')
ylabel('acceleration')
hold off
댓글 수: 7
Scott MacKenzie
2021년 6월 10일
@Bruce Rogers I'm going to post a solution in a minute that shows the velocity and acceleration as a sine wave.
채택된 답변
Mathieu NOE
2021년 6월 10일
hello
my suggestion, with some smoothing at all stages :
z_irl = readmatrix('z_irl_data.txt');
z_irls = smoothdata(z_irl,'gaussian',100);
dt = 0.004;
t = dt * (1:length(z_irl));
t = t';
tiledlayout(3,1);
% position
nexttile;
plot(t,z_irl, t, z_irls);
xlabel('time');
ylabel('position');
% velocity
vel_irl = gradient(z_irls,dt);
vel_irls = smoothdata(vel_irl,'gaussian',100);
nexttile;
plot(t, vel_irl, t, vel_irls);
xlabel('time');
ylabel('velocity');
% acceleration
acc_irl = gradient(vel_irls,dt);
acc_irls = smoothdata(acc_irl,'gaussian',100);
nexttile;
plot(t, acc_irl, '-b', t, acc_irls);
xlabel('time');
ylabel('acceleration');
I don't think you can really get a sinusoidal acceleration... seems more to be trapezoidal somehow
댓글 수: 4
Mathieu NOE
2021년 6월 15일
Hello Bruce
ok , I just wanted to show you the options , of course you decide which one fits better your needs
have a good day
추가 답변 (1개)
Scott MacKenzie
2021년 6월 10일
@Bruce Rogers I added some filtering using MATLAB's smoothdata function. The result is a pretty good sine wave both for velocity and acceleration. smoothdata "returns a moving average of the elements of a vector using a fixed window length that is determined heuristically". The windows length is not specifiied, but you can play with this using parameters described in the documentation. The result is below. Note that the new waveforms experience both phase shift and attenuation as a result of the filtering. The acceleration waveform is very attenuated, indicating noise as large spikes in the raw data. Anyway, hope this helps. Good luck.
z_irl = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/647435/z_irl_data.txt');
t = 0.004 * (1:length(z_irl));
t = t';
dt = [0; diff(t)];
tiledlayout(3,1);
% position
nexttile;
plot(t,z_irl);
xlabel('time');
ylabel('position');
% velocity
dz_irl = [0; diff(z_irl)];
vel_irl = dz_irl./dt;
vel_irl = smoothdata(vel_irl); % filter using moving average
nexttile;
plot(t, vel_irl);
xlabel('time');
ylabel('velocity');
% acceleration
dvel_irl = [0; diff(vel_irl)];
acc_irl = dvel_irl./dt;
acc_irl = smoothdata(acc_irl); % filter using moving average
nexttile;
plot(t, acc_irl, '-b');
xlabel('time');
ylabel('acceleration');
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!