示例#1
0
        private EEGSample GetSample(int i)
        {
            if (i >= csvData.Count) return null;
            List<String> row = csvData[i];
            EEGSample sample = new EEGSample();
            sample.index = i;
            sample.timestamp = Convert.ToInt64(row[timestampPosition]);

            Electrode electrode;
            int columnNo;
            foreach (KeyValuePair<Electrode, int> column in columnNumbers)
            {
                electrode = column.Key;
                columnNo = column.Value;
                sample.eegValues.Add(electrode, Convert.ToDouble(row[columnNo], System.Globalization.CultureInfo.InvariantCulture));
            }

            sample.eyeX = Convert.ToDouble(row[eyeXColumnNo], System.Globalization.CultureInfo.InvariantCulture);
            sample.eyeY = Convert.ToDouble(row[eyeYColumnNo], System.Globalization.CultureInfo.InvariantCulture);

            return sample;
        }
示例#2
0
        private EEGSample FindNextGoodSample(EEGSample startSample)
        {
            int i = startSample.index;

            long timestampWanted = (long)(startSample.timestamp + (1000000 / sampleRate));
            long bestDifferenceToWantedTimestamp = startSample.timestamp;
            EEGSample bestSample = null;

            // Überspringe aufeinanderfolgende Timestamps mit demselben Wert. Manchmal häufen die sich.
            EEGSample nextSample = GetSample(i + 1);
            while (nextSample != null && nextSample.timestamp == startSample.timestamp)
            {
                i++;
                nextSample = GetSample(i + 1);
            }

            // Suche den nächsten Timestamp, der (entsprechend der angegebenen Sample-Rate) dem erwarteten Wert am nächsten kommt
            for (int j = i + 1; j < (i + 5); j++)
            {
                nextSample = GetSample(j);
                if (nextSample == null) return null;
                long differenceToWantedTimestamp = Math.Abs(timestampWanted - nextSample.timestamp);

                if (differenceToWantedTimestamp < bestDifferenceToWantedTimestamp)
                {
                    bestDifferenceToWantedTimestamp = differenceToWantedTimestamp;
                    bestSample = nextSample;
                }
            }

            return bestSample;
        }