EKG_Project.Modules.ECG_Baseline.ECG_Baseline.processData C# (CSharp) Method

processData() private method

private processData ( ) : void
return void
        private void processData()
        {
            int channel = _currentChannelIndex;
            int startIndex = _samplesProcessed;
            int step = 1000;

            if (channel < NumberOfChannels)
            {
                if (startIndex + step >= _currentChannelLength)
                {

                    _currentVector = InputData.Signals[_currentChannelIndex].Item2.SubVector(startIndex, _currentChannelLength - startIndex);

                    switch (Params.Method)
                    {
                        case Filtr_Method.MOVING_AVG:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            break;
                        case Filtr_Method.BUTTERWORTH:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcLow, Params.OrderLow, Filtr_Type.LOWPASS);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcHigh, Params.OrderHigh, Filtr_Type.HIGHPASS);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcLow, Params.OrderLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcHigh, Params.OrderHigh, Filtr_Type.HIGHPASS);
                            }
                            break;
                        case Filtr_Method.SAV_GOL:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            break;
                        case Filtr_Method.LMS:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _temporaryVector = _currentVector;
                                _temporaryVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.lms(_currentVector, _temporaryVector, Params.WindowSizeLow);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _temporaryVector = _currentVector;
                                _temporaryVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                                _currentVector = _newFilter.lms(_currentVector, _temporaryVector, Params.WindowSizeHigh);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _temporaryVector = _currentVector;
                                _temporaryVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _temporaryVector = _newFilter.savitzky_golay(_temporaryVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                                _currentVector = _newFilter.lms(_currentVector, _temporaryVector, Params.WindowSizeHigh);
                            }
                            break;
                    }

                    _currentVector.CopySubVectorTo(_temporaryVector2, 0, startIndex, _currentVector.Count);
                    //OutputData.SignalsFiltered.Add(new Tuple<string, Vector<double>>(InputData.Signals[_currentChannelIndex].Item1, _currentVector));
                    OutputData.SignalsFiltered.Add(new Tuple<string, Vector<double>>(InputData.Signals[_currentChannelIndex].Item1, _temporaryVector2));
                    _currentChannelIndex++;

                    if (_currentChannelIndex < NumberOfChannels)
                    {
                        _samplesProcessed = 0;
                        _currentChannelLength = InputData.Signals[_currentChannelIndex].Item2.Count;
                        _currentVector = Vector<Double>.Build.Dense(_currentChannelLength);
                        _temporaryVector2 = Vector<Double>.Build.Dense(_currentChannelLength);
                    }

                }
                else
                {

                    _currentVector = InputData.Signals[_currentChannelIndex].Item2.SubVector(startIndex, step);

                    switch (Params.Method)
                    {
                        case Filtr_Method.MOVING_AVG:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.moving_average(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            break;
                        case Filtr_Method.BUTTERWORTH:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcLow, Params.OrderLow, Filtr_Type.LOWPASS);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcHigh, Params.OrderHigh, Filtr_Type.HIGHPASS);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcLow, Params.OrderLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.butterworth(_currentVector, InputData.Frequency, Params.FcHigh, Params.OrderHigh, Filtr_Type.HIGHPASS);
                            }
                            break;
                        case Filtr_Method.SAV_GOL:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                            }
                            break;
                        case Filtr_Method.LMS:
                            if (Params.Type == Filtr_Type.LOWPASS)
                            {
                                _temporaryVector = _currentVector;
                                _temporaryVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _currentVector = _newFilter.lms(_currentVector, _temporaryVector, Params.WindowSizeLow);
                            }
                            if (Params.Type == Filtr_Type.HIGHPASS)
                            {
                                _temporaryVector = _currentVector;
                                _temporaryVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                                _currentVector = _newFilter.lms(_currentVector, _temporaryVector, Params.WindowSizeHigh);
                            }
                            if (Params.Type == Filtr_Type.BANDPASS)
                            {
                                _temporaryVector = _currentVector;
                                _temporaryVector = _newFilter.savitzky_golay(_currentVector, Params.WindowSizeLow, Filtr_Type.LOWPASS);
                                _temporaryVector = _newFilter.savitzky_golay(_temporaryVector, Params.WindowSizeHigh, Filtr_Type.HIGHPASS);
                                _currentVector = _newFilter.lms(_currentVector, _temporaryVector, Params.WindowSizeHigh);
                            }
                            break;

                    }
                    _currentVector.CopySubVectorTo(_temporaryVector2, 0, startIndex, _currentVector.Count);
                    //OutputData.SignalsFiltered.Add(new Tuple<string, Vector<double>>(InputData.Signals[_currentChannelIndex].Item1, _currentVector));
                    _samplesProcessed = startIndex + step;
                }
            }
            else
            {
                OutputWorker.Save(OutputData);
                _ended = true;
            }
        }