self.id = packet_id
        self.channel_data = channel_data
        self.aux_data = aux_data


###############################################################################
# Get the data to be simulated from file
'''
    If it were real-time the data would come directly from eeg.
    For the simulation purpose it has to be read from the file.
'''
# Specify file with eeg data.
eeg_file = '../example_data/blink_00.csv'

# Read requested data.
data = read_csv(eeg_file)


###############################################################################
# Main function of the program       #

###############################################################################
# [Child process] Objects creation and main loop

# Define a function to run as the background process (foreground will be the
# graphical interface.
def func_ssvep_det(ssvep_state):
    def handle_sample(sample):

        # get data point (value) form the first channel (index '0')
        smp = sample.channel_data[channel]
        self.id = packet_id
        self.channel_data = channel_data
        self.aux_data = aux_data


###############################################################################
# Get the data to be simulated from file
'''
    If it were real-time the data would come directly from eeg.
    For the simulation purpose it has to be read from the file.
'''
# Specify file with eeg data.
eeg_file = '../example_data/blink_00.csv'

# Read requested data.
data = read_csv(eeg_file)

###############################################################################
# Main function of the program       #

###############################################################################
# [Child process] Objects creation and main loop


# Define a function to run as the background process (foreground will be the
# graphical interface.
def func_ssvep_det(ssvep_state):
    def handle_sample(sample):

        # get data point (value) form the first channel (index '0')
        smp = sample.channel_data[channel]
Esempio n. 3
0
def plot_time(eeg_file,
              fs,
              channel,
              bandstop=(49, 51),
              bandpass=(1, 50),
              order=4,
              sec_remove=None,
              show=True,
              xticklabels='samples',
              title='Signal time domain after filtration',
              sec_range=None,
              ylim=None,
              threshold=None,
              linewidth=1.0):
    '''
    This function has dual purpose: plotting eeg signal or visualising
    threshold detection line.

    sec_remove - remove first n seconde (e.g. for filter settling time)
    '''

    # in case someone passes float value (it has to be int for indexing)
    fs = int(fs)

    data = read_csv(eeg_file, channel=channel)

    if bandstop or bandpass:
        # filter data using bandstop (first), and then bandpass filter
        filtered_data = filter_eeg(data,
                                   fs,
                                   bandstop=bandstop,
                                   bandpass=bandpass,
                                   order=order)

        if sec_remove:
            filtered_data = filtered_data[int(fs * sec_remove):]
        elif sec_range:
            filtered_data = \
                filtered_data[int(fs*sec_range[0]):int(fs*sec_range[1])]

        data_plotted = filtered_data

    else:
        data_plotted = data

    if xticklabels == 'seconds':
        xlabel = 'Time [s]'
        if sec_range:
            x_axis = np.arange(0,
                               len(data_plotted) / float(fs),
                               1 / float(fs)) + sec_range[0]
        else:
            x_axis = np.arange(0, len(data_plotted) / float(fs), 1 / float(fs))
    else:
        xlabel = 'Sample number'
        x_axis = np.arange(0, len(data_plotted))

    fig, ax = plt.subplots()

    plt.plot(x_axis, data_plotted, linewidth=1.5, label='signal')

    ax.set_xlabel(xlabel, labelpad=15)
    ax.set_ylabel(r'microvolts [$\mu$V]', labelpad=20)

    if threshold:
        ax.text(x_axis[0] - 0.12,
                45,
                r'50',
                style='oblique',
                fontsize=30,
                color='red')
        # draw threshold line
        plt.plot((x_axis[0], x_axis[-1]), (threshold, threshold),
                 'r-',
                 linewidth=linewidth,
                 label='threshold')
        # change default title
        plt.title('Threshold Blink Detection', y=1.02)

    leg = plt.legend(bbox_to_anchor=(0.985, 0.14))
    llines = leg.get_lines()
    plt.setp(llines, linewidth=5)

    # set y axis boundries
    if ylim:
        plt.ylim(ylim)

    plt.rcParams.update({'font.size': 32})

    # show result
    if show:
        plt.show()
Esempio n. 4
0

############################################
#                                          #
#          GET DATA FROM FILE              #
#                                          #
############################################

# location of the file with eeg data
eeg_file = '/home/jesmasta/eeg_data/OpenBCI/ssvep_00.csv'

# get data form channel X
channel = 0

# read requested data form csv file
data = read_csv(eeg_file, channel)


############################################
#                                          #
#              FILTER DATA                 #
#                                          #
############################################

# filter data using first, bandstop filter, then bandpass filter
filtered_data = filter_eeg(data, fs, bandstop=(49, 51), bandpass=(1, 50))

# get signal for 2nd second - how many you have to cut depends on the order
# of the digital filter you apply to the signal
filtered_data = filtered_data[int(fs):]
Esempio n. 5
0
def plot_time(
        eeg_file, fs, channel,
        bandstop=(49, 51), bandpass=(1, 50), order=4,
        sec_remove=None, show=True, xticklabels='samples',
        title='Signal time domain after filtration',
        sec_range=None, ylim=None, threshold=None, linewidth=1.0
        ):
    '''
    This function has dual purpose: plotting eeg signal or visualising
    threshold detection line.

    sec_remove - remove first n seconde (e.g. for filter settling time)
    '''

    # in case someone passes float value (it has to be int for indexing)
    fs = int(fs)

    data = read_csv(eeg_file, channel=channel)

    if bandstop or bandpass:
        # filter data using bandstop (first), and then bandpass filter
        filtered_data = filter_eeg(
            data, fs, bandstop=bandstop, bandpass=bandpass,
            order=order
            )

        if sec_remove:
            filtered_data = filtered_data[int(fs*sec_remove):]
        elif sec_range:
            filtered_data = \
                filtered_data[int(fs*sec_range[0]):int(fs*sec_range[1])]

        data_plotted = filtered_data

    else:
        data_plotted = data

    if xticklabels == 'seconds':
        xlabel = 'Time [s]'
        if sec_range:
            x_axis = np.arange(
                0, len(data_plotted)/float(fs), 1/float(fs)
                ) + sec_range[0]
        else:
            x_axis = np.arange(0, len(data_plotted)/float(fs), 1/float(fs))
    else:
        xlabel = 'Sample number'
        x_axis = np.arange(0, len(data_plotted))

    fig, ax = plt.subplots()

    plt.plot(x_axis, data_plotted, linewidth=1.5, label='signal')


    ax.set_xlabel(xlabel, labelpad=15)
    ax.set_ylabel(r'microvolts [$\mu$V]', labelpad=20)


    if threshold:
        ax.text(
            x_axis[0]-0.12, 45, r'50',
            style='oblique', fontsize=30, color='red'
            )
        # draw threshold line
        plt.plot(
            (x_axis[0], x_axis[-1]),
            (threshold, threshold),
            'r-', linewidth=linewidth, label='threshold'
            )
        # change default title
        plt.title('Threshold Blink Detection', y=1.02)

    leg = plt.legend(bbox_to_anchor=(0.985, 0.14))
    llines = leg.get_lines()
    plt.setp(llines, linewidth=5)

    # set y axis boundries
    if ylim:
        plt.ylim(ylim)


    plt.rcParams.update({'font.size': 32})

    # show result
    if show:
        plt.show()