示例#1
0
def process_eeg(data):
    print "Lost packets: ", utils.check_packet_drops(data[:, CTR])

    ch = signal.detrend(data[:, O2].T)
    time_step = 1/128.0
    sample_freq = fftpack.fftfreq(ch.size, d=time_step)
    pidxs = np.where(sample_freq > 0)
    freqs = sample_freq[pidxs]

    fft = fftpack.fft(ch)
    power = np.abs(fft)[pidxs]
    max_power_ind = power.argmax()
    max_args = power.argsort()[::-1][:5]
    print freqs[max_args], power[max_args]
def process_eeg(data):
    print "Lost packets: ", utils.check_packet_drops(data[:, CTR])

    ch = signal.detrend(data[:, O2].T)
    time_step = 1 / 128.0
    sample_freq = fftpack.fftfreq(ch.size, d=time_step)
    pidxs = np.where(sample_freq > 0)
    freqs = sample_freq[pidxs]

    fft = fftpack.fft(ch)
    power = np.abs(fft)[pidxs]
    max_power_ind = power.argmax()
    max_args = power.argsort()[::-1][:5]
    print freqs[max_args], power[max_args]
示例#3
0
    try:
        folder = sys.argv[1]
        resting_sig = loadmat(os.path.join(folder, "eeg-resting"))
        ssvep_sig = loadmat(os.path.join(folder, "eeg-ssvep"))
    except IndexError, ie:
        print "Usage: %s <data-folder> [channel]" % sys.argv[0]

    else:
        time_step = 1/128.0
        sample_count = ssvep_sig['SEQ'].size
        sample_freq = fftpack.fftfreq(sample_count, d=time_step)
        pidxs = np.where(sample_freq > 0)
        freqs = sample_freq[pidxs]

        resting_drops = utils.check_packet_drops(resting_sig['SEQ'][0,:])
        ssvep_drops = utils.check_packet_drops(ssvep_sig['SEQ'][0,:])
        if ssvep_drops:
            print "SSVEP drops: %s" % ssvep_drops
        if resting_drops:
            print "Resting drops: %s" % resting_drops

        if ch:
            fig, axarr = plt.subplots(5, len(ch), sharex=False)
            axarr = np.array(axarr).reshape((-1, len(ch)))
            channels = ch
        else:
            # 3 for matlab meta data arrays, and 1 for SEQ
            fig, axarr = plt.subplots(5, len(ssvep_sig) - 4, sharex=False)
            channels = [c for c in ssvep_sig.keys() if not c.startswith(("__", "SEQ"))]
示例#4
0
    data = np.empty((duration * 128, n_channels), dtype=np.uint16)

    try:
        for i in range(duration):
            # Blocks
            raw_bytes = client.recv(RECVSIZE)

            # We should receive 1 second of EEG data 128x15 matrix
            d = np.fromstring(raw_bytes, dtype=np.uint16).reshape((128, n_channels))

            # This is for accumulating
            data[i * 128:(i+1) * 128, :] = d

            # Process data
            #process_eeg(data[:(i+1)*128, :])
            process_eeg(d)

    except Exception, e:
        print e
        pass
    finally:
        # Pass the result back to acquisition daemon
        # TODO: client.send(...)
        server.close()
        os.unlink(SOCKET)
        utils.save_as_matlab(data, channel_mask, metadata=metadata)
        print "Total packet lost: %d/%d" % (len(utils.check_packet_drops(data[:, CTR])), data[:, CTR].size)

if __name__ == "__main__":
    sys.exit(main())
        for i in range(duration):
            # Blocks
            raw_bytes = client.recv(RECVSIZE)

            # We should receive 1 second of EEG data 128x15 matrix
            d = np.fromstring(raw_bytes, dtype=np.uint16).reshape(
                (128, n_channels))

            # This is for accumulating
            data[i * 128:(i + 1) * 128, :] = d

            # Process data
            #process_eeg(data[:(i+1)*128, :])
            process_eeg(d)

    except Exception, e:
        print e
        pass
    finally:
        # Pass the result back to acquisition daemon
        # TODO: client.send(...)
        server.close()
        os.unlink(SOCKET)
        utils.save_as_matlab(data, channel_mask, metadata=metadata)
        print "Total packet lost: %d/%d" % (len(
            utils.check_packet_drops(data[:, CTR])), data[:, CTR].size)


if __name__ == "__main__":
    sys.exit(main())
    try:
        folder = sys.argv[1]
        resting_sig = loadmat(os.path.join(folder, "eeg-resting"))
        ssvep_sig = loadmat(os.path.join(folder, "eeg-ssvep"))
    except IndexError, ie:
        print "Usage: %s <data-folder> [channel]" % sys.argv[0]

    else:
        time_step = 1/128.0
        sample_count = ssvep_sig['SEQ'].size
        sample_freq = fftpack.fftfreq(sample_count, d=time_step)
        pidxs = np.where(sample_freq > 0)
        freqs = sample_freq[pidxs]

        resting_drops = utils.check_packet_drops(resting_sig['SEQ'][0,:])
        ssvep_drops = utils.check_packet_drops(ssvep_sig['SEQ'][0,:])
        if ssvep_drops:
            print "SSVEP drops: %s" % ssvep_drops
        if resting_drops:
            print "Resting drops: %s" % resting_drops

        if ch:
            fig, axarr = plt.subplots(5, len(ch), sharex=False)
            axarr = np.array(axarr).reshape((-1, len(ch)))
            channels = ch
        else:
            # 3 for matlab meta data arrays, and 1 for SEQ
            fig, axarr = plt.subplots(5, len(ssvep_sig) - 4, sharex=False)
            channels = [c for c in ssvep_sig.keys() if not c.startswith(("__", "SEQ"))]