Define exactly which pairs can match
For N observations x(1),...,x(N), choose an integer m ≥ 1 and use starts i = 1,...,N-m. At each start, form the length-m vector [x(i),...,x(i+m-1)] and its extension through x(i+m). Compare each unordered pair i < j once. The final possible length-m template, starting at N-m+1, is excluded because it has no extension. This is the common-start convention described by Richman, Lake and Moorman.
- Use Chebyshev distance: d_m(i,j) = max over k = 0,...,m-1 of |x(i+k)-x(j+k)|. A pair matches when d_m ≤ r, where r is an absolute tolerance in the units of x. Equality counts here; software using a strict inequality can disagree at the boundary.
- B counts matches at length m. A counts those same pairs that also satisfy |x(i+m)-x(j+m)| ≤ r. There are M = N-m eligible starts and M(M-1)/2 candidate pairs, so 0 ≤ A ≤ B. Ordered-pair counting doubles both counts and leaves A/B unchanged.
- Exclude i = j at both lengths. Distinct templates may overlap in time in this convention. Excluding all overlapping templates is an additional rule and changes the statistic; it is not the same as removing self-matches.
- SampEn = -ln(A/B) uses the natural logarithm and reports nats. A base-2 version reports bits and equals SampEn/ln(2). This score is not normalized to a universal range from 0 to 1.