# As we don't have an ECG channel we use one that correlates a lot with heart # beats: 'MEG 1531'. We can directly pass the name to the find_sources method. # In our example, the find_sources method returns and array of correlation # scores for each ICA source. ecg_ch_name = 'MEG 1531' ecg_scores = ica.find_sources_epochs(epochs, target=ecg_ch_name, score_func='pearsonr') # get the source most correlated with the ECG. ecg_source_idx = np.argsort(np.abs(ecg_scores))[-1] # get sources as epochs object and inspect some trial some_trial = 10 title = 'Source most similar to ECG' ica.plot_sources_epochs(epochs[some_trial], ecg_source_idx, title=title) # As we have an EOG channel, we can use it to detect the source. eog_scores = ica.find_sources_epochs(epochs, target='EOG 061', score_func='pearsonr') # get maximum correlation index for EOG eog_source_idx = np.abs(eog_scores).argmax() # As the subject did not constantly move her eyes, the movement artifacts # may remain hidden when plotting single epochs. # Plotting the identified source across epochs reveals # considerable EOG artifacts. title = 'Source most similar to EOG' ica.plot_sources_epochs(epochs, eog_source_idx, title=title)
tmin, tmax, event_id = -0.2, 0.5, 1 # baseline = None baseline = (None, 0) reject = None events = mne.find_events(raw, stim_channel='STI 014') epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks, baseline=baseline, preload=True, reject=reject) # fit sources from epochs or from raw (both works for epochs) ica.decompose_epochs(epochs) # plot components for one epoch of interest # A distinct cardiac component should be visible ica.plot_sources_epochs(epochs, epoch_idx=13, n_components=25) ############################################################################### # Automatically find the ECG component using correlation with ECG signal # As we don't have an ECG channel we use one that correlates a lot with heart # beats: 'MEG 1531'. We can directly pass the name to the find_sources method. # In our example, the find_sources method returns and array of correlation # scores for each ICA source. ecg_scores = ica.find_sources_epochs(epochs, target='MEG 1531', score_func='pearsonr') # get maximum correlation index for ECG ecg_source_idx = np.abs(ecg_scores).argmax()
# baseline = None baseline = (None, 0) reject = None events = mne.find_events(raw, stim_channel="STI 014") epochs = mne.Epochs( raw, events, event_id, tmin, tmax, proj=True, picks=picks, baseline=baseline, preload=True, reject=reject ) # fit sources from epochs or from raw (both works for epochs) ica.decompose_epochs(epochs) # plot components for one epoch of interest # A distinct cardiac component should be visible ica.plot_sources_epochs(epochs, epoch_idx=13, n_components=25) ############################################################################### # Automatically find the ECG component using correlation with ECG signal # As we don't have an ECG channel we use one that correlates a lot with heart # beats: 'MEG 1531'. We can directly pass the name to the find_sources method. # In our example, the find_sources method returns and array of correlation # scores for each ICA source. ecg_scores = ica.find_sources_epochs(epochs, target="MEG 1531", score_func="pearsonr") # get maximum correlation index for ECG ecg_source_idx = np.abs(ecg_scores).argmax() print "#%i -- ICA component resembling the ECG" % ecg_source_idx