Beispiel #1
0
        //private double[] discreteFourierTransform(double[] data)
        //{
        //    int n = data.Length;
        //    int m = n;// I use m = n / 2d;
        //    var real = new double[n];
        //    var imag = new double[n];
        //    var result = new double[m];
        //    double pi_div = 2.0 * Math.PI / n;
        //    Parallel.For(0, m, w =>
        //    {
        //        double a = w * pi_div;
        //        Parallel.For(0, n, t =>
        //        {
        //            real[w] += data[t] * Math.Cos(a * t);
        //            imag[w] += data[t] * Math.Sin(a * t);
        //        });
        //        result[w] = Math.Sqrt(real[w]);
        //    });
        //    Parallel.For(0, m, w =>
        //    {
        //        double a = w * pi_div;
        //        Parallel.For(0, n, t =>
        //        {
        //            real[w] += data[t] * Math.Cos(a * t);
        //            imag[w] += data[t] * Math.Sin(a * t);
        //        });
        //        result[w] = Math.Sqrt(real[w] * real[w] + imag[w] * imag[w]) / n;
        //    });
        //    return result;
        //}

        private void bgRekam_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.UserState.ToString() == "MuseCSharpLSL.Stimulus, Text: Stimulus")
            {
                Stimulus stimulus = (Stimulus)e.UserState;
                if (e.ProgressPercentage == 1)
                {
                    stimulus.perbaharuiStimulus("+");
                }
                if (e.ProgressPercentage == 2)
                {
                    stimulus.perbaharuiStimulus(arah);
                }
                if (e.ProgressPercentage == 3)
                {
                    stimulus.perbaharuiStimulus("");
                }
                stimulus.Show();
            }
            else
            {
                StimulusHuruf stimulusHuruf = (StimulusHuruf)e.UserState;
                if (e.ProgressPercentage == 1)
                {
                    stimulusHuruf.perbaharuiStimulus("+");
                }
                if (e.ProgressPercentage == 2)
                {
                    stimulusHuruf.perbaharuiStimulus(arah);
                }
                if (e.ProgressPercentage == 3)
                {
                    stimulusHuruf.perbaharuiStimulus("");
                }
                stimulusHuruf.Show();
            }
        }
Beispiel #2
0
        private void rekam()
        {
            if (cbOtomatis.Checked != true)
            {
                if (cbRekamHuruf.Checked)
                {
                    stimulusHuruf = new StimulusHuruf();
                }
                else
                {
                    stimulus = new Stimulus();
                }
            }
            groupLatih.Invoke((MethodInvoker) delegate { groupLatih.Enabled = false; });
            var checkedButton = tlArah.Controls.OfType <RadioButton>()
                                .FirstOrDefault(r => r.Checked);

            arah = checkedButton.Text;
            var epoching = new List <float[]>();
            var watch    = new Stopwatch();

            if (cbRekamHuruf.Checked)
            {
                bgRekam.ReportProgress(1, stimulusHuruf);
            }
            else
            {
                bgRekam.ReportProgress(1, stimulus);
            }
            watch.Start();
            updateAktivitas("REST");
            do
            {
            } while (watch.Elapsed.Seconds != 2);
            watch.Restart();
            if (cbRekamHuruf.Checked)
            {
                bgRekam.ReportProgress(2, stimulusHuruf);
            }
            else
            {
                bgRekam.ReportProgress(2, stimulus);
            }
            // read samples
            float[,] buffer = new float[_chunks, _kanal];
            double[] timestamps = new double[_chunks];
            updateAktivitas("Rekam " + arah);
            inlet = new liblsl.StreamInlet(results[0]);
            do
            {
                int num = inlet.pull_chunk(buffer, timestamps);
                for (int s = 0; s < num; s++)
                {
                    var d = new float[_kanal];
                    for (int i = 0; i < _kanal; i++)
                    {
                        d[i] = buffer[s, i];
                    }
                    epoching.Add(d);
                    if (epoching.Count == _epocSizeTesting)
                    {
                        break;
                    }
                }
            } while (epoching.Count < _epocSizeTesting);
            updateAktivitas(arah + " pengambilan +- " + watch.ElapsedMilliseconds + " ms");
            watch.Restart();
            if (cbRekamHuruf.Checked)
            {
                bgRekam.ReportProgress(3, stimulusHuruf);
            }
            else
            {
                bgRekam.ReportProgress(3, stimulus);
            }
            updateAktivitas("REST");
            do
            {
            } while (watch.Elapsed.Seconds != 2);
            watch.Stop();
            if (cbOtomatis.Checked != true)
            {
                if (cbRekamHuruf.Checked)
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        stimulusHuruf.Close();
                    });
                }
                else
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        stimulus.Close();
                    });
                }
            }
            var    pecah      = pecahSinyal(epoching);
            var    preprocess = preprocessSignal(pecah);
            var    dft        = featureExtraction(preprocess);
            var    feature    = dftToOneRowFeature(dft);
            string dateTime   = DateTime.Now.ToString("HH_mm_ss");

            if (cbRekamHuruf.Checked)
            {
                saveFile(pecah, "RAW_HURUF", arah, dateTime);
                saveFile(preprocess, "BPF_HURUF", arah, dateTime);
                saveFile(dft, "DFT_HURUF", arah, dateTime);
                saveFeature(feature, arah, "HURUF");
            }
            else
            {
                saveFile(pecah, "RAW_GAMBAR", arah, dateTime);
                saveFile(preprocess, "BPF_GAMBAR", arah, dateTime);
                saveFile(dft, "DFT_GAMBAR", arah, dateTime);
                saveFeature(feature, arah, "GAMBAR");
            }
            groupLatih.Invoke((MethodInvoker) delegate { groupLatih.Enabled = true; });
        }
Beispiel #3
0
 private void bgRekam_DoWork(object sender, DoWorkEventArgs e)
 {
     if (cbRekamHuruf.Checked)
     {
         if (cbOtomatis.Checked == true)
         {
             stimulusHuruf = new StimulusHuruf();
             for (int i = 0; i < (int)numPerulangan.Value; i++)
             {
                 rbMaju.Invoke((MethodInvoker) delegate { rbMaju.Checked = true; });
                 rekam();
                 rbMundur.Invoke((MethodInvoker) delegate { rbMundur.Checked = true; });
                 rekam();
                 rbBerhenti.Invoke((MethodInvoker) delegate { rbBerhenti.Checked = true; });
                 rekam();
                 rbKiri.Invoke((MethodInvoker) delegate { rbKiri.Checked = true; });
                 rekam();
                 rbKanan.Invoke((MethodInvoker) delegate { rbKanan.Checked = true; });
                 rekam();
             }
             this.Invoke((MethodInvoker) delegate
             {
                 stimulusHuruf.Close();
             });
         }
         else
         {
             rekam();
         }
     }
     else
     {
         if (cbOtomatis.Checked == true)
         {
             stimulus = new Stimulus();
             for (int i = 0; i < (int)numPerulangan.Value; i++)
             {
                 rbMaju.Invoke((MethodInvoker) delegate { rbMaju.Checked = true; });
                 rekam();
                 rbMundur.Invoke((MethodInvoker) delegate { rbMundur.Checked = true; });
                 rekam();
                 rbBerhenti.Invoke((MethodInvoker) delegate { rbBerhenti.Checked = true; });
                 rekam();
                 rbKiri.Invoke((MethodInvoker) delegate { rbKiri.Checked = true; });
                 rekam();
                 rbKanan.Invoke((MethodInvoker) delegate { rbKanan.Checked = true; });
                 rekam();
             }
             this.Invoke((MethodInvoker) delegate
             {
                 stimulus.Close();
             });
         }
         else
         {
             rekam();
         }
     }
     cbOtomatis.Invoke((MethodInvoker) delegate { cbOtomatis.Checked = false; });
     if (bgRekam.CancellationPending)
     {
         e.Cancel = true;
         return;
     }
 }