function saen = SampEn( dim, r, data, tau )
% dim : embedded dimension。 r : tolerance (typically 0.2 * std)。data: time-series data
% tau : delay time for downsampling (user can omit this, in which case the default value is 1)
if nargin < 4, tau = 1; end
if tau > 1, data = downsampl