def __init__(self, verbose=False):
     self.samplingRate = ConfigProvider().getEmotivConfig().get(
         "samplingRate")
     self.qualUtil = QualityUtil()
     self.fftUtil = FFTUtil()
     self.eegUtil = EEGUtil()
     self.verbose = verbose
Exemple #2
0
    def plotEEGSignal(self):
        # Filter a noisy signal.

        data = self.getEEGSignal()
        fs = data.getSamplingRate()
        x = data.getColumn("F3")
        x = SignalUtil().normalize(x)

        duration = self.getDuration(data)
        t = np.linspace(0, duration, len(x), endpoint=False)

        plt.figure(2)
        plt.clf()
        plt.plot(t, x, label='normalized signal')

        for label, (lowcut, highcut) in EEGUtil().channel_ranges.iteritems():
            if label == "alpha":
                y = self.su.butterBandpassFilter(x,
                                                 lowcut,
                                                 highcut,
                                                 fs,
                                                 order=6)
                plt.plot(t,
                         y,
                         label='%s (%d - %dHz)' % (label, lowcut, highcut))

        plt.xlabel('time (seconds)')
        plt.grid(True)
        plt.axis('tight')
        plt.legend(loc='upper left')
Exemple #3
0
class DeltaSignalPlotter(RawSignalPlotter):
    def __init__(self,
                 person,
                 eegData,
                 signals,
                 filePath,
                 save=True,
                 plot=True,
                 logScale=False):
        RawSignalPlotter.__init__(self,
                                  person,
                                  eegData,
                                  signals,
                                  filePath,
                                  save,
                                  plot,
                                  logScale,
                                  name="delta")
        self.chain = SignalProcessor()
        self.eegUtil = EEGUtil()

    def _getData(self, signal):
        raw = self.eegData.getColumn(signal)
        qual = self.eegData.getQuality(signal)
        samplingRate = self.eegData.getSamplingRate()

        proc, _ = self.chain.process(raw, qual)
        proc = QualityUtil().replaceNans(proc)
        return self.eegUtil.getDeltaWaves(proc, samplingRate)
Exemple #4
0
 def __init__(self,
              person,
              eegData,
              signals,
              filePath,
              save=True,
              plot=True,
              logScale=False):
     RawSignalPlotter.__init__(self,
                               person,
                               eegData,
                               signals,
                               filePath,
                               save,
                               plot,
                               logScale,
                               name="delta")
     self.chain = SignalProcessor()
     self.eegUtil = EEGUtil()
class FFTProcessor(object):
    def __init__(self, verbose=False):
        self.samplingRate = ConfigProvider().getEmotivConfig().get(
            "samplingRate")
        self.qualUtil = QualityUtil()
        self.fftUtil = FFTUtil()
        self.eegUtil = EEGUtil()
        self.verbose = verbose

    def process(self, proc):
        fft = self.fftUtil.fft(proc)
        chan = self.eegUtil.getChannels(fft)
        return chan, False
    def __init__(self, queue, filePath, signals=None, save=True, plot=True, logScale=False, name=""):
        self.queue = queue
        self.filePath = filePath
        self._initStatsDict()
        self.config = ConfigProvider()
        self.eegData = FileUtil().getDto(filePath)
        self._initSignals(signals)
        self.su = SignalUtil()
        self.qu = QualityUtil()
        self.eu = EEGUtil()
        self.fft = FFTUtil()
        self._initFields()
        self.save = save
        self.plot = plot
        self.name = name
        self._initPlotter(logScale)
        self.ssPrint = SignalStatisticPrinter(filePath)
        self.preProcessor = SignalPreProcessor()
        self.processor = SignalProcessor()

        windowSeconds = self.config.getCollectorConfig().get("windowSeconds")
        self.windowSize = EEGDataCollector.calcWindowSize(windowSeconds, self.eegData.samplingRate)
Exemple #7
0
 def setUp(self):
     self.util = EEGUtil()
Exemple #8
0
class TestEEGUtil(BaseTest):
    def setUp(self):
        self.util = EEGUtil()

    def test__getSliceParams(self):
        for _, freqRange in self.util.channel_ranges.iteritems():
            self.assertEqual(type(self.util._getSliceParam(freqRange)[0]), int)

    def test_getChannels_short(self):
        data = [1, 2, 3, 4, 5, 6, 7, 8]

        channels = self.util.getChannels(data)
        self.assertTrue(len(channels) == 5)
        self.assertTrue(len(channels["delta"]) > 0)
        self.assertTrue(len(channels["theta"]) > 0)

        self.assertTrue(len(channels["alpha"]) == 0)

    def test_getChannels(self):
        fft = self.TEST_DATA_12000Hz

        channels = self.util.getChannels(fft)
        flattenChannels = np.hstack(channels.values())
        self.assertTrue(all([x in fft for x in flattenChannels]))

        self.assertTrue(len(flattenChannels) <= len(fft))

    def test_getSingleChannels(self):
        fft = self.TEST_DATA_12000Hz
        channels = self.util.getChannels(fft)

        delta = self.util.getDeltaChannel(fft)
        # TODO delta range from 0.5 to 4Hz, actual range from 1 - 4Hz
        self.assertEqual(len(delta), 3)
        self.assertTrue(all([x in channels["delta"] for x in delta]))

        theta = self.util.getThetaChannel(fft)
        self.assertEqual(len(theta), 4)
        self.assertTrue(all([x in channels["theta"] for x in theta]))

        alpha = self.util.getAlphaChannel(fft)
        self.assertEqual(len(alpha), 5)
        self.assertTrue(all([x in channels["alpha"] for x in alpha]))

        beta = self.util.getBetaChannel(fft)
        self.assertEqual(len(beta), 17)
        self.assertTrue(all([x in channels["beta"] for x in beta]))

        gamma = self.util.getGammaChannel(fft)
        self.assertEqual(len(gamma),
                         len(range(*self.util.channel_ranges["gamma"])))
        self.assertTrue(all([x in channels["gamma"] for x in gamma]))

    def test_getWaves(self):
        eegData = FileUtil().getDto(self.getData32CSV())
        eeg = eegData.getColumn("F3")
        nEeg = len(eeg)
        waves = self.util.getWaves(eeg, eegData.getSamplingRate())

        self.assertEqual(len(waves), 5)
        for _, wave in waves.iteritems():
            self.assertEqual(len(wave), nEeg)

    def test_getSingleWaves(self):
        eegData = FileUtil().getDto(self.getData32CSV())
        eeg = eegData.getColumn("F3")
        nEeg = len(eeg)
        samplingRate = eegData.getSamplingRate()
        waves = self.util.getWaves(eeg, samplingRate)

        delta = self.util.getDeltaWaves(eeg, samplingRate)
        self.assertEqual(len(delta), nEeg)
        self.assertTrue(all([x in waves["delta"] for x in delta]))

        theta = self.util.getThetaWaves(eeg, samplingRate)
        self.assertEqual(len(theta), nEeg)
        self.assertTrue(all([x in waves["theta"] for x in theta]))

        alpha = self.util.getAlphaWaves(eeg, samplingRate)
        self.assertEqual(len(alpha), nEeg)
        self.assertTrue(all([x in waves["alpha"] for x in alpha]))

        beta = self.util.getBetaWaves(eeg, samplingRate)
        self.assertEqual(len(beta), nEeg)
        self.assertTrue(all([x in waves["alpha"] for x in alpha]))

        gamma = self.util.getGammaWaves(eeg, samplingRate)
        self.assertEqual(len(gamma), nEeg)
        self.assertTrue(all([x in waves["gamma"] for x in gamma]))