Derivative of the incoming sensor data for a duration of 200ms

조회 수: 1 (최근 30일)
Pooja Nath
Pooja Nath 2021년 6월 13일
I need to find the derivative of accelerometer sensor data coming via the serial port in real time for a duration of 200ms.
I get 69 samples per second but the processing can delay and reduce the samples. Iam not able to figure out how do I calculate the derivative with the time. I could calculate the moving average but not the derivative. I cannot simply assume the time and go for code. I have used 11 accelerometer sensors.
Here is the code:
s = serial('COM5','BaudRate',115200);
fopen(s);
%display data
k=1;
for j=0:inf
for i=1:34
data(i)=str2double(fscanf(s));
display(data);
pause(0.01)
end
% detect a sync bit
B=data(1,1);
if B==1000
D(k,:)=data; k=k+1;
else
continue;
end
% for three point moving average
if k >=4
V=D(k-3:k-1,:);
mv(k-3,:)=sum(V)./3;
display(mv);
else
continue;
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Counter and Timer Input and Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by