This site is best viewed in a browser that conforms to web standards.
Most implementations construct a triangular integer window over the time series.

A more effective and even more accurate algorithm uses a Bartlett window for construction. This kind of data window also has a triangular form but is based on floating point calculations.



inline double W_BARTLETT(double n, double k, double d = 1.0)
{
return (n == 0) ? 0 : (d * (1 - fabs((k - 0.5 * n) / (0.5 * n))));
}
BOOL ivorix_tma (
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;
double div = 0;
if ( span == 0 || span >= e )
return false;
ovec.resize(ivec.size());
ovec[0] = ivec[0];
for ( x = 1; x < e; x++ )
{
sum = 0;
p = min(x, span);
if ( p <= span )
{
div = 0;
for ( y = 1; y <= p; y++ )
div += W_BARTLETT(p+1, y, p);
}
for ( y = 1; y <= p; y++ )
sum += ivec[x-y+1] * W_BARTLETT(p+1, y, p);
ovec[x] = sum / div;
}
return true;
}