This site is best viewed in a browser that conforms to web standards.



BOOL ivorix_sma (
vector<double>& ivec, // input vector
vector<double>& ovec, // output vector
unsigned long span) // time period or span of embedding
{
ULONG x = 0;
ULONG y = 0;
ULONG p = 0;
ULONG e = ivec.size();
double sum = 0;
if ( span == 0 || span >= e )
return false;
ovec.resize(ivec.size());
ovec[0] = ivec[0];
for ( x = 1; x < e; x++ )
{
p = min(x, span);
if ( p <= span )
{
sum = 0;
for ( y = 0; y < p; y++ )
sum += ivec[x-y];
}
else
{
// save cpu cycles: add current
// value and subtract least recent
sum = sum - ivec[x-p] + ivec[x];
}
ovec[x] = sum / p;
}
return true;
}