|
5 | 5 | Created on Sat Mar 23 14:15:36 2019
|
6 | 6 |
|
7 | 7 | @author: ssshe
|
| 8 | +
|
| 9 | +
|
| 10 | +Adapted from https://github.com/NeuroTechX/bci-workshop |
| 11 | +
|
8 | 12 | """
|
9 | 13 |
|
10 | 14 | # Most code comes from bci_workshop_tools
|
@@ -62,19 +66,33 @@ def GrattonEmcpRaw(ch_names, n_chEEG, data_epoch):
|
62 | 66 | data_epoch (numpy.ndarray): feature matrix of shape [number of feature points,
|
63 | 67 | number of different features]
|
64 | 68 | """
|
| 69 | + |
| 70 | + # VEOG (eyeblink) correction |
65 | 71 | raw_eeg = data_epoch[:,:n_chEEG] #get EEG data only
|
66 | 72 | raw_eeg = raw_eeg.T
|
67 | 73 | # eog_idx = [int(ch_names.index('HEOG')),int(ch_names.index('VEOG'))]
|
68 | 74 | eog_idx = int(ch_names.index('VEOG')) #for eyeblink correction
|
69 | 75 | raw_eog = np.zeros((data_epoch.shape[0],1)) #pre-allocate
|
70 | 76 | raw_eog[:,0] = data_epoch[:,eog_idx]
|
71 | 77 | raw_eog = raw_eog.T
|
72 |
| - |
| 78 | + # Calculate beta values |
73 | 79 | beta = np.linalg.solve(np.dot(raw_eog,raw_eog.T), np.dot(raw_eog,raw_eeg.T))
|
74 | 80 | eeg_corrected = (raw_eeg.T - np.dot(raw_eog.T,beta)).T
|
75 |
| - |
76 | 81 | data_epoch[:,:n_chEEG] = eeg_corrected.T #replace w/corrected data
|
| 82 | + |
| 83 | + # HEOG (eye movemrny) correction |
| 84 | + raw_eegH = data_epoch[:,:n_chEEG] #get EEG data only |
| 85 | + raw_eegH = raw_eegH.T |
| 86 | + eog_idxH = int(ch_names.index('HEOG')) #for eyeblink correction |
| 87 | + raw_eogH = np.zeros((data_epoch.shape[0],1)) #pre-allocate |
| 88 | + raw_eogH[:,0] = data_epoch[:,eog_idxH] |
| 89 | + raw_eogH = raw_eogH.T |
| 90 | + # Calculate beta values |
| 91 | + betaH = np.linalg.solve(np.dot(raw_eogH,raw_eogH.T), np.dot(raw_eogH,raw_eegH.T)) |
| 92 | + eeg_correctedH = (raw_eegH.T - np.dot(raw_eogH.T,betaH)).T |
| 93 | + data_epoch[:,:n_chEEG] = eeg_correctedH.T #replace w/corrected data |
77 | 94 |
|
| 95 | + |
78 | 96 | return data_epoch
|
79 | 97 |
|
80 | 98 |
|
|
0 commit comments