for a project, I need to build a machine learning algorithm that can predict MI-BCI performance based on mu suppression. So first, I need to calculate the ERD/ERS of the mu band during user’s BCI tasks. The dataset that I’m using contains data from participants during a MI-BCI task where they had to imagine left or right-hand movement. Each trial took 8 seconds where the first 4 seconds are the rest period and the last 4 seconds are the imagery period. Each period is indicated by a TimeStamp from -3 to 5, to at 0 the imagery period starts. I want to calculate the average power of the resting period and of the imagery period and then use the formula for ERD/ERS. To do so, I used code I found on
So far it looks like this:
# import data set df = pd.read_csv('TestSubject.csv') #tmin, tmax tmin, tmax = min(df['TimeStamp']),max(df['TimeStamp']) #transpose data set data_trans = df.transpose() # information for raw file ch_names = ['C3','C4','Trigger','class'] sfreq = 250 #create raw mne file info = mne.create_info(ch_names = ch_names,sfreq = sfreq) raw = mne.io.RawArray(data_trans,info) raw.plot() #get picks from raw data picks = mne.pick_channels(raw.info["ch_names"], ["C3", "C4"]) events = mne.make_fixed_length_events(raw, id=1, duration=8) #get epochs of 8 seconds #filter raw.filter(l_freq = 8.0 ,h_freq = 13.0,picks=picks,fir_design='firwin') #create epochs epochs = mne.Epochs(raw, events,None, tmin, tmax, picks=picks, baseline=None, preload=True) event_id, tmin, tmax = 1,-3, 5 # define id and epochs around events (in s) freqs = np.arange(8, 13, 1) n_cycles = freqs # use constant t/f resolution vmin, vmax = -1, 1.5 # set min and max ERDS values in plot baseline = [0, 1] # baseline interval (in s) cmap = center_cmap(plt.cm.RdBu, vmin, vmax) # zero maps to white kwargs = dict(n_permutations=100, step_down_p=0.05, seed=1, buffer_size=None, out_type='mask') # for cluster test tfr = tfr_multitaper(epochs, freqs=freqs, n_cycles=n_cycles, use_fft=True, return_itc=False, average=False, decim=2,picks=picks) power = tfr_multitaper(epochs[event_id], freqs=freqs, n_cycles=n_cycles, use_fft=True, return_itc=False, decim=2,picks=picks) power.crop(tmin, tmax)
How do calculate the ERD/ERS for each epoch?
Thank you in advance.