Saturday, June 17, 2006

Algorithm for time synch of multiple data streams

Because I am tired of big corporations acquiring patents and copyrights for everything in sight, I decided to do my best to keep as much in the public domain as possible. So, every time I think of anything that some stupid company can get a patent for, I will create a blog entry for it. So when any company attempt to get a patent for it, I can point at my dated blog entry and prove that the idea is MINE!!!!!!

So, here's my first contribution.

When time synchronizing multiple data streams, the following algorithm may be applied to determine which data stream(s) are behind, which stream(s) are ahead, and which are within tolearance.



e = error tolerance

n = number of data streams

T = array of n time codes (64-bits signed integer), one for each data stream

D = array of n x n time code differences between each data stream

S = array of n status, one for each data stream in which the values
-1 means the data stream is behind
0 means the data stream is within tolerance
1 means the data stream is ahead



// populating the array of time code differences
for ( CurrentStreamIdx = 0 ;
CurrentStreamIdx < n ;
CurrentStreamIdx++
) {

for ( CompareStreamIdx
= CurrentStreamIdx + 1 ;
CompareStreamIdx < n ;
CompareStreamIdx++
) {

D[CurrentStreamIdx,
CompareStreamIdx]
= T[CurrentStreamIdx]
- T[CompareStreamIdx];

D[CompareStreamIdx,
CurrentStreamIdx]
= - D[CurrentStreamIdx,
CompareStreamIdx];
} ;

} ;



// for each data stream,
// determine if more than half of its time code differences are behind or ahead
for ( CurrentStreamIdx = 0 ;
CurrentStreamIdx < n ;
CurrentStreamIdx++
) {


for ( CompareStreamIdx = 0 ;
CompareStreamIdx < n ;
CompareStreamIdx++
) {

aheadErrorCnt = 0 ;
behindErrorCnt = 0 ;


if ( CurrentStreamIdx
!= CompareStreamIdx
) {

if ( D[CurrentStreamIdx,
CompareStreamIdx]
> e
) {
aheadErrorCnt
= aheadErrorCnt + 1 ;
}
else if ( D[CurrentStreamIdx,
CompareStreamIdx]
< -e
) {
behindErrorCnt
= behindErrorCnt + 1 ;
}
} ;

} ;

if ( aheadErrorCnt >= n/2 ) {
s[CurrentStreamIdx] = 1 ;
}
else if ( behindErrorCnt >= n/2 ) {
s[CurrentStreamIdx] = -1 ;
}
else {
s[CurrentStreamIdx] = 0 ;
} ;
} ;

No comments: