Ejemplo n.º 1
0
        public void CalculateFeature()
        {
            for (int i = 0; i < model.dataTraining.Count; i++)
            {
                model.dataTrainingFreq.Add(fft.DoWork(model.dataTraining[i]));
            }

            List <double[]> deltaTheta = new List <double[]>();
            List <double[]> alpha      = new List <double[]>();
            List <double[]> beta       = new List <double[]>();
            List <double[]> gamma      = new List <double[]>();
            List <double[]> result;

            for (int i = 0; i < model.dataTrainingFreq.Count; i++)
            {
                result = dsp.Decomposes(model.dataTrainingFreq[i]);
                deltaTheta.Add(result[0]);
                alpha.Add(result[1]);
                beta.Add(result[2]);
                gamma.Add(result[3]);
            }

            model.spectral.Add("deltaTheta", deltaTheta);
            model.spectral.Add("alpha", alpha);
            model.spectral.Add("beta", beta);
            model.spectral.Add("gamma", gamma);

            int jumlahSensor = model.GetTotalSelectedChannels();
            int jumlahData   = model.GetTotalData();

            //MessageBox.Show(jumlahData.ToString() + " " + jumlahSensor.ToString());

            List <double> fitur = new List <double>();;

            for (int k = 0; k < jumlahData; k++)
            {
                for (int i = 0; i < jumlahSensor; i++)
                {
                    fitur.Add(model.spectral["deltaTheta"][k][i]);
                    fitur.Add(model.spectral["alpha"][k][i]);
                    fitur.Add(model.spectral["beta"][k][i]);
                    fitur.Add(model.spectral["gamma"][k][i]);
                }

                if (jumlahSensor > 1)
                {
                    for (int i = 0; i < jumlahSensor; i++)
                    {
                        for (int j = i + 1; j < jumlahSensor; j++)
                        {
                            double val1      = model.spectral["deltaTheta"][k][i];
                            double val2      = model.spectral["deltaTheta"][k][j];
                            double powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                            fitur.Add(powerDiff);

                            val1      = model.spectral["alpha"][k][i];
                            val2      = model.spectral["alpha"][k][j];
                            powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                            fitur.Add(powerDiff);

                            val1      = model.spectral["beta"][k][i];
                            val2      = model.spectral["beta"][k][j];
                            powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                            fitur.Add(powerDiff);

                            val1      = model.spectral["gamma"][k][i];
                            val2      = model.spectral["gamma"][k][j];
                            powerDiff = Math.Abs((val1 - val2) / (val1 + val2));
                            fitur.Add(powerDiff);
                        }
                    }
                }

                if ((k + 1) % bufferDecision == 0)
                {
                    //MessageBox.Show(fitur.Count.ToString());
                    model.features.Add(fitur);
                    fitur = new List <double>();
                }
            }

            model.SetFeatureClass();

            //MessageBox.Show(model.features.Count.ToString());
        }
Ejemplo n.º 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;
        }