If you have a question or issue with MNE-Python, please include the following info:
- MNE-Python version: 0.20.7
- operating system: windows 10
i have some questions about the spatial patterns drawn by csp.plot_pattern/filters. Here are my results:
why its number was too high in the colorbar? it seemed abnormal. I only used a 4-order butterworth filter befor.Here are part of my codes. Look forward to your reply sincerely.
# defination of bandpass filter
def butter_bandpass(lowcut,highcut,fs,order):
nyq=0.5*fs#采样频率:奈奎斯特抽样定理指若频带宽度有限的,要从抽样信号中无失真地恢复原信号,抽样频率应大于2倍信号最高频率(脑电最高频率)
low=lowcut/nyq
high=highcut/nyq
b,a=signal.butter(4,[low,high],'bandpass')#阶数为4
return b,a
def butter_bandpass_filter(data,lowcut,highcut,fs,order):
b,a=butter_bandpass(lowcut,highcut,fs,order)
#y=signal.filtfilt(b,a,data,axis=2)
y=signal.filtfilt(b,a,data)
return y
raw_fname1='E:\\实验数据\\2020.1.6上午before\\03.fif'
raw=mne.io.read_raw_fif(raw_fname1)
raw.load_data()
#raw_temp=raw.copy()
raw.drop_channels({'TP10', 'ECG', 'TP9'})
print(raw.info)
<Info | 10 non-empty values
bads: []
ch_names: C3, C4, CP1, CP2, CP5, CP6, Cz, F3, F4, F7, F8, FC1, FC2, FC5, ...
chs: 29 EEG
custom_ref_applied: False
dig: 31 items (31 EEG)
file_id: 4 items (dict)
highpass: 0.0 Hz
lowpass: 500.0 Hz
meas_date: 2020-01-06 10:25:47 UTC
meas_id: 4 items (dict)
nchan: 29
projs: []
sfreq: 1000.0 Hz
>
csp=CSP(n_components=6, reg=None, log=True, norm_trace=False)
from mne.decoding import CSP
#acquire and combine features of different fequency bands
features_train=[]
#features_test=[]
#freq=[4,8,14,20]
#freq=[0.5,4]
#freq=[4,8]
#freq=[8,14]
#freq=[14,20]
freq=[4,20]
#freq=[4,8,12,16,20,24,28,32,36,40]
#freq=[4,8,12,16,20,24,28]
#freq=[2,3,4,5,6,7,8]#p300主要在2-8hz
#freq=[2,4,6,8]
#freq=[2,5,8];
for freq_count in range(len(freq)):
#loop for freqency
lower=freq[freq_count]
if lower==freq[-1]:#到最后一个时停止
break
higher=freq[freq_count+1]
#print(lower,higher)
X_train_filt=butter_bandpass_filter(X_train,lowcut=lower,highcut=higher,fs=250,order=4)
print(X_train_filt.shape)
tmp_train=csp.fit_transform(X_train_filt,y_train)
vmax=np.argmax(tmp_train)
vmin=np.argmin(tmp_train)
csp.plot_patterns(raw.info, ch_type='eeg',units=None, size=1.5)
csp.plot_filters(raw.info, ch_type='eeg', units='Patterns (AU)', size=1.5)
if freq_count==0:
features_train=X_train_filt
else:
features_train=np.concatenate((features_train,X_train_filt),axis=1)
np.set_printoptions(threshold=np.inf)
print(features_train.shape)