Tot_trials = epdat.shape[1] + epdat_3.shape[1] plt.figure() plt.plot(Peak2Peak.T) plt.title(subject + ' Tot trials:' + str(Tot_trials)) # plt.figure() # plt.plot(Peak2Peak_3.T) #%% Correlation Analysis Ht_12 = mseqXcorr(epdat,mseq[0,:]) Ht_3 = mseqXcorr(epdat_3,mseq_shift[0,:]) Ht_epochs_12, t_epochs = mseqXcorrEpochs_fft(epdat,mseq[0,:],fs) Ht_epochs_3, t_epochs = mseqXcorrEpochs_fft(epdat_3,mseq_shift[0,:],fs) Ht_epochs = np.concatenate([Ht_epochs_12,Ht_epochs_3],axis=1) Ht = Ht_12 * epdat.shape[1]/Tot_trials + Ht_3 * epdat_3.shape[1]/Tot_trials #%% Plot Ht # if ch_picks.size == 31: # sbp = [5,3] # sbp2 = [4,4] # elif ch_picks.size == 32: # sbp = [4,4] # sbp2 = [4,4]
plt.plot(Peak2Peak.T) plt.title(subject + ' ' + str(m)) #%% Correlation Analysis Ht = [] Htnf = [] Ht_epochs = [] t_epochs = [] # do cross corr for m in range(len(epdat)): print('On mseq # ' + str(m + 1)) Ht_m = mseqXcorr(epdat[m], mseq[m][0, :]) Ht_epochs_m, t_epochs_m = mseqXcorrEpochs_fft(epdat[m], mseq[m][0, :], fs) Ht.append(Ht_m) Ht_epochs.append(Ht_epochs_m) t_epochs.append(t_epochs_m) for nf in range(num_nfs): print('On nf: ' + str(nf)) resp = epdat[m].copy() inv_inds = np.random.permutation( epdat[m].shape[1])[:round(epdat[m].shape[1] / 2)] resp[:, inv_inds, :] = -resp[:, inv_inds, :] Ht_nf = mseqXcorr(resp, mseq[m][0, :]) Htnf.append(Ht_nf) #%% Plot Ht
plt.figure() plt.plot(Peak2Peak.T) plt.title(subject + ' ' + str(Tot_trials)) # plt.figure() # plt.plot(Peak2Peak[:,mask_trials].T) # plt.figure() # plt.plot(Peak2Peak[np.delete(ch_picks,ch_maxAmp),:].T) #%% Correlation Analysis Htnf = [] Ht = mseqXcorr(epdat,mseq[0,:]) Ht_epochs, t_epochs = mseqXcorrEpochs_fft(epdat,mseq[0,:],fs) for nf in range(num_nfs): print('On nf:' + str(nf)) resp = epdat.copy() inv_inds = np.random.permutation(epdat.shape[1])[:round(epdat.shape[1]/2)] resp[:,inv_inds,:] = -resp[:,inv_inds,:] Ht_nf = mseqXcorr(resp,mseq[0,:]) Htnf.append(Ht_nf) #%% Plot Ht if ch_picks.size == 31: sbp = [5,3] sbp2 = [4,4] elif ch_picks.size == 32:
#%% Remove epochs with large deflections # Reject_Thresh=150e-6 Tot_trials = np.zeros([len(mseq)]) for m in range(len(epdat)): Peak2Peak = epdat[m].max(axis=2) - epdat[m].min(axis=2) mask_trials = np.all(Peak2Peak < Reject_Thresh, axis=0) print('rejected ' + str(epdat[m].shape[1] - sum(mask_trials)) + ' trials due to P2P') epdat[m] = epdat[m][:, mask_trials, :] print('Total Trials Left: ' + str(epdat[m].shape[1])) Tot_trials[m] = epdat[m].shape[1] plt.figure() plt.plot(Peak2Peak.T) #%% Correlation Analysis Ht = [] Htnf = [] # do cross corr for m in range(len(epdat)): print('On mseq # ' + str(m + 1)) Ht_m, t_keep = mseqXcorrEpochs_fft(epdat[m], mseq[:, 0], fs) Ht.append(Ht_m[0, :, :]) #%% Save Data with open(os.path.join(pickle_loc, subject + '_TMTF_cz.pickle'), 'wb') as file: pickle.dump([t_keep, Ht, info_obj, ch_picks], file) del data_eeg, data_evnt, epdat, Ht, info_obj, Htnf, Ht_m