예제 #1
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; });
        }
예제 #2
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;
     }
 }