Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pyentrp/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,34 @@ def sample_entropy(time_series, sample_length, tolerance=None):
return se


def multiscale_entropy(time_series, sample_length, tolerance):
def multiscale_entropy(time_series, scale_factor, tolerance, sample_length=2):
"""Calculate the Multiscale Entropy of the given time series considering
different time-scales of the time series.

Args:
time_series: Time series for analysis
sample_length: Bandwidth or group of points
scale_factor: Calculate MSE upto this sized scale factor
sample_length: Number of sequential points of the time series - input to sample_entropy
tolerance: Tolerance (default = 0.1...0.2 * std(time_series))

Returns:
Vector containing Multiscale Entropy

Reference:
[1] http://en.pudn.com/downloads149/sourcecode/math/detail646216_en.html
[2] https://dbiom.org/files/publications/Peng_MultiscaleEntropyAnalysisComplexPhysiologicTimeSeries.pdf
"""
n = len(time_series)
mse = np.zeros((1, sample_length))
mse = np.zeros((1, scale_factor))

for i in range(sample_length):
for i in range(scale_factor):
b = int(np.fix(n / (i + 1)))
temp_ts = [0] * int(b)
for j in range(b):
num = sum(time_series[j * (i + 1): (j + 1) * (i + 1)])
den = i + 1
temp_ts[j] = float(num) / float(den)
se = sample_entropy(temp_ts, 1, tolerance)
se = sample_entropy(temp_ts, sample_length, tolerance)
mse[0, i] = se

return mse[0]
Expand Down