Exemple #1
0
def feature_extraction(data, sfreq):
	#What features do I want???
	#Kurtosis
	#line-length
	#entropy

	#Perform feature extraction for 2 second segments
	kurt = np.zeros((data.shape[0],data.shape[1]//2//sfreq))
	s = np.zeros((data.shape[0],data.shape[1]//2//sfreq))
	H = np.zeros((data.shape[0],data.shape[1]//2//sfreq))


	segments = np.zeros((data.shape[0],data.shape[1]//2//sfreq,sfreq*2))
	for n in range(0,data.shape[1]//2//sfreq):
		cur_data = data[:,n*sfreq*2:(n+1)*sfreq*2]
		segments[:,n,:] = cur_data
		kurt[:,n] = univariate.compute_kurtosis(cur_data)
		s[:,n] = univariate.compute_line_length(cur_data)
		H[:,n] = univariate.compute_spect_entropy(sfreq, cur_data, psd_method='welch')

	#Average across channels
	kurt_avg = np.mean(kurt,axis=0)
	s_avg = np.mean(s,axis=0)*np.power(10,6)
	H_avg = np.mean(H,axis=0)

	return kurt_avg, s_avg, H_avg
def test_spect_entropy():
    expected = -(0.005 / 0.00625) * log(0.005 / 0.00625, 2.) - \
        (0.00125 / 0.00625) * log(0.00125 / 0.00625, 2.)
    assert_almost_equal(compute_spect_entropy(sfreq, data_sin), expected)
def test_shape_output_spect_entropy():
    for j in range(n_epochs):
        feat = compute_spect_entropy(sfreq, data[j, :, :])
        assert_equal(feat.shape, (n_channels, ))