📄 datavala.m
字号:
function a_filt=datavala(alpha,temp,D);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ref: "Succeed at On-Line Validation and Reconstruction of Data"
% Ming T. Tham & Andrew Parr., Measurement and Control, 1994
% Chemical Engineering Progress.
%
% Written by A. Mitchell 15/1/96.
%
% n - the number of past values used in sequence is set by user,
% n=10
% BetaVal = 2
% DVal = 3
% GammaVal = 2
% for best performance
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a_filt=[];
n=10;
BetaVal=2;
DVal=3;
GammaVal=2;
for q=1:1:D
%
% initialize
%
Suma1=0;
Suma2=0;
S1=0;
S2=0;
SumDelta=0;
SumMed=0;
SumaBar=0;
SumStand=0;
if q > n+2
a=[temp(q),a(1:n+1)];
%
% Calculates values needed to find a distinct trend
%
ZOld = a(2) - a(3);
if ZOld > 0
SgnOld = 1;
elseif ZOld < 0
SgnOld = -1;
else
SgnOld = 0;
end
ZNew = a(1) - a(2);
if ZNew > 0
SgnNew = 1;
elseif ZNew < 0
SgnNew = -1;
else
SgnNew = 0;
end
%
% Calculates values needed to find a trend which isn't apparent
%
for i=1:1:n/2
Suma1 = Suma1 + a(i);
end
aBar1 = (2/n)*(Suma1);
for i=1+n/2:1:n
Suma2 = Suma2 + a(i);
end
aBar2 = (2/n)*(Suma2);
for i=1:1:n/2
S1 = S1 + ((a(i) - aBar1)^2 / ((n/2) - 1));
end
for i=1+n/2:1:n
S2 = S2 + ((a(i) - aBar2)^2 / ((n/2) - 1));
end
S = sqrt((S1 + S2) / 2);
Test = ((aBar1 - aBar2)*sqrt(n)) / (2*S);
%
% Tests for a distinct trend
%
if SgnNew == SgnOld
%
% Deals with oultiers for a distinct trend
%
Delta = abs(ZNew);
for i=1:1:n
SumDelta = SumDelta + abs(a(i+1) - a(1+i+1));
end
DeltaBar = (1/n)*(SumDelta)*(BetaVal);
if Delta > DeltaBar
filty = a(2) + (SgnNew)*(DeltaBar);
else
filty = a(1);
end
%
% Tests for trend that isn't apparent - value of 3.355 is a students
% t-test for alpha = 0.005 and n = 10.
%
elseif Test > 3.355
%
% Deals with outliers for a none apparent trend
%
aMed = median(a(:,2:n));
for i=1:1:n
SumMed = SumMed + abs(a(1+i) - aMed);
end
DeltaMed = (1/n)*(SumMed)*(DVal);
Med = (a(1) - aMed);
if Med > 0
SgnMed = 1;
elseif Med < 0
SgnMed = -1;
else
SgnMed = 0;
end
if abs(Med) > DeltaMed
filty = aMed + (SgnMed)*(DeltaMed);
else
filty = a(1);
end
%
% Otherwise No Trend
%
else
%
% Deals with outliers for no trend
%
for i=1:1:n
SumaBar = SumaBar + a(1+i);
end
aBar = (1/n)*(SumaBar);
for i=1:1:n-1
SumStand = SumStand + ((a(1+i) - aBar)^2) / (n - 1);
end
Stand = (GammaVal)*(sqrt(SumStand));
Bar = (a(1) - aBar);
if Bar > 0
SgnBar = 1;
elseif Bar < 0
SgnBar = -1;
else
SgnBar = 0;
end
if Bar > Stand
filty = aBar + (SgnBar)*(Stand);
else
filty = a(1);
end
end
temp1(q)=filty;
else
temp1(q)=temp(q);
a(n-q+1+2)=temp(q);
end
end
temp1_filt=bdfiltb(alpha,temp1);
a_filt=temp1_filt;
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -