Azzera filtri
Azzera filtri

Noisy plot after deviation (no sensor)

5 visualizzazioni (ultimi 30 giorni)
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 Commenti
Bruce Rogers
Bruce Rogers il 10 Giu 2021
thanks for proving my code. It looks really strange to me, it's really not the result I expected. I hope there is a way to remove the noise in the velocity data, maybe a filter or something like that.
Thank you for your help!
Scott MacKenzie
Scott MacKenzie il 10 Giu 2021
@Bruce Rogers I'm going to post a solution in a minute that shows the velocity and acceleration as a sine wave.

Accedi per commentare.

Risposta accettata

Mathieu NOE
Mathieu NOE il 10 Giu 2021
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 Commenti
Bruce Rogers
Bruce Rogers il 15 Giu 2021
Hello Mathieu, this look great thanks for your help! But I think I have to work with the triangular shaped acceleration, because otherwise the acceleration and velocity are too low as they should be in theory. (v = -25 to 25 mm/s and a = -12.5 to 12.5 mm/s^2)
Mathieu NOE
Mathieu NOE il 15 Giu 2021
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

Accedi per commentare.

Più risposte (1)

Scott MacKenzie
Scott MacKenzie il 10 Giu 2021
@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');
  1 Commento
Bruce Rogers
Bruce Rogers il 10 Giu 2021
This is really nice, I was also reading about the smoothdata function, just when you posted your answer. It's great, but it fakes the result a lot. Like the velocity should go from -25 to 25 and the acceleration from -12.5 to 12.5.
I thought about splitting the velocity vector in smaller vectors of 5 or 10 elements and get the average, so I can get a good signal, but also reduce the noise.

Accedi per commentare.

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by