bci_workshop_tools.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Wall-EEG 作者: neurotechuoft 项目源码 文件源码
def compute_feature_vector(eegdata, Fs):
    """
    Extract the features from the EEG

    Arguments:
    eegdata: array of dimension [number of samples, number of channels]
    Fs: sampling frequency of eegdata

    Outputs:
    feature_vector: np.array of shape [number of feature points; number of different features]

    """
    #Delete last column (Status)
    eegdata = np.delete(eegdata, -1 , 1)    

    # 1. Compute the PSD
    winSampleLength, nbCh = eegdata.shape

    # Apply Hamming window
    w = np.hamming(winSampleLength)
    dataWinCentered = eegdata - np.mean(eegdata, axis=0) # Remove offset
    dataWinCenteredHam = (dataWinCentered.T*w).T

    NFFT = nextpow2(winSampleLength)
    Y = np.fft.fft(dataWinCenteredHam, n=NFFT, axis=0)/winSampleLength
    PSD = 2*np.abs(Y[0:NFFT/2,:])
    f = Fs/2*np.linspace(0,1,NFFT/2)     

    # SPECTRAL FEATURES
    # Average of band powers
    # Delta <4
    ind_delta, = np.where(f<4)
    meanDelta = np.mean(PSD[ind_delta,:],axis=0)
    # Theta 4-8
    ind_theta, = np.where((f>=4) & (f<=8))
    meanTheta = np.mean(PSD[ind_theta,:],axis=0)
    # Alpha 8-12
    ind_alpha, = np.where((f>=8) & (f<=12)) 
    meanAlpha = np.mean(PSD[ind_alpha,:],axis=0)
    # Beta 12-30
    ind_beta, = np.where((f>=12) & (f<30))
    meanBeta = np.mean(PSD[ind_beta,:],axis=0)

    feature_vector = np.concatenate((meanDelta, meanTheta, meanAlpha, meanBeta),
                                    axis=0)

    feature_vector = np.log10(feature_vector)   

    return feature_vector
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号