我目前正在研究一个 MATLAB 脚本,该脚本可以从运动传感器中发现错误,其中数据“翻转”半球并记录它应该是什么的倒数。除此之外,还有一个过渡期,传感器在此“翻转”过程中继续记录值。
下面是一个示例(x 轴是以样本为单位的时间,y 是以英寸为单位的传感器与传感器的距离):
我目前的进展如下:
数据错误已被抑制,但仍与数据集的其余部分不一致。有人可以提出改进的方法吗?
我的代码如下:
%Create counter variable
n = 1;
%Find length of the matrix under test
size = length(mTest);
intVals = zeros(size,1);
for n = 1:size
%Round all of the values recorded to the nearest integer (inch)
intVals(n,1) = round(mTest(n,1));
end
%Find the mode of the integers to have a reference point against the errors
ref = mode(intVals);
%Create a sample to put the new `fixed` data into
mFix1 = zeros(size,1);
for n = 1:size
checkVal = mTest(n,1);
%If the raw value is not within an inch either side of the reference
%point check for complete wrapping by inverting the data.
if checkVal < (ref-1)
checkVal = -checkVal;
end
if checkVal > (ref+1);
checkVal = -checkVal;
end
%If the data is still outside of the range of acceptable values create
%an estimate based upon the last 3 samples
if checkVal < (ref-1) && checkVal > (ref+1)
m(1,1) = mFix1(n-3,1);
m(2,1) = mFix1(n-2,1);
m(3,1) = mFix1(n-1,1);
checkVal = mean(m);
end
%Output the data after error checking
mFix1(n,1) = checkVal;
end