示例#1
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:    
     
     # 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:
示例#2
0
    
    
    #%% Start pulling data and classifying in real-time
    
    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)
示例#3
0
    #BCIw.plot_classifier_training(feat_matrix0, feat_matrix1) # This will plot the decision boundary of a 2-feature SVM

    #%% Start pulling data and classifying in real-time

    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)  # 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))
 
 mules_client.flushdata()  # Flush old data from MuLES
 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: