Ejemplo n.º 1
0
        private static List <double[]> preprocessSignal(List <double[]> sinyal)
        {
            Console.WriteLine("Bandpass Filter");
            var watch = new Stopwatch();

            watch.Start();
            var jumlahKanal  = sinyal.Count();
            var jumlahSample = sinyal.First().Length;
            var sinyalFilter = new List <double[]>();

            for (int i = 0; i < jumlahKanal; i++)
            {
                sinyalFilter.Add(new double[jumlahSample]);
            }
            Parallel.For(0, jumlahKanal, i => {
                var bandpass   = new DesignButterworth(Filter.BandPass, 5, 8, 30, _samplingrate);
                bandpass.Input = sinyal[i];
                bandpass.iirInitialization();
                bandpass.compute();
                sinyalFilter[i] = bandpass.Output;
            });
            watch.Stop();
            Console.WriteLine("Selesai Bandpass Filter " + watch.ElapsedMilliseconds + " ms");
            return(sinyalFilter);
        }
Ejemplo n.º 2
0
        private List <double[]> preprocessSignal(List <double[]> sinyal)
        {
            var jumlahKanal  = sinyal.Count();
            var jumlahSample = sinyal.First().Length;
            var sinyalFilter = new List <double[]>();

            for (int i = 0; i < jumlahKanal; i++)
            {
                sinyalFilter.Add(new double[jumlahSample]);
            }
            Parallel.For(0, jumlahKanal, i => {
                var bandpass   = new DesignButterworth(Filter.BandPass, 5, 8, 30, _samplingrate);
                bandpass.Input = sinyal[i];
                bandpass.iirInitialization();
                bandpass.compute();
                sinyalFilter[i] = bandpass.Output;
            });
            return(sinyalFilter);
        }
Ejemplo n.º 3
0
        public TestButterworth()
        {
            InitializeComponent();
            var row = File.ReadLines("D:\\Clouds\\Google Drive\\Dari Dropbox\\FILKOM - IF\\Semester 7\\Skripsi\\MuseCSharpLSL\\MuseCSharpLSL\\bin\\Debug\\RAW_HURUF\\Adri_Berhenti_RAW_HURUF_16_56_20.csv");

            y = Array.ConvertAll(row.First().Split(';'), double.Parse);

            var bandpass = new DesignButterworth(Filter.BandPass, 5, 8, 30, 256);

            bandpass.iirInitialization();
            bandpass.Input = y;
            bandpass.compute();
            yf2 = bandpass.Output;
            for (int i = 0; i < y.Length; i++)
            {
                //chart1.Series[0].Points.AddY(y[i]);
                chart1.Series[2].Points.AddY(y[i]);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var    nama  = new string[] { "Ramda", "Nanda", "Veny", "Col", "Ekky", "Adri", "Yoga", "RefriR", "RefriR_Test", "Della", "Della_Test", "Galang", "Galang_Test", "Arif", "Arif_Test", "Dian", "Dian_Test", "Chen", "Chen_Test", "Rizky", "Rizky_Test" };
            var    arah  = new string[] { "Maju", "Mundur", "Berhenti", "Kiri", "Kanan" };
            double total = nama.Length * arah.Length * 5;
            var    now   = 0;

            foreach (var n in nama)
            {
                foreach (var a in arah)
                {
                    var folderPath = "Sinyal\\" + n + "\\" + a;
                    foreach (string file in Directory.EnumerateFiles(folderPath, "*.csv"))
                    {
                        string dateTime     = DateTime.Now.ToString("HH_mm_ss");
                        var    channels     = File.ReadLines(file);
                        var    sinyalFilter = new double[channels.Count()][];
                        int    i            = 0;
                        foreach (var c in channels)
                        {
                            var signal   = Array.ConvertAll(c.Split(';'), double.Parse);
                            var bandpass = new DesignButterworth(Filter.BandPass, 5, 8, 30, _samplingrate);
                            bandpass.Input = signal;
                            bandpass.iirInitialization();
                            bandpass.compute();
                            sinyalFilter[i] = bandpass.Output;
                            i++;
                        }
                        var dft     = featureExtraction(sinyalFilter);
                        var feature = dftToOneRowFeature(dft);
                        saveFile(sinyalFilter, n, "BPF", a, dateTime);
                        saveFile(dft, n, "DFT", a, dateTime);
                        saveFeature(feature, n, a);
                        now++;
                        Console.WriteLine("DONE " + n + " " + a + " " + now + "/" + total);
                    }
                }
            }
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            opendatasets();
            Console.WriteLine("Masukkan Samplingrate : ");
            _SamplingRate = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Channels (Contoh Input : 0,1,2,..,N (Lihat Dokumentasi Datasets)) : ");
            _ChannelsChoose = Array.ConvertAll(Console.ReadLine().Split(','), int.Parse);
            Console.WriteLine("Masukkan Times Triggers Start : ");
            _TriggerTimeStart = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Masukkan Times Triggers Stop : ");
            _TriggerTimeStop  = Convert.ToInt32(Console.ReadLine());
            _EpocSizeTraining = (_TriggerTimeStop - _TriggerTimeStart) * _SamplingRate;
            _Artifact         = new List <List <bool> >();
            _ClassLabel       = new List <List <int> >();
            _Trigger          = new List <List <int> >();
            _Data             = new List <List <double[]> >();

            for (int i = 0; i < _dataPath.Count; i++)
            {
                ReadArtifactSelection(_artifactPath[i]);
                Console.WriteLine("Datasets " + Path.GetFileNameWithoutExtension(_dataPath[i]) + " List Artifact Load Done");
            }
            for (int i = 0; i < _dataPath.Count(); i++)
            {
                ReadClassLabels(_classLabelPath[i]);
            }
            for (int i = 0; i < _dataPath.Count; i++)
            {
                ReadTrigger(_triggerPath[i]);
                Console.WriteLine("Datasets " + Path.GetFileNameWithoutExtension(_dataPath[i]) + " List Trigger Load Done");
            }
            for (int i = 0; i < _dataPath.Count; i++)
            {
                ReadData(_dataPath[i]);
                Console.WriteLine("Datasets " + Path.GetFileNameWithoutExtension(_dataPath[i]) + " List Data EEG Load Done");
            }
            int countFile = _Data.Count();

            _Subject = new double[countFile][][][];//subject //perStimulus //times //Channels
            Parallel.For(0, countFile, i =>
            {
                var perData = new double[_Trigger[i].Count][][];
                Parallel.For(0, _Trigger[i].Count(), j =>
                {
                    var startFrom    = _Trigger[i][j] + (_SamplingRate * _TriggerTimeStart);
                    var endTo        = startFrom + (_SamplingRate * (_TriggerTimeStop - _TriggerTimeStart));
                    var newArrayTemp = new double[endTo - startFrom][];
                    int l            = 0;
                    for (int k = startFrom; k < endTo; k++)
                    {
                        newArrayTemp[l] = _Data[i][k];
                        l++;
                    }
                    var pivotArray = new double[newArrayTemp[0].Length][];
                    Parallel.For(0, pivotArray.Length, k =>
                    {
                        var pivotTimes = new double[newArrayTemp.Length];
                        Parallel.For(0, pivotTimes.Length, m =>
                        {
                            pivotTimes[m] = newArrayTemp[m][k];
                        });
                        pivotArray[k] = pivotTimes;
                    });
                    perData[j] = pivotArray;
                });
                _Subject[i] = perData;
            });

            var ApplyingButterworth = new double[countFile][][][];

            Parallel.For(0, ApplyingButterworth.Length, i =>
            {
                var subjectRow = new double[_Subject[i].Length][][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    var channels = new double[_Subject[i][j].Length][];
                    Parallel.For(0, channels.Length, k =>
                    {
                        var bandpass   = new DesignButterworth(Filter.BandPass, 5, 8, 30, _SamplingRate);
                        bandpass.Input = _Subject[i][j][k];
                        bandpass.iirInitialization();
                        bandpass.compute();
                        channels[k] = bandpass.Output;
                    });
                    subjectRow[j] = channels;
                });
                Console.WriteLine("Subject-" + i + " Butterworth Done");
                ApplyingButterworth[i] = subjectRow;
            });

            var ApplyingDFT = new double[countFile][][][];

            Parallel.For(0, ApplyingDFT.Length, i =>
            {
                var subjectRow = new double[ApplyingButterworth[i].Length][][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    var channels = new double[ApplyingButterworth[i][j].Length][];
                    Parallel.For(0, channels.Length, k =>
                    {
                        var jumlahSample = ApplyingButterworth[i][j][k].Length / 2;
                        channels[k]      = new DiscreteFourierTransform().discreteFourierTransform(ApplyingButterworth[i][j][k]).Take(jumlahSample).ToArray();
                    });
                    subjectRow[j] = channels;
                });
                Console.WriteLine("Subject-" + i + " DFT Done");
                ApplyingDFT[i] = subjectRow;
            });

            var ExtractFeature = new double[countFile][][];

            Parallel.For(0, ExtractFeature.Length, i =>
            {
                var subjectRow = new double[ApplyingDFT[i].Length][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    subjectRow[j] = dftToOneRowFeature(ApplyingDFT[i][j]);
                });
                Console.WriteLine("Subject-" + i + " Extraction Feature Done");
                ExtractFeature[i] = subjectRow;
            });
            Parallel.For(0, ExtractFeature.Length, i =>
            {
                for (int j = 0; j < ExtractFeature[i].Length; j++)
                {
                    if (!_Artifact[i][j])
                    {
                        saveFeature(ExtractFeature[i][j], Path.GetFileNameWithoutExtension(_dataPath[i]), _ClassLabel[i][j]);
                    }
                }
                Console.WriteLine("Subject-" + i + " Save Feature Done");
            });
        }
Ejemplo n.º 6
0
        private void bgProses_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Invoke((MethodInvoker) delegate
            {
                tlpMain.Enabled         = false;
                btnOpenDatasets.Enabled = false;
            });
            _SamplingRate     = (int)numSamplingRate.Value;
            _ChannelsChoose   = tbChannels.Text.Split(',').Select(Int32.Parse).ToArray();
            _TriggerTimeStart = (int)numTriggerStart.Value;
            _TriggerTimeStop  = (int)numTriggerStop.Value;
            _EpocSizeTraining = (_TriggerTimeStop - _TriggerTimeStart) * _SamplingRate;
            _Artifact         = new List <List <bool> >();
            _ClassLabel       = new List <List <int> >();
            _Trigger          = new List <List <int> >();
            _Data             = new List <List <double[]> >();
            for (int i = 0; i < _dataPath.Count; i++)
            {
                ReadArtifactSelection(_artifactPath[i]);
                updateAktivitas("Datasets " + Path.GetFileNameWithoutExtension(_dataPath[i]) + " List Artifact Load Done");
            }
            for (int i = 0; i < _dataPath.Count(); i++)
            {
                ReadClassLabels(_classLabelPath[i]);
            }
            for (int i = 0; i < _dataPath.Count; i++)
            {
                ReadTrigger(_triggerPath[i]);
                updateAktivitas("Datasets " + Path.GetFileNameWithoutExtension(_dataPath[i]) + " List Trigger Load Done");
            }
            for (int i = 0; i < _dataPath.Count; i++)
            {
                ReadData(_dataPath[i]);
                updateAktivitas("Datasets " + Path.GetFileNameWithoutExtension(_dataPath[i]) + " List Data EEG Load Done");
            }
            int countFile = _Data.Count();

            _Subject = new double[countFile][][][];//subject //perStimulus //times //Channels
            Parallel.For(0, countFile, i =>
            {
                var perData = new double[_Trigger[i].Count][][];
                Parallel.For(0, _Trigger[i].Count(), j =>
                {
                    var startFrom    = _Trigger[i][j] + (_SamplingRate * _TriggerTimeStart);
                    var endTo        = startFrom + (_SamplingRate * (_TriggerTimeStop - _TriggerTimeStart));
                    var newArrayTemp = new double[endTo - startFrom][];
                    int l            = 0;
                    for (int k = startFrom; k < endTo; k++)
                    {
                        newArrayTemp[l] = _Data[i][k];
                        l++;
                    }
                    var pivotArray = new double[newArrayTemp[0].Length][];
                    Parallel.For(0, pivotArray.Length, k =>
                    {
                        var pivotTimes = new double[newArrayTemp.Length];
                        Parallel.For(0, pivotTimes.Length, m =>
                        {
                            pivotTimes[m] = newArrayTemp[m][k];
                        });
                        pivotArray[k] = pivotTimes;
                    });
                    perData[j] = pivotArray;
                });
                _Subject[i] = perData;
            });

            var ApplyingButterworth = new double[countFile][][][];

            Parallel.For(0, ApplyingButterworth.Length, i =>
            {
                var subjectRow = new double[_Subject[i].Length][][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    var channels = new double[_Subject[i][j].Length][];
                    Parallel.For(0, channels.Length, k =>
                    {
                        var bandpass   = new DesignButterworth(Filter.BandPass, 5, 8, 30, _SamplingRate);
                        bandpass.Input = _Subject[i][j][k];
                        bandpass.iirInitialization();
                        bandpass.compute();
                        channels[k] = bandpass.Output;
                    });
                    subjectRow[j] = channels;
                });
                updateAktivitas("Subject-" + i + " Butterworth Done");
                ApplyingButterworth[i] = subjectRow;
            });

            var ApplyingDFT = new double[countFile][][][];

            Parallel.For(0, ApplyingDFT.Length, i =>
            {
                var subjectRow = new double[ApplyingButterworth[i].Length][][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    var channels = new double[ApplyingButterworth[i][j].Length][];
                    Parallel.For(0, channels.Length, k =>
                    {
                        var jumlahSample = ApplyingButterworth[i][j][k].Length / 2;
                        channels[k]      = new DiscreteFourierTransform().discreteFourierTransform(ApplyingButterworth[i][j][k]).Take(jumlahSample).ToArray();
                    });
                    subjectRow[j] = channels;
                });
                updateAktivitas("Subject-" + i + " DFT Done");
                ApplyingDFT[i] = subjectRow;
            });

            var ExtractFeature = new double[countFile][][];

            Parallel.For(0, ExtractFeature.Length, i =>
            {
                var subjectRow = new double[ApplyingDFT[i].Length][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    subjectRow[j] = dftToOneRowFeature(ApplyingDFT[i][j]);
                });
                updateAktivitas("Subject-" + i + " Extraction Feature Done");
                ExtractFeature[i] = subjectRow;
            });
            Parallel.For(0, ExtractFeature.Length, i =>
            {
                for (int j = 0; j < ExtractFeature[i].Length; j++)
                {
                    if (!_Artifact[i][j])
                    {
                        saveFeature(ExtractFeature[i][j], Path.GetFileNameWithoutExtension(_dataPath[i]), _ClassLabel[i][j]);
                    }
                }
                updateAktivitas("Subject-" + i + " Save Feature Done");
            });
            this.Invoke((MethodInvoker) delegate
            {
                tlpMain.Enabled         = true;
                btnOpenDatasets.Enabled = true;
            });
            if (bgProses.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            _Artifact   = new List <List <bool> >();
            _ClassLabel = new List <List <int> >();
            _Trigger    = new List <List <int> >();

            foreach (string file in Directory.EnumerateFiles("datasets", "*.HDR_ArtifactSelection"))
            {
                var contents    = File.ReadLines(file);
                var newArtifact = new List <bool>();
                foreach (var row in contents)
                {
                    newArtifact.Add(Convert.ToBoolean(Convert.ToInt16(row)));
                }
                _Artifact.Add(newArtifact);
            }
            foreach (string file in Directory.EnumerateFiles("datasets", "*.HDR_Classlabel"))
            {
                var contents = File.ReadLines(file);
                var newLabel = new List <int>();
                foreach (var row in contents)
                {
                    if (row == "NaN")
                    {
                        newLabel.Add(5);
                    }
                    else
                    {
                        newLabel.Add(Convert.ToInt16(row));
                    }
                }
                _ClassLabel.Add(newLabel);
            }
            foreach (string file in Directory.EnumerateFiles("datasets", "*.HDR_TRIG"))
            {
                var contents   = File.ReadLines(file);
                var newTrigger = new List <int>();
                foreach (var row in contents)
                {
                    newTrigger.Add(Convert.ToInt32(row));
                }
                _Trigger.Add(newTrigger);
            }
            _Data = new List <List <double[]> >();
            foreach (string file in Directory.EnumerateFiles("datasets", "*.data"))
            {
                var contents = File.ReadLines(file);
                var newData  = new List <double[]>();
                foreach (var row in contents)
                {
                    var timesAllChannels = Array.ConvertAll(row.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries), Double.Parse);
                    var times            = new double[] { timesAllChannels[26], timesAllChannels[5], timesAllChannels[9], timesAllChannels[36] };
                    newData.Add(times);
                }
                _Data.Add(newData);
            }
            int countFile = _Data.Count();

            _Subject = new double[countFile][][][];//subject //perStimulus //times //Channels
            Parallel.For(0, countFile, i =>
            {
                var perData = new double[_Trigger[i].Count][][];
                Parallel.For(0, _Trigger[i].Count(), j =>
                {
                    var startFrom    = _Trigger[i][j] + (_SamplingRate * (_FixationCross + _BlankScreen));
                    var endTo        = startFrom + (_SamplingRate * _StimulusShown);
                    var newArrayTemp = new double[endTo - startFrom][];
                    int l            = 0;
                    for (int k = startFrom; k < endTo; k++)
                    {
                        newArrayTemp[l] = _Data[i][k];
                        l++;
                    }
                    var pivotArray = new double[newArrayTemp[0].Length][];
                    Parallel.For(0, pivotArray.Length, k =>
                    {
                        var pivotTimes = new double[newArrayTemp.Length];
                        Parallel.For(0, pivotTimes.Length, m =>
                        {
                            pivotTimes[m] = newArrayTemp[m][k];
                        });
                        pivotArray[k] = pivotTimes;
                    });
                    perData[j] = pivotArray;
                });
                _Subject[i] = perData;
            });


            var ApplyingButterworth = new double[countFile][][][];

            Parallel.For(0, ApplyingButterworth.Length, i =>
            {
                var subjectRow = new double[_Subject[i].Length][][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    var channels = new double[_Subject[i][j].Length][];
                    Parallel.For(0, channels.Length, k =>
                    {
                        var bandpass   = new DesignButterworth(Filter.BandPass, 5, 8, 30, _SamplingRate);
                        bandpass.Input = _Subject[i][j][k];
                        bandpass.iirInitialization();
                        bandpass.compute();
                        channels[k] = bandpass.Output;
                    });
                    subjectRow[j] = channels;
                });
                Console.WriteLine("Subject-" + i + " Butterworth Done");
                ApplyingButterworth[i] = subjectRow;
            });

            var ApplyingDFT = new double[countFile][][][];

            Parallel.For(0, ApplyingDFT.Length, i =>
            {
                var subjectRow = new double[ApplyingButterworth[i].Length][][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    var channels = new double[ApplyingButterworth[i][j].Length][];
                    Parallel.For(0, channels.Length, k =>
                    {
                        var jumlahSample = ApplyingButterworth[i][j][k].Length / 2;
                        channels[k]      = new DiscreteFourierTransform().discreteFourierTransform(ApplyingButterworth[i][j][k]).Take(jumlahSample).ToArray();
                    });
                    subjectRow[j] = channels;
                });
                Console.WriteLine("Subject-" + i + " DFT Done");
                ApplyingDFT[i] = subjectRow;
            });

            var ExtractFeature = new double[countFile][][];

            Parallel.For(0, ExtractFeature.Length, i =>
            {
                var subjectRow = new double[ApplyingDFT[i].Length][];
                Parallel.For(0, subjectRow.Length, j =>
                {
                    subjectRow[j] = dftToOneRowFeature(ApplyingDFT[i][j]);
                });
                Console.WriteLine("Subject-" + i + " Extraction Feature Done");
                ExtractFeature[i] = subjectRow;
            });
            Parallel.For(0, ExtractFeature.Length, i =>
            {
                for (int j = 0; j < ExtractFeature[i].Length; j++)
                {
                    if (!_Artifact[i][j])
                    {
                        saveFeature(ExtractFeature[i][j], i, _ClassLabel[i][j] - 1);
                    }
                }
                Console.WriteLine("Subject-" + i + " Save Feature Done");
            });
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            Console.ReadKey();
            stopwatch.Stop();
        }