MATLAB中的错误处理和插值

时间:2012-05-13 17:27:29

标签: matlab error-handling interpolation data-processing

我正在研究一个MATLAB脚本,该脚本可以发现运动传感器的错误,其中数据“翻转”半球,并记录它应该是什么的倒数。除此之外,还有一个过渡期,传感器在此“翻转”过程中继续记录值。

下面可以看到一个例子(x轴是样本中的时间,y是传感器与传感器的距离,单位为英寸):

enter image description here

我目前的进展如下:

enter image description here

数据错误已被抑制但仍与数据集的其余部分不一致。有人可以建议改进方法吗?

我的代码如下:

%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

1 个答案:

答案 0 :(得分:0)

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

如果你能找到一个好的窗口宽度,它应该比你正在表现的移动平均值好一点。

例如:

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

Matlab medfilt1