ATAR Algorithm - Automatic and Tunable Artifact Removal Algorithm for EEG Signal.
The algorithm is based on wavelet packet decomposion (WPD), the full description of algorithm can be found here Automatic and Tunable Artifact Removal Algorithm for EEG from the article [1]. Figure 1 shows the the block diagram and operating mode of filtering.
The algorithm is applied on the given multichannel signal X (n,nch), window wise and reconstructed with overall add method. The defualt window size is set to 1 sec (128 samples). For each window, the threshold $\theta_\alpha$ is computed and applied to filter the wavelet coefficients.
There is manily one parameter that can be tuned $\beta$ with different operating modes and other settings. Here is the list of parameters and there simplified meaning given:
Parameters:
$\beta$: This is a main parameter to tune, highher the value, more aggressive the algorithm to remove the artifacts. By default it is set to 0.1. $\beta$ is postive float value.
*OptMode*: This sets the mode of operation, which decides hoe to remove the artifact. By default it is set to 'soft', which means Soft Thresholding, in this mode, rather than removing the pressumed artifact, it is suppressed to the threshold, softly. OptMode='linAtten', suppresses the pressumed artifact depending on how far it is from threshold. Finally, the most common mode - Elimination (OptMode='elim'), which remove the pressumed artifact.
*wv=db3*: Wavelet funtion, by default set to db3, could be any of ['db3'.....'db38', 'sym2.....sym20', 'coif1.....coif17', 'bior1.1....bior6.8', 'rbio1.1...rbio6.8', 'dmey']
$k_1$, $k_2$: Lower and upper bounds on threshold $\theta_\alpha$.
*IPR=[25,75]*: interpercentile range, range used to compute threshold
Figure 2, below, shows the affect of $\beta$ on a segment of signal with three different modes.
Reference
There are three functions in spkit.eeg for ATAR algorithm
*spkit.eeg.ATAR_1Ch* is for single channel input signal x of shape (n,), where as, *spkit.eeg.ATAR_mCh* is for multichannel signal X with shape (n,ch), which uses joblib for parallel processing of multi channels. For some OS, joblib raise an error of *BrokenProcessPool, in that case use spkit.eeg.ATAR_mCh_noParallel, which is same as spkit.eeg.ATAR_mCh, except parallel processing. Alternatively, use spkit.eeg.ATAR_1Ch* with for loop for each channel.
*spkit.eeg.ATAR* is generalized function, this will call *spkit.eeg.ATAR_1Ch* is single channel is passed else *spkit.eeg.ATAR_mCh* and with use_joblib agrument, it can be set to try parallel processing, else will process each channel individually. We recommed to use *spkit.eeg.ATAR*.
import numpy as np
import matplotlib.pyplot as plt
import spkit as sp
sp.__version__
'0.0.9.4'
X,ch_names = sp.load_data.eegSample()
fs = 128
#help(sp.filter_X)
Xf = sp.filter_X(X,band=[0.5], btype='highpass',fs=fs,verbose=0)
Xf.shape
(2048, 14)
t = np.arange(Xf.shape[0])/fs
plt.figure(figsize=(12,5))
plt.plot(t,Xf+np.arange(-7,7)*200)
plt.xlim([t[0],t[-1]])
plt.xlabel('time (sec)')
plt.yticks(np.arange(-7,7)*200,ch_names)
plt.grid()
plt.title('Xf: 14 channel - EEG Signal (filtered)')
plt.show()
XR = sp.eeg.ATAR(Xf.copy(),verbose=0)
XR.shape
(2048, 14)
plt.figure(figsize=(12,5))
plt.plot(t,XR+np.arange(-7,7)*200)
plt.xlim([t[0],t[-1]])
plt.xlabel('time (sec)')
plt.yticks(np.arange(-7,7)*200,ch_names)
plt.grid()
plt.title('XR: Corrected Signal')
plt.show()
plt.figure(figsize=(12,5))
plt.plot(t,(Xf-XR)+np.arange(-7,7)*200)
plt.xlim([t[0],t[-1]])
plt.xlabel('time (sec)')
plt.yticks(np.arange(-7,7)*200,ch_names)
plt.grid()
plt.title('Xf - XR: Difference (removed signal)')
plt.show()
XR = sp.eeg.ATAR(Xf.copy(),verbose=0,OptMode='linAtten')
XR.shape
(2048, 14)
plt.figure(figsize=(12,5))
plt.plot(t,XR+np.arange(-7,7)*200)
plt.xlim([t[0],t[-1]])
plt.xlabel('time (sec)')
plt.yticks(np.arange(-7,7)*200,ch_names)