1

我目前正在研究一个 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
4

1 回答 1

1

您是否尝试过中值过滤器?

如果你能找到一个好的窗口宽度,它可能会比你正在执行的移动平均线好一点。

例如:

Avg([1 100 1]) = 34;
Median([1 100 1) = 1;

Matlab medfilt1

于 2012-05-16T07:12:05.750 回答