Hello, I am very new to mathematica and also new to this community. I have a problem given below.I want to implement a Sample Entropy Algorithm click here ,and here ,and here in Mathematica.I wrote the code , but do not know is there correct.
data = Table[Sin[i], {i, 1, 100, .2}];f[n_] := data[[n ;; n]];
d[i_, j_, m_, n_] := Max[Table[Abs[f[i + k] - f[j + k]], {k, 0, m - 1}]];
nm[i_, r_, m_, n_] := (1/(n - m - 1))* Sum[If[d[i, j, m, n] < r, 1, 0], {j, 1, n - m}];
nm1[i_, r_, m_, n_] := (1/(n - m - 1))*Sum[If[d[i, j, m + 1, n] < r, 1, 0], {j, 1, n - m}];
B[r_, m_, n_] := (1/(n - m))*Sum[nm[i, r, m, n], {i, 1, n - m}];
A[r_, m_, n_] := (1/(n - m))*Sum[nm1[i, r, m, n], {i, 1, n - m}];
SampEn[n_, m_, r_] := -Log[A[r, m, n]/B[r, m, n]];
SampEn[Length[data], 2, 0.2 StandardDeviation[data]] // N
with this document click here SampEn= 0.2359326 ,but with my code is SampEn=0.230084.
I do not know at which point I made a mistake.Any help will be appreciated!