def set_pfd(self): for e in xrange(self.data.shape[0]): if np.all(self.data[e][:1000] == 0): continue name = 'pfd_e' + str(e) value = pyeeg.pfd(self.data[e], self.fod['e' + str(e)]) self.features[name] = value
def mean_pfd(df): pfd_vals = [] for col in df.columns: col = df[col].to_numpy() pfd_val = p.pfd(col) pfd_vals.append(pfd_val) return np.mean(pfd_vals)
def ecg_extract(file_path, time_length): ecg_mat = np.genfromtxt(file_path, dtype=float, delimiter=',', usecols=(1, ), skip_header=True) num = ecg_mat.shape[0] col = time_length * 250 row = int(num / col) ecg_mat = ecg_mat[1:row * col + 1].reshape(row, col) num_row = ecg_mat.shape[0] result = np.zeros((num_row, 5)) for i in range(num_row): ecg = ecg_mat[i, :] if np.any(np.isnan(ecg)): indices = np.where(np.isnan(ecg))[0] for j in indices: ecg[j] = ecg[j - 1] power = np.sum(np.power(ecg, 4)) k = kfd(ecg) hjm = pyeeg.hjorth(ecg) pfd = pyeeg.pfd(ecg) result[i, 0] = power result[i, 1] = k result[i, 2] = hjm[0] result[i, 3] = hjm[1] result[i, 4] = pfd return result
def hr_extract(file_path, time_length): hr_mat = np.genfromtxt(file_path, dtype=float, delimiter=',', usecols=(1, ), skip_header=True) num = hr_mat.shape[0] noise = np.random.normal(0, 1.1, num) hr_mat = hr_mat + noise col = time_length row = int(num / col) hr_mat = hr_mat[:row * col].reshape(row, col) num_row = hr_mat.shape[0] result = np.zeros((num_row, 5)) for i in range(num_row): hr = hr_mat[i, :] if np.any(np.isnan(hr)): indices = np.where(np.isnan(hr))[0] for j in indices: hr[j] = hr[j - 1] power = np.sum(np.power(hr, 4)) k = kfd(hr) hjm = pyeeg.hjorth(hr) pfd = pyeeg.pfd(hr) result[i, 0] = power result[i, 1] = k result[i, 2] = hjm[0] result[i, 3] = hjm[1] result[i, 4] = pfd result = result[:, 1:] return result
def features(mat): Kmax = 5 Tau = 4 DE = 10 M = 10 R = 0.3 Band = np.arange(1, 86) Fs = 173 DFA = pyeeg.dfa(mat) HFD = pyeeg.hfd(mat, Kmax) SVD_Entropy = pyeeg.svd_entropy(mat, Tau, DE) Fisher_Information = pyeeg.fisher_info(mat, Tau, DE) PFD = pyeeg.pfd(mat) sleep(0.01) return (DFA, HFD, SVD_Entropy, Fisher_Information, PFD)
def beta_parametrs(self,val_): temp_val1 = []; temp_val2 = [] fq_, px_ = welch(val_, nperseg=256, nfft=1023, fs = 128, noverlap=100, scaling='density' ) fq1_up = 38.0; fq1_dwn = 20.0 fq2_up = 42.0; fq2_dwn = 14.0 for i in range(len(px_)): if fq_[i]<=fq1_up and fq_[i]>=fq1_dwn:temp_val1.append(px_[i]) elif fq_[i]<=fq2_up and fq_[i]>=fq2_dwn:temp_val2.append(px_[i]) vaf_eng1 = sum(temp_val1) vaf_eng2 = sum(temp_val2) vaf_r = vaf_eng1 / vaf_eng2 vaf_pfd = pfd(val_) vaf_hjorth_mob = (hjorth_mob(val_))*10.0 """Value = ['beta ratio','Petrosian Fractal Dimension','Hjorth Mobility']""" vaf_tt = np.array([vaf_r,vaf_pfd,vaf_hjorth_mob]) return vaf_tt
def features(mat): Kmax = 5 Tau = 4 DE = 10 M = 10 R = 0.3 Band = np.arange(1, 86) Fs = 173 DFA = pyeeg.dfa(mat) HFD = pyeeg.hfd(mat, Kmax) SVD_Entropy = pyeeg.svd_entropy(mat, Tau, DE) Fisher_Information = pyeeg.fisher_info(mat, Tau, DE) #ApEn = pyeeg.ap_entropy(mat, M, R) # very slow PFD = pyeeg.pfd(mat) Spectral_Entropy = pyeeg.spectral_entropy(mat, Band, Fs, Power_Ratio=None) sleep(0.01) return (DFA, HFD, SVD_Entropy, Fisher_Information, PFD, Spectral_Entropy)
def get_state_features(state): nof = len(state) po = 600 pfds = np.zeros((4, int(nof / po))) ap_entropy = np.zeros((4, int(nof / po))) hursts = np.zeros((4, int(nof / po))) hfd = np.zeros((4, int(nof / po))) bins = np.zeros(((int(nof / po), 4, 2, 5))) lastnum = 0 for i in range(0, (int(nof / po))): channels = np.zeros((4, po)) for x in range(0, po): for y in range(0, 4): channels[y, x] = float(state[lastnum + x, y]) for x in range(0, 4): channels[x] = scipy.signal.savgol_filter(channels[x], 11, 3, deriv=0, delta=1.0, axis=-1, mode='interp', cval=0.0) #alpha=[] if ((nof - lastnum) != 0): for x in range(0, 4): hursts[x, i] = pyeeg.hurst(channels[x]) pfds[x, i] = pyeeg.pfd(channels[x]) #ap_entropy[x,i] = pyeeg.ap_entropy(X, M, R) hfd[x, i] = pyeeg.hfd(channels[x], 15) bins[i, x] = pyeeg.bin_power(channels[x], [0.5, 4, 7, 12, 15, 18], 200) k = 1 lastnum = lastnum + po return pfds, hursts, bins, hfd
def get_features(signal): #print(signal) freq_cutoffs = [3, 8, 12, 27, 50] features = [] features.append(rms(signal)) s = lpf(signal, SAMPLING_RATE, freq_cutoffs[0]) features.append(rms(s)) for i in range(len(freq_cutoffs) - 1): s = bp(signal, SAMPLING_RATE, freq_cutoffs[i], freq_cutoffs[i + 1]) features.append(rms(s)) fourier = np.fft.rfft(signal * np.hamming(signal.size)) features.extend(abs(fourier)) wsize = 64 X = mne.time_frequency.stft(signal, wsize, verbose=False) freqs = np.reshape(abs(X), X.size) features.extend(freqs) features.append(pyeeg.hurst(signal)) features.append(pyeeg.hfd(signal, 10)) e = pyeeg.spectral_entropy(signal, np.append(0.5, freq_cutoffs), SAMPLING_RATE) features.append(e) features.extend(pyeeg.hjorth(signal)) features.append(pyeeg.pfd(signal)) features.append(pyeeg.mean(signal)) features.append(scipy.stats.skew(signal)) features.append(scipy.stats.kurtosis(signal)) #features.extend(signal) return features
def get_features(signal): #print(signal) freq_cutoffs = [3, 8, 12, 27, 50] features = [] features.append(rms(signal)) s = lpf(signal, SAMPLING_RATE, freq_cutoffs[0]) features.append(rms(s)) for i in range(len(freq_cutoffs)-1): s = bp(signal, SAMPLING_RATE, freq_cutoffs[i], freq_cutoffs[i+1]) features.append(rms(s)) fourier = np.fft.rfft(signal * np.hamming(signal.size)) features.extend(abs(fourier)) wsize = 64 X = mne.time_frequency.stft(signal, wsize, verbose=False) freqs = np.reshape(abs(X), X.size) features.extend(freqs) features.append(pyeeg.hurst(signal)) features.append(pyeeg.hfd(signal, 10)) e = pyeeg.spectral_entropy(signal, np.append(0.5, freq_cutoffs), SAMPLING_RATE) features.append(e) features.extend(pyeeg.hjorth(signal)) features.append(pyeeg.pfd(signal)) features.append(pyeeg.mean(signal)) features.append(scipy.stats.skew(signal)) features.append(scipy.stats.kurtosis(signal)) #features.extend(signal) return features
def eeg_features(data): data = np.asarray(data) res = np.zeros([22]) Kmax = 5 # M = 10 # R = 0.3 Band = [1, 5, 10, 15, 20, 25] Fs = 256 power, power_ratio = pyeeg.bin_power(data, Band, Fs) f, P = welch(data, fs=Fs, window='hanning', noverlap=0, nfft=int(256.)) # Signal power spectrum area_freq = cumtrapz(P, f, initial=0) res[0] = np.sqrt(np.sum(np.power(data, 2)) / data.shape[0]) # amplitude RMS res[1] = statistics.stdev(data)**2 # variance res[2] = kurtosis(data) # kurtosis res[3] = skew(data) # skewness res[4] = max(data) # max amplitude res[5] = min(data) # min amplitude res[6] = len(argrelextrema( data, np.greater)[0]) # number of local extrema or peaks res[7] = ((data[:-1] * data[1:]) < 0).sum() # number of zero crossings res[8] = pyeeg.hfd(data, Kmax) # Higuchi Fractal Dimension res[9] = pyeeg.pfd(data) # Petrosian Fractal Dimension res[10] = pyeeg.hurst(data) # Hurst exponent res[11] = pyeeg.spectral_entropy( data, Band, Fs, Power_Ratio=power_ratio) # spectral entropy (1.21s) res[12] = area_freq[-1] # total power res[13] = f[np.where(area_freq >= res[12] / 2)[0][0]] # median frequency res[14] = f[np.argmax(P)] # peak frequency res[15], res[16] = pyeeg.hjorth(data) # Hjorth mobility and complexity res[17] = power_ratio[0] res[18] = power_ratio[1] res[19] = power_ratio[2] res[20] = power_ratio[3] res[21] = power_ratio[4] # res[22] = pyeeg.samp_entropy(data, M, R) # sample entropy # res[23] = pyeeg.ap_entropy(data, M, R) # approximate entropy (1.14s) return (res)
def StatisticalFeatures(self, data): mean = np.mean(data) # Mean of data std = np.std(data) # std of data pfd = pyeeg.pfd(data) # Petrosian Fractal Dimension hurst = pyeeg.hurst(data) # Hurst Exponent Feature dfa = pyeeg.dfa(data) # Detrended Fluctuation Analysis corr = nolds.corr_dim(data, 1) # Correlation Dimension Feature power = np.sum(np.abs(data)**2) / len(data) # Power feature FD = hfda(data, 5) # fractal dimension statistics = { "mean": mean, "std": std, "pfd": pfd, "hurst": hurst, "hjorth": hjorth, "dfa": dfa, "corr": corr, "power": power } return (statistics)
def extract_features(couple_data): pca1 = pca_project_data(couple_data, 1) #take 1st pca dimension pca1_mean = np.mean(pca1, axis=0) # pca1_std = np.std(pca1, axis=0) # pca1_med = np.median(pca1, axis=0) # features = [] def sinuosity_deviation_features(seq, mean, std): sinuosity_dict = {"A":0, "B":0, "C":0} deviation_dict = {"I":0, "II":0, "III":0} sinuosity_deviation_dict = {"A-I":0,"A-II":0,"A-III":0,"B-I":0,"B-II":0,"B-III":0,"C-I":0,"C-II":0,"C-III":0} n = len(seq) for i in range(1,n-1): current_af = seq[i] prev_af = seq[i-1] next_af = seq[i+1] sinu = abs((next_af - current_af) + (current_af - prev_af)) if sinu == 0: label1 = "A" elif 0< sinu <= 1: label1 = "B" else: label1 = 'C' sinuosity_dict[label1] += 1 devi = abs(current_af - mean) close = std / 2 if devi <= close: label2 = "I" elif devi <= std: label2 = "II" elif devi > std: label2 = "III" deviation_dict[label2] += 1 sinuosity_deviation_dict["%s-%s"%(label1,label2)] += 1 return sinuosity_deviation_dict.values() n = len(pca1) pca1_sinuosity_deviation = sinuosity_deviation_features( pca1, pca1_mean, pca1_std ) features += list(np.array(pca1_sinuosity_deviation)/float(n-2)) seq = pca1 dfa = eg.dfa(seq); pfd = eg.pfd(seq) apen = eg.ap_entropy(seq,1,np.std(seq)*.2) svden = eg.svd_entropy(seq, 2, 2) features += [pca1_mean, pca1_med, pca1_std, dfa, pfd, apen, svden] return features
def get_state_features(channel): nof = len(channel) pfds = np.zeros((4)) ap_entropy = np.zeros((4)) hursts = np.zeros((4)) hfd = np.zeros((4)) bins = np.zeros(((4, 2, 5))) lastnum = 0 #alpha=[] if ((nof - lastnum) != 0): for x in range(0, 4): hursts[x] = pyeeg.hurst(channel[x]) pfds[x] = pyeeg.pfd(channel[x]) #ap_entropy[x,i] = pyeeg.ap_entropy(X, M, R) hfd[x] = pyeeg.hfd(channel[x], 15) bins[x] = pyeeg.bin_power(channel[x], [0.5, 4, 7, 12, 15, 18], 200) delta = np.zeros((4)) beta = np.zeros((4)) alpha = np.zeros((4)) theta = np.zeros((4)) dfas = np.zeros((4)) bt = np.zeros((4)) for y in range(0, 4): delta[y] = bins[y, 0, 0] theta[y] = bins[y, 0, 1] alpha[y] = bins[y, 0, 2] beta[y] = bins[y, 0, 4] bt[y] = theta[y] / beta[y] lastnum = lastnum + nof return pfds, dfas, hursts, bins, bt, hfd
def get_features(sig, sampling_rate=250.0): #print(signal) # freq_cutoffs = [3, 8, 12, 27, 40, 59, 61, 80, 100, 120] features = [] # features.append(rms(sig)) # s = lpf(sig, freq_cutoffs[0], sampling_rate) # features.append(rms(s)) # for i in range(len(freq_cutoffs)-1): # s = bp(sig, freq_cutoffs[i], freq_cutoffs[i+1], sampling_rate) # features.append(rms(s)) # fourier = np.fft.rfft(sig * np.hamming(sig.size)) # features.extend(abs(fourier)) # features.append(pyeeg.hurst(sig)) # features.append(pyeeg.hfd(sig, 10)) # e = pyeeg.spectral_entropy(sig, np.append(0.5, freq_cutoffs), sampling_rate) # features.append(e) # very fast, but slow overall =/ features.extend(pyeeg.hjorth(sig)) features.append(pyeeg.pfd(sig)) features.append(np.mean(sig)) features.append(np.std(sig)) features.append(scipy.stats.skew(sig)) features.append(scipy.stats.kurtosis(sig)) #features.extend(sig) return features
def get_features(sig, sampling_rate = 250.0): #print(signal) # freq_cutoffs = [3, 8, 12, 27, 40, 59, 61, 80, 100, 120] features = [] # features.append(rms(sig)) # s = lpf(sig, freq_cutoffs[0], sampling_rate) # features.append(rms(s)) # for i in range(len(freq_cutoffs)-1): # s = bp(sig, freq_cutoffs[i], freq_cutoffs[i+1], sampling_rate) # features.append(rms(s)) # fourier = np.fft.rfft(sig * np.hamming(sig.size)) # features.extend(abs(fourier)) # features.append(pyeeg.hurst(sig)) # features.append(pyeeg.hfd(sig, 10)) # e = pyeeg.spectral_entropy(sig, np.append(0.5, freq_cutoffs), sampling_rate) # features.append(e) # very fast, but slow overall =/ features.extend(pyeeg.hjorth(sig)) features.append(pyeeg.pfd(sig)) features.append(np.mean(sig)) features.append(np.std(sig)) features.append(scipy.stats.skew(sig)) features.append(scipy.stats.kurtosis(sig)) #features.extend(sig) return features
def advanced_statistics(signal, fs=128): K_boundary = 10 # to be tuned t_fisher = 12 # to be tuned d_fisher = 40 # to be tuned features_num = 11 threshold = 0.0009 advanced_stats = np.zeros((signal.shape[0], features_num)) print("Gathering advanced statistics...") for i in tqdm((np.arange(signal.shape[0]))): feat_array = np.array([ pyeeg.fisher_info(signal[i, :], t_fisher, d_fisher), pyeeg.pfd(signal[i, :]), pyeeg.dfa(signal[i, :]), pyeeg.hfd(signal[i, :], K_boundary), np.sum((abs(signal[i, :])**(-0.3)) > 20), np.sum((abs(signal[i, :])) > threshold), np.std(abs(signal[i, :])**(0.05)), np.sqrt(np.mean(np.power(np.diff(signal[i, :]), 2))), np.mean(np.abs(np.diff(signal[i, :]))), np.mean(signal[i, :]**5), np.sum(signal[i, :]**2) ]) advanced_stats[i, :] = feat_array return advanced_stats
def calculate_features(samples): data = samples if not samples: print("no samples") return [] band = [0.5, 4, 7, 12, 30] a = randn(4097) # approx = pyeeg.ap_entropy(data, 5, 1) approx = 0 DFA = pyeeg.dfa(data) first_order_diff = [data[i] - data[i - 1] for i in range(1, len(data))] fisher_info = pyeeg.fisher_info(data, 1, 1, W=None) embed_seq = pyeeg.embed_seq(data, 1, 1) hfd = pyeeg.hfd(data, 6) hjorth = pyeeg.hjorth(data, D=None) hurst = pyeeg.hurst(data) PFD = pyeeg.pfd(data) sam_ent = pyeeg.samp_entropy(data, 1, 2) spectral_entropy = pyeeg.spectral_entropy(data, band, 256, Power_Ratio=None) svd = pyeeg.svd_entropy(data, 6, 4, W=None) PSI = pyeeg.bin_power(data, band, 256) # # Power Spectral Intensity (PSI) and Relative Intensity Ratio (RIR) Two 1- D v ec t o rs # # print("bin_power = ", PSI) # # Petrosian Fractal Dimension (PFD) Ascalar # print("PFD = ", PFD) # # Higuchi Fractal Dimension (HFD) Ascalar # print("hfd = ", hfd) # # Hjorth mobility and complexity Two s c a la rs # print("hjorth = ", hjorth) # # Spectral Entropy (Shannon’s entropy of RIRs) Ascalar # print("spectral_entropy = ", spectral_entropy) # # SVD Entropy Ascalar # print("svd = ", svd) # # Fisher Information Ascalar # print("fisher_info = ", fisher_info) # # Approximate Entropy (ApEn) Ascalar # print("approx entrophy = ", approx) # # Detrended Fluctuation Analysis (DFA) Ascalar # print("DFA = ", DFA) # # HurstExponent(Hurst) Ascalar # print("Hurst_Exponent = ", hurst) # # Build a set of embedding sequences from given time series X with lag Tau and embedding dimension # print("embed_seq = ", embed_seq) # # Compute the first order difference of a time series. # print("first_order_diff = ", first_order_diff) return { 'approximate': approx, 'DFA': DFA, 'fisher_info': fisher_info, 'embed_seq': embed_seq, 'hfd': hfd, 'hjorth': hjorth, 'hurst': hurst, 'PFD': PFD, 'sam_ent': sam_ent, 'spectral_entropy': spectral_entropy, 'svd': svd, 'PSI': PSI, 'first_order_diff': first_order_diff }
hfft = h[0:len(h) // 2] max = 0 maxIndex = 0 for i in range(len(hfft)): if hfft[i] > max: max = hfft[i] maxIndex = i freq_fond = signal_freq[maxIndex] fftmax_features_test.append(freq_fond) ########### Mise en place de nouvelles variables '''Petrosian Fractal Dimension (PFD)''' ###Okay pfd_features_train = [] for i in range(X_train.shape[0]): ##print i h = pfd(X_train[i, ]) pfd_features_train.append(h) pfd_features_test = [] for i in range(X_test.shape[0]): ##print i h = pfd(X_test[i, ]) pfd_features_test.append(h) '''Higuchi Fractal Dimension (HFD) ''' ##Okay hfd_features_train = [] for i in range(X_train.shape[0]): ##print i h = hfd(X_train[i, ], 5) hfd_features_train.append(h) hfd_features_test = []
def get_state_features(state): nof = len(state) po = 600 pfds = np.zeros((4,int(nof/po))) ap_entropy = np.zeros((4,int(nof/po))) hursts = np.zeros((4,int(nof/po))) hfd = np.zeros((4,int(nof/po))) bins = np.zeros(((int(nof/po),4,2,5))) lastnum=0 for i in range (0,(int(nof/po))): channels = np.zeros((4,po)) channels2 = np.zeros((4,po)) channels3 = np.zeros((4,po)) channels4 = np.zeros((4,po)) channels5 = np.zeros((4,po)) for x in range(0,po): for y in range(0,4): channels[y,x] = float(state[lastnum+x,y]) for y in range(0,4): channels[y] = scipy.signal.savgol_filter(channels[y], 11, 3, deriv=0, delta=1.0, axis=-1, mode='interp', cval=0.0) #for y in range(0,4): #nyq = 0.5 * 200 #low = 1 / nyq #high = 50 / nyq #high2 = 70 / nyq #high3 = 90 / nyq #high4 = 95 / nyq #b, a = butter(5, [low, high], btype='band') #b2, a2 = butter(5, [low, high2], btype='band') #b3, a3 = butter(5, [low, high3], btype='band') #b4, a4 = butter(5, [low, high4], btype='band') #channels2[y] = lfilter(b, a, channels[y]) #channels3[y] = lfilter(b2, a2, channels[y]) #channels4[y] = lfilter(b3, a3, channels[y]) #channels5[y] = lfilter(b4, a4, channels[y]) #x = np.linspace(0,len(channels[1]),len(channels[1])) #f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row') #f.suptitle("Time Series") #ax1.set_ylabel('Amplitude (uV)') #ax1.plot(x, channels2[0],color='red') #ax1.plot(x, channels3[0],color='blue') #ax1.plot(x, channels4[0],color='blue') #ax1.plot(x, channels[0]) #ax1.plot(x, channels5[0],color='yellow') #ax1.plot(x, y4) #ax1.plot(x, y5,color='red') #ax1.plot(x, y4,color='green') #ax1.set_title('Fp1') #ax2.plot(x, channels2[1],color='red') #ax2.plot(x, channels3[1],color='blue') #ax2.plot(x, channels4[1],color='blue') #ax2.plot(x, channels[1]) #ax2.plot(x, y5) #ax2.set_title('Fp2') #ax3.plot(x, channels2[2],color='red') #ax3.plot(x, channels3[2],color='blue') #ax3.plot(x, channels4[2],color='blue') #ax3.plot(x,channels[2]) #ax3.plot(x,y6) #ax3.set_title('O1') #ax3.set_xlabel('sample') #ax3.set_ylabel('Amplitude (uV)') #ax4.plot(x, channels2[3],color='red') #ax4.plot(x, channels3[3],color='blue') #ax4.plot(x, channels4[3],color='blue') #ax4.plot(x,channels[3]) #ax4.plot(x,y6) #ax4.set_title('O2') #ax4.set_xlabel('sample') #plt.show() if((nof-lastnum)!=0): for x in range(0,4): hursts[x,i] = pyeeg.hurst(channels[x]) pfds[x,i] = pyeeg.pfd(channels[x]) #ap_entropy[x,i] = pyeeg.ap_entropy(X, M, R) hfd[x,i] = pyeeg.hfd(channels[x],15) bins[i,x] = pyeeg.bin_power(channels[x], [0.5,4,7,12,15,18], 200) k=1 lastnum=lastnum+po return pfds,dfas,hursts,bins,hfd
for i in range(len(hfft)): if hfft[i] > max: max = hfft[i] maxIndex = i freq_fond = signal_freq[maxIndex] fftmax_features_test.append(freq_fond) ########### Mise en place de nouvelles variables """Petrosian Fractal Dimension (PFD)""" ###Okay pfd_features_train = [] for i in range(X_train.shape[0]): ##print i h = pfd(X_train[i,]) pfd_features_train.append(h) pfd_features_test = [] for i in range(X_test.shape[0]): ##print i h = pfd(X_test[i,]) pfd_features_test.append(h) """Higuchi Fractal Dimension (HFD) """ ##Okay hfd_features_train = [] for i in range(X_train.shape[0]): ##print i h = hfd(X_train[i,], 5) hfd_features_train.append(h)
def pfd4(X): return pyeeg.pfd(X[3])
def compute_pyeeg_feats(self, rec): # these values are taken from the tuh paper TAU, DE, Kmax = 4, 10, 5 pwrs, pwrrs, pfds, hfds, mblts, cmplxts, ses, svds, fis, hrsts = [], [], [], [], [], [], [], [], [], [] dfas, apes = [], [] for window_id, window in enumerate(rec.signals): for window_electrode_id, window_electrode in enumerate(window): # taken from pyeeg code / paper electrode_diff = list(np.diff(window_electrode)) M = pyeeg.embed_seq(window_electrode, TAU, DE) W = scipy.linalg.svd(M, compute_uv=False) W /= sum(W) power, power_ratio = self.bin_power(window_electrode, self.bands, rec.sampling_freq) pwrs.extend(list(power)) # mean of power ratio is 1/(len(self.bands)-1) pwrrs.extend(list(power_ratio)) pfd = pyeeg.pfd(window_electrode, electrode_diff) pfds.append(pfd) hfd = pyeeg.hfd(window_electrode, Kmax=Kmax) hfds.append(hfd) mobility, complexity = pyeeg.hjorth(window_electrode, electrode_diff) mblts.append(mobility) cmplxts.append(complexity) se = self.spectral_entropy(window_electrode, self.bands, rec.sampling_freq, power_ratio) ses.append(se) svd = pyeeg.svd_entropy(window_electrode, TAU, DE, W=W) svds.append(svd) fi = pyeeg.fisher_info(window_electrode, TAU, DE, W=W) fis.append(fi) # this crashes... # ape = pyeeg.ap_entropy(electrode, M=10, R=0.3*np.std(electrode)) # apes.append(ape) # takes very very long to compute # hurst = pyeeg.hurst(electrode) # hrsts.append(hurst) # takes very very long to compute # dfa = pyeeg.dfa(electrode) # dfas.append(dfa) pwrs = np.asarray(pwrs).reshape(rec.signals.shape[0], rec.signals.shape[1], len(self.bands) - 1) pwrs = np.mean(pwrs, axis=0) pwrrs = np.asarray(pwrrs).reshape(rec.signals.shape[0], rec.signals.shape[1], len(self.bands) - 1) pwrrs = np.mean(pwrrs, axis=0) pfds = np.asarray(pfds).reshape(rec.signals.shape[0], rec.signals.shape[1]) pfds = np.mean(pfds, axis=0) hfds = np.asarray(hfds).reshape(rec.signals.shape[0], rec.signals.shape[1]) hfds = np.mean(hfds, axis=0) mblts = np.asarray(mblts).reshape(rec.signals.shape[0], rec.signals.shape[1]) mblts = np.mean(mblts, axis=0) cmplxts = np.asarray(cmplxts).reshape(rec.signals.shape[0], rec.signals.shape[1]) cmplxts = np.mean(cmplxts, axis=0) ses = np.asarray(ses).reshape(rec.signals.shape[0], rec.signals.shape[1]) ses = np.mean(ses, axis=0) svds = np.asarray(svds).reshape(rec.signals.shape[0], rec.signals.shape[1]) svds = np.mean(svds, axis=0) fis = np.asarray(fis).reshape(rec.signals.shape[0], rec.signals.shape[1]) fis = np.mean(fis, axis=0) return list(pwrs.ravel()), list(pwrrs.ravel( )), pfds, hfds, mblts, cmplxts, ses, svds, fis, apes, hrsts, dfas
def pfd1(X): return pyeeg.pfd(X[0])
def myFeaturesExtractor( X, myM, myV): # X has to be a matrix where each row is a channel N = len(X) # number of channels L = len(X[0]) maxtLyap = min(500, L // 2 + L // 4) lyapLags = np.arange(maxtLyap) / Fs # get number of features nFeatures = nMono * N + N * (N - 1) / 2 # here we initialize the list of features // We will transform it to an array later featList = np.zeros((int(nFeatures))) # deal with monovariate features first for kChan in range(N): kFeat = 0 mySig = X[kChan, :] #========== Stats ======================== myMean = myM[kChan] featList[nMono * kChan + kFeat] = myMean kFeat += 1 myMax = max(mySig) featList[nMono * kChan + kFeat] = myMax kFeat += 1 myMin = min(mySig) featList[nMono * kChan + kFeat] = myMin kFeat += 1 peak = max(abs(np.array([myMin, myMax]))) featList[nMono * kChan + kFeat] = peak kFeat += 1 myVar = myV[kChan] featList[nMono * kChan + kFeat] = myVar kFeat += 1 featList[nMono * kChan + kFeat] = sp.skew(mySig) kFeat += 1 featList[nMono * kChan + kFeat] = sp.kurtosis(mySig) kFeat += 1 myRMS = rms(mySig) featList[nMono * kChan + kFeat] = myRMS kFeat += 1 featList[nMono * kChan + kFeat] = peak / myRMS kFeat += 1 featList[nMono * kChan + kFeat] = totVar(mySig) kFeat += 1 featList[nMono * kChan + kFeat] = pyeeg.dfa(mySig) kFeat += 1 featList[nMono * kChan + kFeat] = pyeeg.hurst(mySig) kFeat += 1 hMob, hComp = pyeeg.hjorth(mySig) featList[nMono * kChan + kFeat] = hMob kFeat += 1 featList[nMono * kChan + kFeat] = hComp kFeat += 1 ## ======== fractal ======================== # Now we need to get the embeding time lag Tau and embeding dmension ac = delay.acorr(mySig, maxtau=maxTauLag, norm=True, detrend=True) Tau = firstTrue(ac < corrThresh) # embeding delay f1 , f2 , f3 = dimension.fnn(mySig, dim=dim, tau=Tau, R=10.0, A=2.0, metric='euclidean',\ window=10,maxnum=None, parallel=True) myEmDim = firstTrue(f3 < fracThresh) # Here we construct the Embeding Matrix Em Em = pyeeg.embed_seq(mySig, Tau, myEmDim) U, s, Vh = linalg.svd(Em) W = s / np.sum(s) # list of singular values in decreasing order FInfo = pyeeg.fisher_info(X, Tau, myEmDim, W=W) featList[nMono * kChan + kFeat] = FInfo kFeat += 1 featList[nMono * kChan + kFeat] = Tau kFeat += 1 featList[nMono * kChan + kFeat] = myEmDim kFeat += 1 #======================================== PFD = pyeeg.pfd(mySig, D=None) hfd6 = pyeeg.hfd(mySig, 6) hfd10 = pyeeg.hfd(mySig, 10) # Now we fit aline and get its slope to have Lyapunov exponent divAvg = lyapunov.mle(Em, maxt=maxtLyap, window=3 * Tau, metric='euclidean', maxnum=None) poly = np.polyfit(lyapLags, divAvg, 1, rcond=None, full=False, w=None, cov=False) LyapExp = poly[0] featList[nMono * kChan + kFeat] = PFD kFeat += 1 featList[nMono * kChan + kFeat] = hfd6 kFeat += 1 featList[nMono * kChan + kFeat] = hfd10 kFeat += 1 featList[nMono * kChan + kFeat] = LyapExp kFeat += 1 ## ======== Entropy ======================== tolerance = 1 / 4 entropyDim = max([myEmDim, PFD]) featList[nMono * kChan + kFeat] = pyeeg.samp_entropy( mySig, entropyDim, tolerance) kFeat += 1 featList[nMono * kChan + kFeat] = pyeeg.svd_entropy(mySig, Tau, myEmDim, W=W) kFeat += 1 # here we compute bin power power, power_Ratio = pyeeg.bin_power(mySig, freqBins, Fs) featList[nMono * kChan + kFeat] = pyeeg.spectral_entropy( mySig, freqBins, Fs, Power_Ratio=power_Ratio) kFeat += 1 ## ======== Spectral ======================== for kBin in range(len(freqBins) - 1): featList[nMono * kChan + kFeat] = power[kBin] kFeat += 1 featList[nMono * kChan + kFeat] = power_Ratio[kBin] kFeat += 1 # deal with multivariate features first #============ connectivity ================== corrList = connectome(X) nConnect = len(corrList) if N * (N - 1) / 2 != nConnect: raise ValueError('incorrect number of correlation coeffs') for kC in range(nConnect): featList[-nConnect + kC] = corrList[kC] return featList
def PFD(x): resp = pyeeg.pfd(x) return resp
def myFeaturesExtractor(X): # X has to be a matrix where each row is a channel N = len(X) # L = len(X[0]) # here we initialize the list of features // We will transform it to an array later featList = list() timeList =list () featName =list() for kChan in range(1): mySig = X[kChan , :] if kChan == 0: start=time.perf_counter_ns() #========== Stats ======================== myMean = np.mean(mySig) featList.append(myMean) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append("mean") start=end featList.append(max(mySig)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" max") start=end featList.append(min(mySig)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" min") start=end peak =max(abs(mySig)) featList.append(peak) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" peak") start=end myVar = np.var(mySig) featList.append(myVar) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" var") start=end myVar = np.var(mySig) myStd = np.sqrt(myVar) featList.append(myStd) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" std") start=end featList.append(sp.skew(mySig)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" skew") start=end featList.append(sp.kurtosis(mySig)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" kurt") start=end myRMS = rms(mySig) featList.append(myRMS) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" rms") start=end myRMS = rms(mySig) featList.append(peak/myRMS) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" fact") start=end myRMS = rms(mySig) featList.append(myRMS/myMean) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" papr") start=end featList.append(totVar(mySig)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" totVar") start=end featList.append(pyeeg.dfa(mySig)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" dfa") start=end featList.append(pyeeg.hurst(mySig)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" hurst") start=end hMob , hComp = pyeeg.hjorth(mySig ) featList.append(hMob) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" Hmob") timeList.append(end -start) featName.append(" Hcomp") start=end featList.append(hComp) # ## ======== fractal ======================== # # Now we need to get the embeding time lag Tau and embeding dmension # ac=delay.acorr(mySig, maxtau=maxTauLag, norm=True, detrend=True) # Tau = firstTrue(ac < corrThresh) # embeding delay # featList.append(Tau) # if kChan == 0: # end=time.perf_counter_ns() # # timeList.append(end -start) # featName.append(" dCorrTime") # start=end # f1 , f2 , f3 = dimension.fnn(mySig, dim=dim, tau=Tau, R=10.0, A=2.0, metric='chebyshev', window=10,maxnum=None, parallel=True) # myEmDim = firstTrue(f3 < fracThresh) ## if kChan == 0: ## end=time.perf_counter_ns() ## timeList.append(end -start) ## featName.append(" embDim") ## start=end # # Here we construct the Embeding Matrix Em # Em = pyeeg.embed_seq(mySig, Tau, myEmDim) # U, s, Vh = linalg.svd(Em) # W = s/np.sum(s) # list of singular values in decreasing order # # FInfo = pyeeg.fisher_info(X, Tau, myEmDim , W=W) # featList.append(FInfo) # if kChan == 0: # end=time.perf_counter_ns() # # timeList.append(end -start) # featName.append(" FInfo") # start=end # # featList.append(myEmDim) PFD = pyeeg.pfd(mySig, D=None) featList.append(PFD) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" pfd") start=end hfd6 = pyeeg.hfd(mySig , 6) featList.append(hfd6) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" hfd6") start=end hfd10 = pyeeg.hfd(mySig , 10) featList.append(hfd10) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" hfd10") start=end # Now we fit aline and get its slope to have Lyapunov exponent # divAvg = lyapunov.mle(Em, maxt=maxtLyap, window= 3 * Tau, metric='euclidean', maxnum=None) # poly = np.polyfit(lyapLags, divAvg, 1, rcond=None, full=False, w=None, cov=False) # LyapExp = poly[0] # featList.append(np.mean(LyapExp)) # if kChan == 0: # end=time.perf_counter_ns() # # timeList.append(end -start) # featName.append("Lyapunov") # start=end ## ======== Entropy ======================== # here we compute bin power power, power_Ratio = pyeeg.bin_power(mySig , freqBins , Fs ) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append("Spectral") start=end featList.append( pyeeg.spectral_entropy(mySig, freqBins, Fs, Power_Ratio=power_Ratio)) if kChan == 0: end=time.perf_counter_ns() timeList.append(end -start) featName.append(" specEn") start=end # tolerance = myStd / 4 # entropyDim = max([myEmDim , PFD]) # featList.append( pyeeg.samp_entropy(mySig , entropyDim , tolerance ) ) # if kChan == 0: # end=time.perf_counter_ns() # # timeList.append(end -start) # featName.append(" sampEn") # start=end # featList.append( pyeeg.svd_entropy(mySig, Tau, myEmDim , W=W) ) # if kChan == 0: # end=time.perf_counter_ns() # # timeList.append(end -start) # featName.append(" svdEn") # start=end ## ======== Spectral ======================== appendArray2List(featList , power ) appendArray2List(featList , power_Ratio ) start=time.perf_counter_ns() connectome(X , featList) end=time.perf_counter_ns() timeList.append((end -start)/N/(N-1)*2) featName.append("connectivity") ll=list() ll.append(featName) ll.append(timeList) return np.asarray(featList) , ll
"times": 100, "name": "hjorth", "is_original": True, "fun": lambda x: pyeeg.hjorth(x) }, { "times": 100, "name": "hjorth", "is_original": False, "fun": lambda x: univ.hjorth(x) }, { "times": 100, "name": "pfd", "is_original": True, "fun": lambda x: pyeeg.pfd(x) }, { "times": 100, "name": "pfd", "is_original": False, "fun": lambda x: pyeeg.pfd(x) }, { "times": 2, "name": "samp_ent", "is_original": True, "fun": lambda x: pyeeg.samp_entropy(x, 2, 1.5) }, { "times": 10,
def feature_wave(self, toolName=None, Fs=256): if (toolName == None): print('please select a tool') return if toolName in self.FeatureSet.dict[0]: index = self.FeatureSet.dict[0][toolName] else: index = -1 print(toolName) if toolName == 'DWT': answer_train = DWT(self.DataSet.trainSet_data[0], 'db4') answer_test = DWT(self.DataSet.testSet_data[0], 'db4') print('DWT feature extraction succeed db4') elif toolName == 'hurst': answer_train = [ pyeeg.hurst(i) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.hurst(i) for i in self.DataSet.testSet_data[0] ] print('hurst feature extraction succeed') elif toolName == 'dfa': answer_train = [ pyeeg.dfa(i, L=[4, 8, 16, 32, 64]) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.dfa(i, L=[4, 8, 16, 32, 64]) for i in self.DataSet.testSet_data[0] ] print('dfa feature extraction succeed') elif toolName == 'fisher_info': answer_train = [ pyeeg.fisher_info(i, 2, 20) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.fisher_info(i, 2, 20) for i in self.DataSet.testSet_data[0] ] print('fisher_info feature extraction succeed') elif toolName == 'svd_entropy': answer_train = [ pyeeg.svd_entropy(i, 2, 20) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.svd_entropy(i, 2, 20) for i in self.DataSet.testSet_data[0] ] print('svd_entropy feature extraction succeed') elif toolName == 'spectral_entropy': bandlist = [0.5, 4, 7, 12, 30, 100] answer_train = [ pyeeg.spectral_entropy(i, bandlist, Fs) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.spectral_entropy(i, bandlist, Fs) for i in self.DataSet.testSet_data[0] ] print('spectral_entropy feature extraction succeed') elif toolName == 'hjorth': # 得到两个量 第一个是 mobility 第二个是 complexity answer_train = [ pyeeg.hjorth(i) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.hjorth(i) for i in self.DataSet.testSet_data[0] ] answer_train = np.array(answer_train) answer_test = np.array(answer_test) for i in answer_train: i[1] = i[1] / 100 for i in answer_test: i[1] = i[1] / 100 #只取Mobility answer_train = np.array(answer_train[:, 0]) answer_test = np.array(answer_test[:, 0]) print('hjorth feature extraction succeed') elif toolName == 'hfd': answer_train = [ pyeeg.hfd(i, 8) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.hfd(i, 8) for i in self.DataSet.testSet_data[0] ] print('hfd feature extraction succeed') elif toolName == 'pfd': answer_train = [ pyeeg.pfd(i) for i in self.DataSet.trainSet_data[0] ] answer_test = [pyeeg.pfd(i) for i in self.DataSet.testSet_data[0]] print('pfd feature extraction succeed') elif toolName == 'bin_power': bandlist = [0.5, 4, 7, 12] #,30,100] answer_train = [ pyeeg.bin_power(i, bandlist, Fs) for i in self.DataSet.trainSet_data[0] ] answer_test = [ pyeeg.bin_power(i, bandlist, Fs) for i in self.DataSet.testSet_data[0] ] print('bin_power feature extraction succeed') else: print('does not have this kind of mode') answer_train = np.array(answer_train) answer_train = answer_train.reshape(len(answer_train), -1) answer_test = np.array(answer_test) answer_test = answer_test.reshape(len(answer_test), -1) if index == -1: #print(len(self.FeatureSet.feature.trainSet_feat[0]),len(answer_train)) self.FeatureSet.feature.trainSet_feat[0] = np.column_stack( (self.FeatureSet.feature.trainSet_feat[0], answer_train)) self.FeatureSet.feature.testSet_feat[0] = np.column_stack( (self.FeatureSet.feature.testSet_feat[0], answer_test)) self.FeatureSet.dict[0][toolName] = [ self.FeatureSet.size[0], self.FeatureSet.size[0] + len(answer_train[0]) ] self.FeatureSet.size[0] += len(answer_train[0]) else: self.FeatureSet.feature.trainSet_feat[0][:, index[0]:index[1]] = [ i for i in answer_train ] self.FeatureSet.feature.testSet_feat[0][:, index[0]:index[1]] = [ i for i in answer_test ]
def myFeaturesExtractor1( X, myM, myV, myMin, myMax): # X has to be a matrix where each row is a channel N = len(X) # number of channels # L = len(X[0]) # get number of features nFeatures = nMono * N + N * (N - 1) / 2 # here we initialize the list of features // We will transform it to an array later featList = np.zeros((int(nFeatures))) # deal with monovariate features first for kChan in range(N): kFeat = 0 mySig = X[kChan, :] #========== Stats ======================== myMean = myM[kChan] featList[nMono * kChan + kFeat] = myMean kFeat += 1 featList[nMono * kChan + kFeat] = myMax[kChan] kFeat += 1 featList[nMono * kChan + kFeat] = myMin[kChan] kFeat += 1 myVar = myV[kChan] featList[nMono * kChan + kFeat] = myVar kFeat += 1 featList[nMono * kChan + kFeat] = sp.skew(mySig) kFeat += 1 featList[nMono * kChan + kFeat] = sp.kurtosis(mySig) kFeat += 1 featList[nMono * kChan + kFeat] = pyeeg.dfa(mySig) kFeat += 1 hMob, hComp = pyeeg.hjorth(mySig) featList[nMono * kChan + kFeat] = hMob kFeat += 1 featList[nMono * kChan + kFeat] = hComp kFeat += 1 ## ======== fractal ======================== # Now we need to get the embeding time lag Tau and embeding dmension ac = delay.acorr(mySig, maxtau=maxTauLag, norm=True, detrend=True) Tau = firstTrue(ac < corrThresh) # embeding delay featList[nMono * kChan + kFeat] = Tau kFeat += 1 PFD = pyeeg.pfd(mySig, D=None) hfd10 = pyeeg.hfd(mySig, 10) featList[nMono * kChan + kFeat] = PFD kFeat += 1 featList[nMono * kChan + kFeat] = hfd10 kFeat += 1 ## ======== Entropy ======================== # here we compute bin power power, power_Ratio = pyeeg.bin_power(mySig, freqBins, Fs) featList[nMono * kChan + kFeat] = pyeeg.spectral_entropy( mySig, freqBins, Fs, Power_Ratio=power_Ratio) kFeat += 1 ## ======== Spectral ======================== for kBin in range(len(freqBins) - 1): featList[nMono * kChan + kFeat] = power[kBin] kFeat += 1 featList[nMono * kChan + kFeat] = power_Ratio[kBin] kFeat += 1 # deal with multivariate features first #============ connectivity ================== corrList = connectome(X) nConnect = len(corrList) if N * (N - 1) / 2 != nConnect: raise ValueError('incorrect number of correlation coeffs') for kC in range(nConnect): featList[-nConnect + kC] = corrList[kC] return featList
def PFD(self): resp = pyeeg.pfd(self.channel_data) return [np.array([resp]), ['PFD']]
def petrosian_fractal_dimension(samples, **kwargs): try: differential_sequence = kwargs[DIFF_SEQ] except KeyError: differential_sequence = DIFF_SEQ_DEFAULT return pyeeg.pfd(samples, D=differential_sequence)
def PFD(self): resp = pyeeg.pfd(self.channel_data) return [np.array([resp]),['PFD']]
def find_pfd(self): self.pfd = pyeeg.pfd(self.filtered_signal, self.first_order_diff)
import sys MIN_EPOCH_N = 256 * 5 MAX_EPOCH_N = 256 * 30 EPOCH_STEP = 256 * 5 N_REPLICATES = 5 SPECT_ENT_BANDS = 2 ** np.arange(0,8)/2 fun_to_test = [ {"times":100,"name":"hfd", "is_original":True,"fun": lambda x: pyeeg.hfd(x,2**3)}, {"times":100,"name":"hfd", "is_original":False,"fun": lambda x: univ.hfd(x,2**3)}, {"times":100,"name":"hjorth", "is_original":True,"fun": lambda x: pyeeg.hjorth(x)}, {"times":100,"name":"hjorth", "is_original":False,"fun": lambda x: univ.hjorth(x)}, {"times":100,"name":"pfd", "is_original":True, "fun":lambda x: pyeeg.pfd(x)}, {"times":100,"name":"pfd", "is_original":False, "fun":lambda x: pyeeg.pfd(x)}, {"times":2,"name":"samp_ent", "is_original":True, "fun":lambda x: pyeeg.samp_entropy(x,2,1.5)}, {"times":10,"name":"samp_ent", "is_original":False, "fun":lambda x: univ.samp_entropy(x,2,1.5,relative_r=False)}, {"times":2,"name":"ap_ent", "is_original":True, "fun":lambda x: pyeeg.ap_entropy(x,2,1.5)}, {"times":10,"name":"ap_ent", "is_original":False, "fun":lambda x: univ.ap_entropy(x,2,1.5)}, {"times":10,"name":"svd_ent", "is_original":True, "fun":lambda x: pyeeg.svd_entropy(x,2,3)}, {"times":100,"name":"svd_ent", "is_original":False, "fun":lambda x: univ.svd_entropy(x,2,3)}, {"times":10,"name":"fisher_info", "is_original":True, "fun":lambda x: pyeeg.fisher_info(x,2,3)}, {"times":100, "name":"fisher_info", "is_original":False, "fun":lambda x: univ.fisher_info(x,2,3)}, {"times":100,"name":"spectral_entropy", "is_original":True, "fun":lambda x: pyeeg.spectral_entropy(x,SPECT_ENT_BANDS,256)}, {"times":100, "name":"spectral_entropy", "is_original":False, "fun":lambda x: univ.spectral_entropy(x,256, SPECT_ENT_BANDS)}, ]
vibration_list.append(0) #print vibration_list #vibration_array = np.zeros(fft_size) #for i in range(len(vibration_list)): # index = (vibration_list[i]-1) * sampling_rate # vibration_array[index:index+sampling_rate] = 1 (power_xf, power_xf_filtered, freqs, xfp) = return_filtered_epoch(time_series) dominant_f = return_dominant_freq(freqs, power_xf_filtered) (delta_ratio, theta_ratio, alpha_ratio, sigma_ratio, beta_ratio) = return_power_ratio(freqs, power_xf_filtered) (A5_mean, D5_mean, D4_mean, D3_mean, A5_std, D5_std, D4_std, D3_std, A5_pm, D5_pm, D4_pm, D3_pm, \ A5_ratio_mean, D5_ratio_mean, D4_ratio_mean, D3_ratio_mean) = return_DWT_feature(time_series) hurst_index = pyeeg.hurst(time_series) pfd_index = pyeeg.pfd(time_series) sp_entropy = pyeeg.spectral_entropy(time_series, [0.5, 3, 8, 12, 16, 30], sampling_rate, Power_Ratio = None) hj_activity, hj_mobility, hj_complexity = pyeeg.hjorth(time_series) fmax=getfmax(time_series) fmin=getfmin(time_series) fmean=getfmean(time_series) fstd=getfstd(time_series) fvar=getfvar(time_series) fskew=getfskew(time_series) fkur=getfkur(time_series) fmd=getfmd(time_series) zcnum=getzcnum(time_series) print [fmax, fmin, fmean, fstd, fvar, fskew, fkur, fmd, zcnum, dominant_f[0], delta_ratio, \ theta_ratio, alpha_ratio, sigma_ratio, beta_ratio, A5_mean, D5_mean, D4_mean, D3_mean, \