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
评论列表
文章目录