Exemplo n.º 1
0
    def extractThetaAlphaBeta(self, x):
        '''
        :param x: eeg signal
        :return: theta, alpha, and beta of the signal
        '''
        filtered = self.preProcessing(x)
        theta = butterBandpassFilter(filtered, lowcut=4, highcut=7, fs=self.fs, order=2)
        alpha = butterBandpassFilter(filtered, lowcut=8, highcut=15, fs=self.fs, order=2)
        beta = butterBandpassFilter(filtered, lowcut=16, highcut=31, fs=self.fs, order=2)

        return theta, alpha, beta
Exemplo n.º 2
0
 def extractMFCCFeatures(self, x, winlen=2.0, stride=0.5, min_len=465):
     '''
     Compute melch frequency spectrum of EDA
     :param x: input signal
     :param winlen: windows length for framming. The default is 2.0 sec since the gradual changes in principle EDA towards stimulus is between 1.0 and 3.0 secs
     :param stride: string length for framming. The default is 0.5 sec
     :return: normalized melc coefficient
     '''
     x_len = len(x)
     len_diff = min_len - x_len
     if len_diff > 0:
         x = np.append(x, x[x_len - len_diff:])
     # print(x.shape)
     filtered = butterBandpassFilter(x,
                                     lowcut=0.03,
                                     highcut=5.,
                                     order=4,
                                     fs=self.fs)
     melcfet = mfcc(filtered,
                    samplerate=self.fs,
                    winlen=winlen,
                    winstep=stride)
     melcfet -= (np.mean(melcfet, axis=0) + 1e-18)
     # print(np.squeeze(np.squeeze(melcfet)).flatten().shape)
     return np.squeeze(np.squeeze(melcfet)).flatten()
Exemplo n.º 3
0
    def preProcessing(self, x, n=50):
        lc = 4
        hc = 55
        filtered = butterBandpassFilter(x, lowcut=lc, highcut=hc, fs=self.fs)
        smoothed = avgSlidingWindow(filtered, n=n)

        return smoothed
Exemplo n.º 4
0
    def extractCVXEDA(self, x):
        if np.std(x) < 1e-5:
            return np.array([])
        try:
            filtered = butterBandpassFilter(x,
                                            lowcut=0.03,
                                            highcut=5.,
                                            order=4,
                                            fs=self.fs)
            yn = (filtered - filtered.mean()) / filtered.std()
            [r, p, t, l, d, _, _] = cvxEDA(yn, 1. / self.fs)

            # r features
            r_mean = np.mean(r)
            r_std = np.std(r)
            r_max = np.max(r)
            r_min = np.min(r)

            # p features
            p_mean = np.mean(p)
            p_std = np.std(p)
            p_max = np.max(p)
            p_min = np.min(p)

            # t features
            t_mean = np.mean(t)
            t_std = np.std(t)
            t_max = np.max(t)
            t_min = np.min(t)

            # l features
            l_mean = np.mean(l)
            l_std = np.std(l)
            l_max = np.max(l)
            l_min = np.min(l)

            # l features
            d_mean = np.mean(d)
            d_std = np.std(d)
            d_max = np.max(d)
            d_min = np.min(d)

            return np.array([
                r_mean, r_std, r_max, r_min, p_mean, p_std, p_max, p_min,
                t_mean, t_std, t_max, t_min, l_mean, l_std, l_max, l_min,
                d_mean, d_std, d_max, d_min
            ])
        except:
            return np.array([])
Exemplo n.º 5
0
    def extractThetaAlphaBeta(self, x):
        '''
        ref:https://www.journals.elsevier.com/clinical-neurophysiology/view-for-free/guidelines-of-the-ifcn-2nd-ed-published-1999
        :param x: eeg signal
        :return: theta, alpha, and beta of the signal
        '''
        filtered = self.preProcessing(x)
        theta = butterBandpassFilter(filtered,
                                     lowcut=4,
                                     highcut=8,
                                     fs=self.fs,
                                     order=2)
        alpha_low = butterBandpassFilter(filtered,
                                         lowcut=8,
                                         highcut=10,
                                         fs=self.fs,
                                         order=2)
        alpha_high = butterBandpassFilter(filtered,
                                          lowcut=10,
                                          highcut=14,
                                          fs=self.fs,
                                          order=2)
        beta = butterBandpassFilter(filtered,
                                    lowcut=14,
                                    highcut=25,
                                    fs=self.fs,
                                    order=2)
        gamma_low = butterBandpassFilter(filtered,
                                         lowcut=25,
                                         highcut=40,
                                         fs=self.fs,
                                         order=2)
        gamma_high = butterBandpassFilter(filtered,
                                          lowcut=40,
                                          highcut=100,
                                          fs=self.fs,
                                          order=2)

        return theta, alpha_low, alpha_high, beta, gamma_low, gamma_high
Exemplo n.º 6
0
featuresExct = GSRFeatures()
for i in (0, 1, 7, 9):
    time_start = timeToInt(game_results.iloc[i]["Time_Start"])
    time_end = timeToInt(game_results.iloc[i]["Time_End"])

    skin_conductance = gsr_data[
        (gsr_data["GSR_Timestamp_Shimmer_CAL"].values >= time_start)
        & (gsr_data["GSR_Timestamp_Shimmer_CAL"].values <= time_end
           )]["GSR_GSR_Skin_Conductance_CAL"].values
    ppg = gsr_data[(gsr_data["GSR_Timestamp_Shimmer_CAL"].values >= time_start)
                   & (gsr_data["GSR_Timestamp_Shimmer_CAL"].values <= time_end
                      )]["GSR_PPG_A13_CAL"].values

    skin_conductance_f = butterBandpassFilter(skin_conductance,
                                              0.03,
                                              5.0,
                                              15.0,
                                              order=5)
    ts, ppg_f = featuresExct.computeHeartBeat(ppg.flatten(), 15.0)

    plt.plot(skin_conductance_f)
    plt.ylim([0, 1])
    plt.ylabel("Skin conductance (µS)")
    plt.savefig(save_path + str(i) + "_GSR.png")
    plt.show()
    plt.plot(ts, ppg_f)
    plt.ylim([40, 100])
    plt.ylabel("Heart rate (bpm)")
    plt.savefig(save_path + str(i) + "_PPG.png")
    plt.show()