예제 #1
0
    # script with <Ctrl-C>
    print(' Press Ctrl-C in the console to break the While Loop')
    try:

        while True:
            """ 1- ACQUIRE DATA """
            eeg_data = mules_client.getdata(
                shift_secs, False)  # Obtain EEG data from MuLES
            eeg_buffer = BCIw.updatebuffer(eeg_buffer,
                                           eeg_data)  # Update EEG buffer
            # Get newest "testing samples" from the buffer
            test_data = BCIw.getlastdata(
                eeg_buffer, win_test_secs * params['sampling frequency'])
            """ 2- COMPUTE FEATURES and CLASSIFY"""
            # Compute features on "test_data"
            feat_vector = BCIw.compute_feature_vector(
                test_data, params['sampling frequency'])
            y_hat = BCIw.classifier_test(classifier,
                                         feat_vector.reshape(1, -1), mu_ft,
                                         std_ft)

            decision_buffer = BCIw.updatebuffer(decision_buffer,
                                                np.reshape(y_hat, (-1, 1)))
            """ 3- VISUALIZE THE DECISIONS"""
            print(str(y_hat))
            plotter_decision.updatePlot(
                decision_buffer)  # Plot the decision buffer

            plt.pause(0.001)

    except KeyboardInterrupt:
예제 #2
0
 
 # The try/except structure allows to quit the while loop by aborting the 
 # script with <Ctrl-C>
 print(' Press Ctrl-C in the console to break the While Loop')
 try:    
     
     # The following loop does what we see in the diagram of Exercise 1:
     # acquire data, compute features, visualize the raw EEG and the features        
     while True:    
         
         """ 1- ACQUIRE DATA """
         eeg_data = mules_client.getdata(shift_secs, False) # Obtain EEG data from MuLES  
         eeg_data = eeg_data[:,[index_channel ,-1]] # Keep only one electrode (and the STATUS channel) for further analysis      
         eeg_buffer = BCIw.updatebuffer(eeg_buffer, eeg_data) # Update EEG buffer
         
         """ 2- COMPUTE FEATURES """
         # Get newest samples from the buffer 
         data_window = BCIw.getlastdata(eeg_buffer, win_test_secs * params['sampling frequency'])
         # Compute features on "data_window" 
         feat_vector = BCIw.compute_feature_vector(data_window, params['sampling frequency'])
         feat_buffer = BCIw.updatebuffer(feat_buffer, np.asarray([feat_vector])) # Update the feature buffer
         
         """ 3- VISUALIZE THE RAW EEG AND THE FEATURES """       
         plotter_eeg.updatePlot(eeg_buffer) # Plot EEG buffer     
         plotter_feat.updatePlot((feat_buffer)) # Plot the feature buffer 
         
         plt.pause(0.001)
         
 except KeyboardInterrupt:
     
     mules_client.disconnect() # Close connection
예제 #3
0
    # The try/except structure allows to quit the while loop by aborting the
    # script with <Ctrl-C>
    print(' Press Ctrl-C in the console to break the While Loop')
    try:
        while True:
            eeg_data = mules_client.getdata(
                shift_secs, False)  # Obtain EEG data from MuLES

            # Compute features on "eeg_data"
            if args.csp:
                #feat_vector = CSP_test(eeg_data, W_csp)
                pass

            else:
                feat_matrix0t_vector = BCIw.compute_feature_vector(
                    eeg_data, params['sampling frequency'])

            if (args.entropy):
                entropy = calc_entropy(eeg_data)
                feat_vector = np.hstack([feat_vector, entropy])

                y_hat = model.predict(normalize(feat_vector.reshape(1, -1)))

            # DECISION!!!!!!!!!

            #plt.pause(0.001)

    except KeyboardInterrupt:

        mules_client.disconnect()  # Close connection
예제 #4
0
    BCIw.beep() # Beep sound
    
    # The try/except structure allows to quit the while loop by aborting the 
    # script with <Ctrl-C>
    print(' Press Ctrl-C in the console to break the While Loop')
    try:    
        
        while True: 
            
            """ 1- ACQUIRE DATA """
            eeg_data = mules_client.getdata(shift_secs, False)
            eeg_buffer = BCIw.updatebuffer(eeg_buffer, eeg_data)
            # Get newest "testing samples" from the buffer        
            test_data = BCIw.getlastdata(eeg_buffer, win_test_secs * params['sampling frequency'])

            """ 2- COMPUTE FEATURES and CLASSIFY"""            
            # Compute features on "test_data"
            feat_vector = BCIw.compute_feature_vector(test_data, params['sampling frequency'])
            y_hat = BCIw.classifier_test(classifier, feat_vector, mu_ft, std_ft)
            
            decision_buffer = BCIw.updatebuffer(decision_buffer, np.reshape(y_hat,(-1,1)))
            
            """ 3- VISUALIZE THE DECISIONS"""           
            print str(y_hat)
            plotter_decision.updatePlot(decision_buffer) # Plot the decision buffer
            
            plt.pause(0.001)
                 
    except KeyboardInterrupt:
        
        mules_client.disconnect() # Close connection 
예제 #5
0
        # The following loop does what we see in the diagram of Exercise 1:
        # acquire data, compute features, visualize raw EEG and the features
        while True:
            """ 3.1 ACQUIRE DATA """
            # Obtain EEG data from the LSL stream
            eeg_data, timestamp = inlet.pull_chunk(timeout=1,
                                                   max_samples=int(
                                                       shift_length * fs))

            # Only keep the channel we're interested in
            ch_data = np.array(eeg_data)[:, index_channel]

            # Update EEG buffer
            eeg_buffer, filter_state = BCIw.update_buffer(
                eeg_buffer, ch_data, notch=True, filter_state=filter_state)
            """ 3.2 COMPUTE FEATURES """
            # Get newest samples from the buffer
            data_epoch = BCIw.get_last_data(eeg_buffer, epoch_length * fs)

            # Compute features
            feat_vector = BCIw.compute_feature_vector(data_epoch, fs)
            feat_buffer, _ = BCIw.update_buffer(feat_buffer,
                                                np.asarray([feat_vector]))
            """ 3.3 VISUALIZE THE RAW EEG AND THE FEATURES """
            plotter_eeg.update_plot(eeg_buffer)
            plotter_feat.update_plot(feat_buffer)
            plt.pause(0.00001)

    except KeyboardInterrupt:
        print('Closing!')
예제 #6
0
            # Only keep the channel we're interested in
            ch_data = np.array(eeg_data)[:, index_channel]

            # Update EEG buffer
            eeg_buffer, filter_state = BCIw.update_buffer(
                    eeg_buffer, ch_data, notch=True,
                    filter_state=filter_state)

            """ 3.2 COMPUTE FEATURES AND CLASSIFY """
            # Get newest samples from the buffer
            data_epoch = BCIw.get_last_data(eeg_buffer,
                                            epoch_length * fs)

            # Compute features
            feat_vector = BCIw.compute_feature_vector(data_epoch, fs)
            y_hat = BCIw.test_classifier(classifier,
                                         feat_vector.reshape(1, -1), mu_ft,
                                         std_ft)
            print(y_hat)

            decision_buffer, _ = BCIw.update_buffer(decision_buffer,
                                                    np.reshape(y_hat, (-1, 1)))

            """ 3.3 VISUALIZE THE DECISIONS """
            plotter_decision.update_plot(decision_buffer)
            plt.pause(0.00001)

    except KeyboardInterrupt:

        print('Closed!')
 BCIw.beep() # Beep sound 
 
 # The try/except structure allows to quit the while loop by aborting the 
 # script with <Ctrl-C>
 print(' Press Ctrl-C in the console to break the While Loop')
 try:    
      
     # The following loop does what we see in the diagram of Exercise 1:
     # acquire data, compute features, visualize the raw EEG and the features        
     while True:  
         
         """ 1- ACQUIRE DATA """
         eeg_data = mules_client.getdata(shift_secs, False) # Obtain EEG data from MuLES  
         eeg_buffer = BCIw.updatebuffer(eeg_buffer, eeg_data) # Update EEG buffer
         
         """ 2- COMPUTE FEATURES """
         # Get newest samples from the buffer 
         data_window = BCIw.getlastdata(eeg_buffer, win_test_secs * params['sampling frequency'])
         # Compute features on "data_window" 
         feat_vector = BCIw.compute_feature_vector(data_window, params['sampling frequency'])
         feat_buffer = BCIw.updatebuffer(feat_buffer, np.asarray([feat_vector])) # Update the feature buffer
         
         """ 3- VISUALIZE THE RAW EEG AND THE FEATURES """       
         plotter_eeg.updatePlot(eeg_buffer) # Plot EEG buffer     
         plotter_feat.updatePlot((feat_buffer)) # Plot the feature buffer 
         
         plt.pause(0.001)        
     
 except KeyboardInterrupt:
        
     mules_client.disconnect() # Close connection