示例#1
0
        private void buttonTrain_Click(object sender, EventArgs e)
        {
            bool canTrain = true;

            for (int i = 0; i < model.classes.Count; i++)
            {
                if (model.classes[classesCommand[i]] && !classesDataLoaded[classesCommand[i]])
                {
                    canTrain = false;
                }
            }

            if (!canTrain)
            {
                MessageBox.Show("Masih ada data set kelas yang belum dicari");
            }
            else
            {
                buttonPhase2.Enabled        = false;
                groupBoxLoadDataSet.Enabled = false;
                buttonTrain.Enabled         = false;

                model.SetChanelsIndex();
                for (int i = 0; i < allData.Count; i++)
                {
                    if (model.classes[classesCommand[i]])
                    {
                        model.dataTraining.AddRange(allData[i]);
                    }
                }

                fft.Init(model.GetTotalSelectedChannels());
                CalculateFeature();
                labelDetailModel.Text = model.ToString();

                //MessageBox.Show(model.dataTraining[0].Count().ToString());
                progressBarModel.Value = 0;
                timerProgress.Enabled  = true;
            }
        }
示例#2
0
        private void timer_Tick(object sender, EventArgs e)
        {
            int totalSensor = models[comboBoxModel.SelectedIndex].GetTotalSelectedChannels();

            dataTesting = new double[totalSensor];

            if (checkShowChart.Checked)
            {
                for (int i = 0; i < totalChannels; i++)
                {
                    DataPoint dp = new DataPoint();
                    dp.SetValueY(eegData[channelsEeg[i]][counter]);
                    chartEeg.Series[i].Points.Add(dp);
                    chartEeg.Update();

                    if (counter > LIMIT_WINDOW_CHART)
                    {
                        chartEeg.Series[i].Points.RemoveAt(0);
                    }
                }
            }

            for (int i = 0; i < totalSensor; i++)
            {
                string id    = models[comboBoxModel.SelectedIndex].selectedChannelsIndex[i];
                double value = eegData[id][counter];
                dataTesting[i] = value;
            }

            fft.Init(totalSensor);
            double[]        dataEegFreq = fft.DoWork(dataTesting);
            List <double[]> result      = dsp.Decomposes(dataEegFreq);

            for (int i = 0; i < totalSensor; i++)
            {
                if (checkShowChart.Checked)
                {
                    chartDeltaTheta.Series[i].Points.AddY(result[0][i]);
                    chartAlpha.Series[i].Points.AddY(result[1][i]);
                    chartBeta.Series[i].Points.AddY(result[2][i]);
                    chartGamma.Series[i].Points.AddY(result[3][i]);

                    if (counter > LIMIT_WINDOW_CHART)
                    {
                        chartDeltaTheta.Series[i].Points.RemoveAt(0);
                        chartAlpha.Series[i].Points.RemoveAt(0);
                        chartBeta.Series[i].Points.RemoveAt(0);
                        chartGamma.Series[i].Points.RemoveAt(0);
                    }
                }

                fitur.Add(result[0][i]);
                fitur.Add(result[1][i]);
                fitur.Add(result[2][i]);
                fitur.Add(result[3][i]);
            }

            if (checkShowChart.Checked)
            {
                chartEeg.ChartAreas[0].RecalculateAxesScale();
                chartDeltaTheta.ChartAreas[0].RecalculateAxesScale();
                chartAlpha.ChartAreas[0].RecalculateAxesScale();
                chartBeta.ChartAreas[0].RecalculateAxesScale();
                chartGamma.ChartAreas[0].RecalculateAxesScale();
            }

            if (totalSensor > 1)
            {
                for (int i = 0; i < totalSensor; i++)
                {
                    for (int j = i + 1; j < totalSensor; j++)
                    {
                        double val1      = result[0][i];
                        double val2      = result[0][j];
                        double powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                        fitur.Add(powerDiff);

                        val1      = result[1][i];
                        val2      = result[1][j];
                        powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                        fitur.Add(powerDiff);

                        val1      = result[2][i];
                        val2      = result[2][j];
                        powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                        fitur.Add(powerDiff);

                        val1      = result[3][i];
                        val2      = result[3][j];
                        powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                        fitur.Add(powerDiff);
                    }
                }
            }

            if ((buffer + 1) == bufferDecision)
            {
                int classifyResult = knn.Classify(fitur, 1);
                if (compareClass == classifyResult)
                {
                    totalCorrectOutput++;
                }

                labelMovement.Text = classesCommand[classifyResult];

                if (counterOutput == 20)
                {
                    double akurasi = (double)totalCorrectOutput / counterOutput * 100;
                    timer.Enabled = false;
                    MessageBox.Show("akurasi: " + akurasi + "%");
                }

                fitur  = new List <double>();
                buffer = -1;
                tickSecond++;
                counterOutput++;
                labelTickSecond.Text = tickSecond.ToString();
            }

            ++buffer;
            ++counter;
        }