Dispersion Entropy with Embedding dim

Dispersion Entropy is computed by first discretising the signal and then extracting all the dispersing patterns of given embedding dimension. The ditrubution of patterns determines the dispersion entropy of signal. If signal have a few patterns with high repetitions compare to others signal is less random which entails the low entropy. On the other hand, a random signal with no patterns repetitions more than others leads to high entropy.

signal: x, Disperssion Entropy: 2.2717
spkit-version 0.0.9.7
EEG Sample x: Shape (2048,)
--------------------------------------------------
Dispersion Entropy with embeding dimention=2
--------------------------------------------------
Disperssion Entropy:  2.271749287746759
All the patterns found (embeding dimention=2)
(1, 1)  |       (1, 2)  |       (1, 4)  |       (2, 1)  |       (2, 2)
(2, 3)  |       (2, 5)  |       (3, 1)  |       (3, 2)  |       (3, 3)
(3, 4)  |       (4, 2)  |       (4, 3)  |       (4, 4)  |       (4, 5)
(4, 9)  |       (5, 3)  |       (5, 4)  |       (5, 5)  |       (5, 6)
(5, 7)  |       (5, 8)  |       (6, 5)  |       (6, 6)  |       (6, 7)
(7, 5)  |       (7, 6)  |       (7, 7)  |       (7, 8)  |       (8, 4)
(8, 7)  |       (8, 8)  |       (8, 9)  |       (9, 8)  |       (9, 9)
(9, 10) |       (10, 9) |       (10, 10)

import numpy as np
import matplotlib.pyplot as plt
import spkit as sp
print('spkit-version',sp.__version__)

# load sample EEG Signal
X,fs, ch_names = sp.data.eeg_sample_14ch()
x = X[:,0]
x = sp.filter_X(x,band=[1,20],btype='bandpass',verbose=0)
print('EEG Sample x: Shape',x.shape)

t = np.arange(x.shape[0])/fs

#Dispersion Entropy
print('-'*50)
print('Dispersion Entropy with embeding dimention=2')
print('-'*50)

de,prob,patterns_dict,_,_= sp.dispersion_entropy(x,classes=10, scale=1, emb_dim=2, delay=1,return_all=True)
print('Disperssion Entropy: ',de)

plt.figure(figsize=(10,3))
plt.subplot(121)
plt.plot(t,x)
plt.xlim([t[0],t[-1]])
plt.xlabel('time (s)')
plt.ylabel('x')
plt.title('signal: x')
plt.grid()
plt.subplot(122)
plt.stem(np.arange(len(prob)),prob)
plt.xlabel('pattern #')
plt.ylabel('probability')
plt.title(f'Disperssion Entropy: {de:,.4f}')
plt.show()

print('All the patterns found (embeding dimention=2)')
sp.utils.pretty_print(patterns_dict,n=5,show_index=False)

Total running time of the script: (0 minutes 0.155 seconds)

Related examples

Dispersion Entropy with top patterns

Dispersion Entropy with top patterns

Wavelet Filtering

Wavelet Filtering

EEG Artifact removal using ICA

EEG Artifact removal using ICA

ATAR: Automatic and Tunable Artifact Removal Algorithm

ATAR: Automatic and Tunable Artifact Removal Algorithm

Release Highlights for spkit 0.0.9.7

Release Highlights for spkit 0.0.9.7

Gallery generated by Sphinx-Gallery