Exemple #1
0
        public EmotionsChartPresenter(
            IEmotionsChart chart,
            EmotionStateChannel stateChannel,
            SpectrumPowerChannel alphaLeft,
            SpectrumPowerChannel betaLeft,
            SpectrumPowerChannel alphaRight,
            SpectrumPowerChannel betaRight,
            EegIndexChannel indexChannel)
        {
            _stateChannel = stateChannel;
            _alphaLeft    = alphaLeft;
            _betaLeft     = betaLeft;
            _alphaRight   = alphaRight;
            _betaRight    = betaRight;
            _indexChannel = indexChannel;

            _chart      = chart;
            _chart.Mode = EmotionBarMode.Wait;

            _stateChannel.LengthChanged += StateChannelLengthChanged;
            _indexChannel.LengthChanged += _indexChannel_LengthChanged;
            _alphaLeft.LengthChanged    += _alphaLeft_LengthChanged;
            _betaLeft.LengthChanged     += _betaLeft_LengthChanged;
            _alphaRight.LengthChanged   += _alphaRight_LengthChanged;
            _betaRight.LengthChanged    += _betaRight_LengthChanged;
        }
        private void CalculateSpectrum()
        {
            if (_spectrumChannel == null)
            {
                return;
            }
            var readLength = (int)(SamplingFrequency * WindowDuration);

            if (readLength <= 0)
            {
                return;
            }

            var offset = _spectrumChannel.TotalLength - readLength;

            if (offset < 0)
            {
                offset     = 0;
                readLength = _spectrumChannel.TotalLength;
            }
            Spectrum = new Spectrum(_spectrumChannel.Info.Name,
                                    _spectrumChannel.ReadData(offset, readLength, WindowType));
            SpectrumPower = SpectrumPowerChannel.SpectrumPower(LowFrequency, HighFrequency, Spectrum.Data,
                                                               _spectrumChannel.HzPerSpectrumSample);
        }
Exemple #3
0
 public IndexListItem(Control context, SpectrumPowerChannel spectrumPowerChannel, IEnumerable <string> channels, float lowFreq, float highFreq, double window, double overlap)
 {
     _context = context;
     Text     = spectrumPowerChannel.Info.Name;
     SubItems.Add(channels.Aggregate("", (current, chan) => current + chan + " "));
     SubItems.Add($"{lowFreq} - {highFreq} Hz");
     SubItems.Add($"{window}/{overlap}");
     SubItems.Add("0.0");
     _spectrumPowerChannel = spectrumPowerChannel;
     _spectrumPowerChannel.LengthChanged += SpectrumPowerChannelLengthChanged;
 }
Exemple #4
0
        private void OnDeviceConnected()
        {
            BatteryChannel = new BatteryChannel(_currentDevice);

            var deviceChannels = _currentDevice.Channels
                                 .Where(x => x.Type == ChannelType.Signal)
                                 .ToDictionary(channelInfo => channelInfo.Name, channelInfo => new EegChannel(_currentDevice, channelInfo));

            if (deviceChannels.ContainsKey("T3") && deviceChannels.ContainsKey("O1"))
            {
                T3O1SignalChannel   = new BipolarDoubleChannel(deviceChannels["T3"], deviceChannels["O1"]);
                T3O1SpectrumChannel = new SpectrumChannel(T3O1SignalChannel);
                if (deviceChannels.ContainsKey("T4") && deviceChannels.ContainsKey("O2"))
                {
                    T4O21SignalChannel  = new BipolarDoubleChannel(deviceChannels["T4"], deviceChannels["O2"]);
                    T4O2SpectrumChannel = new SpectrumChannel(T4O21SignalChannel);
                    IndexChannel        = new EegIndexChannel(deviceChannels["T3"], deviceChannels["T4"], deviceChannels["O1"],
                                                              deviceChannels["O2"]);
                    IndexChannel.SetWeights(1.00, 1.00, 0.00, 0.00);
                    IndexChannel.Delay = 0.0;

                    IndexViewChannel = new EegIndexChannel(deviceChannels["T3"], deviceChannels["T4"], deviceChannels["O1"],
                                                           deviceChannels["O2"]);
                    IndexViewChannel.SetWeights(1.00, 1.00, 0.00, 1.00);
                    IndexViewChannel.Delay = 0.0;

                    AlphaLeftPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> {
                        T3O1SpectrumChannel
                    }, 8, 14, "AlphaLeft");
                    BetaLeftPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> {
                        T3O1SpectrumChannel
                    }, 14, 34, "BetaLeft");
                    AlphaRightPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> {
                        T4O2SpectrumChannel
                    }, 8, 14, "AlphaRight");
                    BetaRightPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> {
                        T4O2SpectrumChannel
                    }, 14, 34, "BetaRight");

                    ChannelsChanged?.Invoke(this, null);
                }
            }
        }
Exemple #5
0
        private void _createIndexButton_Click(object sender, System.EventArgs e)
        {
            if (!float.TryParse(_startFrequencyTextBox.Text, out var startFreq))
            {
                MessageBox.Show("Wrong low frequency value", "Index creation", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (!float.TryParse(_stopFrequencyTextBox.Text, out var stopFreq))
            {
                MessageBox.Show("Wrong high frequency value", "Index creation", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (stopFreq <= startFreq)
            {
                MessageBox.Show("Wrong frequencies: high frequency must be greater than low", "Index creation", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (!double.TryParse(_indexWindowTextBox.Text, out var window))
            {
                MessageBox.Show("Wrong window duration value", "Index creation", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (!double.TryParse(_indexWindowOverlapTextBox.Text, out var overlap))
            {
                MessageBox.Show("Wrong overlap value", "Index creation", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            var checkedChannels      = _channelsListBox.CheckedItems.OfType <DoubleSignalChannelWrap>().ToList();
            var spectrumPowerChannel = new SpectrumPowerChannel(checkedChannels.Select(x => new SpectrumChannel(x)), startFreq, stopFreq, _indexNameTextBox.Text, window, overlap);

            _indicesListView.Items.Add(new IndexListItem(this, spectrumPowerChannel, checkedChannels.Select(x => x.ToString()), startFreq, stopFreq, window, overlap));
        }