Low Pass Filter Accelerometer Data

5 次查看(过去 30 天)
Hi All,
attached it my code for gathering xyz accelerometer data from a serial stream. The code works well, plotting x,y,z data along with the vector sum of all three plots. However, I would like to add a simple low pass filter to smooth the data out a bit, which is causing me some difficulties,
cut_off=1e-3/delay/2;
order=16;
h=fir1(order,cut_off);
% start time tic;
loop = 0; while ishandle(graph1)
xyz = fscanf(s, '%f %f %f')';
if (loop < 10)
loop = loop + 1;
continue;
elseif (loop == 10)
loop = 0;
end
if(~isempty(xyz))
index = index + 1;
time(index) = toc;
if (numel(xyz) < 3)
continue;
else
x(index) = ((xyz(1, 1))+23)/258;
y(index) = ((xyz(1, 2))+8)/260;
z(index) = ((xyz(1, 3))+26)/253;
vs(index) = sqrt((((xyz(1, 1))+26)/253)^2+(((xyz(1, 2))+26)/253)^2+(((xyz(1, 3))+26)/253)^2);
%vsf(index)=conv(vs(index),h);
end
end
end
fclose(s); end
I'm getting the following message 'In an assignment A(:) = B, the number of elements in A and B must be the same'
How do I go about implementing the LPF correctly ?
Thanks,
  1 个评论
Jose Marques
Jose Marques 2017-9-9
Can you fix the code layout? There is some setence that is not in code format

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by