params = dict(Fs=4096.0, fpass=[5, 600], tapers=[1, 1], pad=1, Npairs=2000, itc=1) nPerDraw = 400 nDraws = 100 print 'Running Pairwise Spectrum Estimation' (pS, f) = spectral.mtpspec(x, params, verbose='DEBUG') print 'Running Raw Spectrum Estimation' (Sraw, f) = spectral.mtspecraw(x, params, verbose=True) print 'Running Mean Spectrum Estimation' (S, N, f) = spectral.mtspec(x, params, verbose=True) print 'Running CPCA PLV Estimation' (cplv, f) = spectral.mtcpca(x, params, verbose=True) # print 'Running CPCA Power Estimation' # (cpow, f) = spectral.mtcspec(x, params, verbose=True) # Saving Results res = dict(pS=pS, cplv=cplv, Sraw=Sraw, f=f, S=S, N=N) # res = dict(cpow = cpow, f = f) save_name = subj + condstem + '.mat' if (not os.path.isdir(respath)): os.mkdir(respath) if (not os.path.isdir(resonly_backup)): os.mkdir(resonly_backup) io.savemat(respath + save_name, res) io.savemat(resonly_backup + save_name, res)
# Filter the data raw.filter(l_freq = 70, h_freq = 1500, picks = np.arange(0,32,1)) # Here events 1 and 7 represent a particular stimulus in each polarity selectedEve = dict(up0 = 1, down0 = 7) # Epoching events of type 1 and 7 epochs = mne.Epochs(raw,eves,selectedEve,tmin = -0.05, tmax = 0.45, baseline = (-0.05, 0), reject = dict(eeg=100e-6)) # Combining both polarities so I can get envelope related FFR responses epochs = mne.epochs.combine_event_ids(epochs,['up0','down0'],dict(all0= 101)) # Getting the epoched data out, this step will also perform rejection x = epochs.get_data() # Reshaping to the format needed by spectral.mtcpca() and calling it x = x.transpose((1,0,2)) x = x[0:32,:,:] params = dict(Fs=4096,fpass=[5,1000],tapers=[2, 3],itc=1) (plv,f) = spectral.mtcpca(x,params) # Plotting results pl.plot(f,plv,linewidth = 2) pl.xlabel('Frequency (Hz)') pl.grid(True) pl.show()
# Here events 1 and 7 represent a particular stimulus in each polarity selectedEve = dict(up0=1, down0=7) # Epoching events of type 1 and 7 epochs = mne.Epochs(raw, eves, selectedEve, tmin=-0.05, tmax=0.45, baseline=(-0.05, 0), reject=dict(eeg=100e-6)) # Combining both polarities so I can get envelope related FFR responses epochs = mne.epochs.combine_event_ids(epochs, ['up0', 'down0'], dict(all0=101)) # Getting the epoched data out, this step will also perform rejection x = epochs.get_data() # Reshaping to the format needed by spectral.mtcpca() and calling it x = x.transpose((1, 0, 2)) x = x[0:32, :, :] params = dict(Fs=4096, fpass=[5, 1000], tapers=[2, 3], itc=1) (plv, f) = spectral.mtcpca(x, params) # Plotting results pl.plot(f, plv, linewidth=2) pl.xlabel('Frequency (Hz)') pl.grid(True) pl.show()
pl.xlabel('Time (s)') pl.ylabel('Frequency (Hz)') pl.title('Phase Locking') pl.colorbar() pl.show() # Induced power pl.figure() bmin, bmax = -0.1, 0.0 powbline = tfspec[:, np.logical_and(times < bmax, times > bmin)].mean(axis=1) pl.imshow((tfspec.T-powbline.T).T, vmin=-3.0, vmax=3.0, extent=[times[0] - t0, times[-1] - t0, freqs[0], freqs[-1]], aspect='auto', origin='lower') pl.xlabel('Time (s)') pl.ylabel('Frequency (Hz)') pl.title('Power (dB re: baseline)') pl.colorbar() pl.show() ######################################################################### # Fourier domain stuff pl.figure() params = dict(Fs=Fs, fpass=[5, 1000], tapers=[1, 1], itc=1) y = x[:, :32, :].transpose((1, 0, 2)) plv, f = spectral.mtcpca(y, params, verbose='DEBUG') pl.plot(f, plv**0.5, linewidth=2) pl.xlabel('Frequency (Hz)', fontsize=16) pl.ylabel('Intertrial PLV', fontsize=16) pl.show()
#%% ITC dataAll = epoch_data.get_data(picks=range(0, 32)) data32 = epoch_data.get_data(picks='A32').squeeze().T t = epoch_data.times t1 = np.where(t >= 0)[0][0] t2 = np.where(t >= 1)[0][0] data32 = data32[t1:t2, :] fs = data_eeg.info['sfreq'] TW = 2 #fres = 2*TW itc, f = ITC(data32, TW, fs) plt.figure() plt.plot(f, itc) data_reshaped = np.zeros( [dataAll.shape[1], dataAll.shape[0], dataAll.shape[2]]) #ch x trial x time for ch in range(0, 32): data_reshaped[ch, :, :] = dataAll[:, ch, :] params = {} params['Fs'] = fs params['tapers'] = [TW, 2 * TW - 1] params['fpass'] = [1, 100] params['itc'] = 1 plv, f = mtcpca(data_reshaped, params) plt.figure() plt.plot(f, plv) plt.xlabel('Freq (hz)')