Indexing first order derivatives and assigning quality to time series

2 Ansichten (letzte 30 Tage)
jakob ekwall
jakob ekwall am 21 Jan. 2016
So I've run into the following problem.
My data consists of an averaged hourly water consumption [l/s] for every hour during a whole year
Date Consumption (l/s)
'01/01/14 00:00' 52.9900
. .
. .
'31/12/14 23:00' 40.2000
The plan is to end up with a time series with a quality code assigned to each and every value in the series which is based on some different criteria. I would want it to look something like this.
Date Consumption (l/s) Quality
'01/01/14 00:00' 52.9900 Ok
'01/01/14 00:01' 148.2 Bad
'01/01/14 00:02' 148.2 Bad
. . .
'31/12/14 23:00' 40.2000 Ok
I've managed to create a time series and assign quality codes for all the criteria I'm testing but one. The criteria that I'm having a difficult time implementing is that the difference between two hours can't be greater than a certain value depending on what day it is. If the difference is based on values originating from Mon-Fri there is one criteria, if they originate from Saturdays or Sundays there is another criteria.
The problem I'm having is assigning the correct quality code in the time series to the values which the difference was based on.
For example Say that the consumption at '01/02/14 00:03' = 20 and the consumption at '01/02/14 00:04'=400 The difference is 400-20=380 and the criteria which can not be exceeded is 100. I then want to assign quality code "bad" to both dates '01/02/14 00:03' & '01/02/14 00:04' in my time series.
What I did was to move all the Mon-Fri values and their corresponding hour (0-23) into one vector and then I did the same for Sat-Sun. Then I applied the diff function on these. The results were then evaluated in the if loop.
This is what the code looks like.
MF (6264x2 double) %Mon-fri..Mon-fri
SS (2496x2 double) %Sat-Sun..Sat-Sun
dMF=diff(MF(:,1)) (6263x1 double)
dSS=diff(SS(:,1)) (2495x1 double)
qv=zeros(length(MF),1);
for iv=1:length(dMF);
if abs(dMF(iv)) >= crit1
qv(iv,1)=2; % 2 is quality code for "Bad"
else
qv(iv,1)=0; % 0 is quality code for "Ok"
end
end
qh=zeros(length(SS),1);
for ih=1:length(dSS);
if abs(dSS(ih)) >=crit2
qh(ih,1)=2;
else
qh(ih,1)=0;
end
end
I end up with two vectors qh (Sat & Sun) and qv (Mon-Fri) indicating if the absolute value of the difference exceeds the criteria or not. However I want to insert this information to my time series quality column and this I were I'm completely lost.
This doesn't feel like the right way to do it, since there is no way to map the values back to their original position. Could this somehow be done without splitting up the original data into Mon-Fri and Sat & Sun?

Antworten (0)

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by