필터 지우기
필터 지우기

Noisy plot after deviation (no sensor)

조회 수: 5 (최근 30일)
Bruce Rogers
Bruce Rogers 2021년 6월 9일
댓글: Mathieu NOE 2021년 6월 15일
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
Bruce Rogers
Bruce Rogers 2021년 6월 10일
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 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
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
Bruce Rogers
Bruce Rogers 2021년 6월 15일
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 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
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');
  댓글 수: 1
Bruce Rogers
Bruce Rogers 2021년 6월 10일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Antennas, Microphones, and Sonar Transducers에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by