Exemplo n.º 1
0
        private static void TestWaveform(Waveform waveform)
        {
            waveform.BackgroundColor = (int)Color.Blue;
            Debug.Print(waveform.BackgroundColor.ToString());
            waveform.Refresh();
            waveform.BackgroundColor = (int)Color.Black;
            waveform.Refresh();

            waveform.GridColor = (int)Color.Red;
            Debug.Print("Grid: " + waveform.GridIntervalHorizontal + " - " + waveform.GridIntervalVertical);

            /*
             * waveform.Refresh();
             * waveform.GridIntervalHorizontal = 0;
             * waveform.GridIntervalVertical = 0;
             * waveform.Refresh();
             *
             * waveform.GridIntervalHorizontal = 30;
             * waveform.GridIntervalVertical = 60;
             * waveform.Refresh();
             */

            waveform.ForegroundColor0 = (int)Color.White;
            waveform.ForegroundColor1 = (int)Color.Blue;
            waveform.ForegroundColor2 = (int)Color.Green;
            waveform.ForegroundColor3 = (int)Color.Yellow;
            waveform.Refresh();

            Debug.Print("-----------------------------");
            Debug.Print("Waveform value add test start");

            int sleep = 100;

            for (double angle = 0; angle < 120; angle += 0.1)
            {
                byte value0 = (byte)(angle);

                byte value1 = ConvertToByte(System.Math.Sin(angle));
                byte value2 = ConvertToByte(System.Math.Cos(angle));

                waveform.Add(0, value0);
                waveform.Add(1, value1);
                waveform.Add(2, value2);

                Thread.Sleep(sleep);
            }

            Debug.Print("Waveform value add test end");
            Debug.Print("-----------------------------");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Hängt zwei Waveforms aneinander an.
 /// </summary>
 /// <param name="a">Die erste Waveform.</param>
 /// <param name="b">Die zweite Waveform.</param>
 /// <returns>Die verbundene Waveform (a+b).</returns>
 public static Waveform Concatenate(Waveform a, Waveform b)
 {
     for (int i = b.First; i <= b.Last; i++)
     {
         a.Add(b[i]);
     }
     return a;
 }
Exemplo n.º 3
0
        public Waveform GetEEGWaveform(Electrode electrode)
        {
            Waveform Waveform = new Waveform(0, sampleRate);
            foreach (EEGSample sample in goodSamples)
            {
                Waveform.Add(sample.eegValues[electrode]);
            }

            return Waveform;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Bildet den Durschnitt aus einer Liste aus Waveforms. Die Waveforms müssen gleich lang sein.
        /// </summary>
        /// <param name="waveforms">Die Liste aus Waveforms.</param>
        /// <returns>Die Durchschnitts-Waveform.</returns>
        public static Waveform AverageWaveform(List<Waveform> waveforms)
        {
            int noOfWaveforms = waveforms.Count;

            if (noOfWaveforms < 1) return null;
            else if (noOfWaveforms < 2) return waveforms[0];

            double average;
            Waveform averageWaveform = new Waveform(0, waveforms[0].Rate);
            for (int i = waveforms[0].First; i <= waveforms[0].Last; i++)
            {
                average = 0;
                foreach (Waveform waveform in waveforms)
                {
                    average = average + waveform[i];
                }
                average = average / noOfWaveforms;
                averageWaveform.Add(average);
            }

            return averageWaveform;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Normalisiert mehrere Waveforms in den Bereich zwischen 0 und 1. Die Referenzen (Minimum und Maximum) werden dabei über alle Waveforms hinweg gesucht.
        /// </summary>
        /// <param name="waveforms">Die zu normalisierenden Waveforms. Die Liste wird durch die normalisierten Waveforms ersetzt.</param>
        public static void NormalizeMultiple(ref List<Waveform> waveforms)
        {
            if (waveforms.Count < 1) return;

            double min = waveforms[0][waveforms[0].First];
            double max = waveforms[0][waveforms[0].First];

            // kleinsten und größten Wert suchen
            foreach (Waveform wf in waveforms)
            {
                for (int i = wf.First; i <= wf.Last; i++)
                {
                    if (wf[i] < min) min = wf[i];
                    if (wf[i] > max) max = wf[i];
                }
            }

            // alle Waveforms normalisieren
            if (max - min > 0)
            {
                for (int j = 0; j < waveforms.Count; j++)
                {
                    Waveform wf = waveforms[j];
                    Waveform normalizedWaveform = new Waveform(0, wf.Rate);
                    for (int i = wf.First; i <= wf.Last; i++)
                    {
                        // Wert normalisieren
                        normalizedWaveform.Add((wf[i] - min) / (max - min));
                    }
                    waveforms[j] = normalizedWaveform;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Generiert eine Waveform, die die sekündliche Aktivität eines EEG-Frequenzbandes wiederspiegelt und speichert sie zwischen. Die Samplerate ist 1 Hz.
        /// </summary>
        private void CalculateActivity()
        {
            this.Activity = new Dictionary<EEGBand, Waveform>();
            foreach (EEGBand eegBand in (EEGBand[])Enum.GetValues(typeof(EEGBand)))
            {
                double minFreq = eegBand.GetMinFreq();
                double maxFreq = eegBand.GetMaxFreq();

                // wir nehmen das Spektrum über 128 Samples
                int fftSize = 128;

                // die Samplerate der Activity-Waveform soll 1 Hz sein.
                int activitySampleRate = 1;

                // wir benötigen eine leere Waveform
                Waveform activityWaveform = new Waveform(0, activitySampleRate);

                // Ermittle das Frequenzspektrum in regelmäßigen Abständen  und berechne die Aktivität im Frequenzband
                for (int i = Waveform.First; i <= Waveform.Last - fftSize; i = i + ((int)sampleRate / activitySampleRate))
                {
                    Waveform amplitudeSpectrum = GetAmplitudeSpectrum(i, fftSize);

                    // finde die Indizes im diskreten Spektrum, die Ober- und Unterkante des Frequenzbands darstellen
                    int minFreqIndex = FindSpectrumIndexForFreq(minFreq, amplitudeSpectrum, (int)sampleRate);
                    int maxFreqIndex = FindSpectrumIndexForFreq(maxFreq, amplitudeSpectrum, (int)sampleRate);

                    double activityValue = 0;
                    for (int j = minFreqIndex; j <= maxFreqIndex; j++)
                    {
                        activityValue = activityValue + amplitudeSpectrum[j];
                    }
                    activityWaveform.Add(activityValue / (maxFreqIndex - minFreqIndex + 1));
                }

                // Die Waveform ist etwas zu kurz (fftSize) und die Werte beziehen sich jeweils auf zwei Sekunden später
                // Kompensieren, indem die Welle nach hinten verschoben wird und die ersten Werte denselben Wert annehmen
                Waveform compensationWaveform = new Waveform(0, activitySampleRate);
                for (int i = 0; i <= fftSize; i = i + ((int)sampleRate / activitySampleRate))
                {
                    compensationWaveform.Add(activityWaveform[activityWaveform.First]);
                }
                this.Activity.Add(eegBand, EEGUtils.Concatenate(compensationWaveform, activityWaveform));
            }
        }