Exemple #1
0
        public void deleteSignal(EDFSignal signal_to_delete)
        {
            if (this.Header.Signals.Contains(signal_to_delete))
            {
                //Remove Signal DataRecords
                foreach (EDFDataRecord dr in this.DataRecords)
                {
                    foreach (EDFSignal signal in this.Header.Signals)
                    {
                        if (signal.IndexNumberWithLabel.Equals(signal_to_delete.IndexNumberWithLabel))
                        {
                            dr.Remove(signal_to_delete.IndexNumber);
                        }
                    }
                }
                //After removing the DataRecords then Remove the Signal from the Header
                this.Header.Signals.Remove(signal_to_delete);

                //Finally Decrement the NumberOfSignals in the Header by 1
                this.Header.NumberOfSignalsInDataRecord = this.Header.NumberOfSignalsInDataRecord - 1;

                //Change the Number Of Bytes in the Header.
                this.Header.NumberOfBytes = (256) + (256 * this.Header.Signals.Count);
            }
        }
Exemple #2
0
        public List <float> retrieveSignalSampleValues(EDFSignal signal_to_retrieve)
        {
            List <float> signalSampleValues = new List <float>();

            if (this.Header.Signals.Contains(signal_to_retrieve))
            {
                //Remove Signal DataRecords
                foreach (EDFDataRecord dr in this.DataRecords)
                {
                    foreach (EDFSignal signal in this.Header.Signals)
                    {
                        if (signal.IndexNumberWithLabel.Equals(signal_to_retrieve.IndexNumberWithLabel))
                        {
                            foreach (float value in dr[signal.IndexNumber])
                            {
                                signalSampleValues.Add(value);
                            }
                        }
                    }
                }
            }
            return(signalSampleValues);
        }
Exemple #3
0
        public void addSignal(EDFSignal signal_to_add, List <float> sampleValues)
        {
            if (this.Header.Signals.Contains(signal_to_add))
            {
                this.deleteSignal(signal_to_add);
            }

            //Remove Signal DataRecords
            int index = 0;

            foreach (EDFDataRecord dr in this.DataRecords)
            {
                dr.Add(signal_to_add.IndexNumber, sampleValues.GetRange(index * signal_to_add.NumberOfSamplesPerDataRecord, signal_to_add.NumberOfSamplesPerDataRecord).ToArray());
                index++;
            }
            //After removing the DataRecords then Remove the Signal from the Header
            this.Header.Signals.Add(signal_to_add);

            //Finally Decrement the NumberOfSignals in the Header by 1
            this.Header.NumberOfSignalsInDataRecord = this.Header.NumberOfSignalsInDataRecord + 1;

            //Change the Number Of Bytes in the Header.
            this.Header.NumberOfBytes = (256) + (256 * this.Header.Signals.Count);
        }
Exemple #4
0
        /// <summary>
        /// 解析导联列表
        /// </summary>
        public void parseSignals(byte[] signals, Encoding encoding)
        {
            // 将转换后的内容写入缓存
            _strHeader.Append(encoding.GetChars(signals));

            // 解析导联列表
            this.Signals = new List <EDFSignal>();

            // TODO 各部分字节数应该写成常量
            EDFSignal edf_signal;
            int       _index;

            for (int i = 0; i < this.NumberOfSignalsInDataRecord; i++)
            {
                edf_signal = new EDFSignal();

                _index = 0;

                // 标签名
                var    _labelLength = 16;
                byte[] label        = getFixedLengthByteArrayFromHeader(signals, (i * _labelLength) + (this.NumberOfSignalsInDataRecord * _index), _labelLength);
                edf_signal.Label = new string(encoding.GetChars(label)).Trim();
                _index          += _labelLength;

                // if (edf_signal.Label.IndexOf("Annotations") > 0) continue;

                // 序号
                edf_signal.IndexNumber = (i + 1);

                // 传感器类型
                var    _transducerTypeLength = 80;
                byte[] transducer_type       = getFixedLengthByteArrayFromHeader(signals, (i * _transducerTypeLength) + (this.NumberOfSignalsInDataRecord * _index), _transducerTypeLength);
                edf_signal.TransducerType = new string(encoding.GetChars(transducer_type));
                _index += _transducerTypeLength;

                //
                var    _physicalDimensionLength = 8;
                byte[] physical_dimension       = getFixedLengthByteArrayFromHeader(signals, (i * _physicalDimensionLength) + (this.NumberOfSignalsInDataRecord * _index), _physicalDimensionLength);
                edf_signal.PhysicalDimension = new string(encoding.GetChars(physical_dimension));
                _index += _physicalDimensionLength;

                //
                var    _physicalMinLength = 8;
                byte[] physical_min       = getFixedLengthByteArrayFromHeader(signals, (i * _physicalMinLength) + (this.NumberOfSignalsInDataRecord * _index), _physicalMinLength);
                edf_signal.PhysicalMinimum = float.Parse(new string(encoding.GetChars(physical_min)).Trim());
                _index += _physicalMinLength;

                //
                var    _physicalMaxLength = 8;
                byte[] physical_max       = getFixedLengthByteArrayFromHeader(signals, (i * _physicalMaxLength) + (this.NumberOfSignalsInDataRecord * _index), _physicalMaxLength);
                edf_signal.PhysicalMaximum = float.Parse(new string(encoding.GetChars(physical_max)).Trim());
                _index += _physicalMaxLength;

                //
                var    _digitalMinLength = 8;
                byte[] digital_min       = getFixedLengthByteArrayFromHeader(signals, (i * _digitalMinLength) + (this.NumberOfSignalsInDataRecord * _index), _digitalMinLength);
                edf_signal.DigitalMinimum = float.Parse(new string(encoding.GetChars(digital_min)).Trim());
                _index += _digitalMinLength;

                //
                var    _digitalMaxLength = 8;
                byte[] digital_max       = getFixedLengthByteArrayFromHeader(signals, (i * _digitalMaxLength) + (this.NumberOfSignalsInDataRecord * _index), _digitalMaxLength);
                edf_signal.DigitalMaximum = float.Parse(new string(encoding.GetChars(digital_max)).Trim());
                _index += _digitalMaxLength;

                //
                var    _prefilteringLength = 80;
                byte[] prefiltering        = getFixedLengthByteArrayFromHeader(signals, (i * _prefilteringLength) + (this.NumberOfSignalsInDataRecord * _index), _prefilteringLength);
                edf_signal.Prefiltering = new string(encoding.GetChars(prefiltering));
                _index += _prefilteringLength;

                //
                var    _samplesEachDatarecordLength = 8;
                byte[] samples_each_datarecord      = getFixedLengthByteArrayFromHeader(signals, (i * _samplesEachDatarecordLength) + (this.NumberOfSignalsInDataRecord * _index), _samplesEachDatarecordLength);
                edf_signal.NumberOfSamplesPerDataRecord = int.Parse(new string(encoding.GetChars(samples_each_datarecord)).Trim());
                _index += _samplesEachDatarecordLength;


                this.Signals.Add(edf_signal);
            }
        }
Exemple #5
0
        public void parseSignals(char[] signals)
        {
            this._strHeader.Append(signals);

            this.Signals = new List <EDFSignal>();

            /**
             * replace nulls with space.
             */
            int h = 0;

            foreach (char c in signals)
            {
                if (signals[h] == (char)0)
                {
                    signals[h] = (char)32;
                }
                h++;
            }

            for (int i = 0; i < this.NumberOfSignalsInDataRecord; i++)
            {
                EDFSignal edf_signal = new EDFSignal();

                int charIndex = 0;

                char[] label = getFixedLengthCharArrayFromHeader(signals, (i * 16) + (this.NumberOfSignalsInDataRecord * charIndex), 16);
                edf_signal.Label = new string(label);
                charIndex       += 16;

                edf_signal.IndexNumber = (i + 1);

                char[] transducer_type = getFixedLengthCharArrayFromHeader(signals, (i * 80) + (this.NumberOfSignalsInDataRecord * charIndex), 80);
                edf_signal.TransducerType = new string(transducer_type);
                charIndex += 80;

                char[] physical_dimension = getFixedLengthCharArrayFromHeader(signals, (i * 8) + (this.NumberOfSignalsInDataRecord * charIndex), 8);
                edf_signal.PhysicalDimension = new string(physical_dimension);
                charIndex += 8;

                char[] physical_min = getFixedLengthCharArrayFromHeader(signals, (i * 8) + (this.NumberOfSignalsInDataRecord * charIndex), 8);
                edf_signal.PhysicalMinimum = float.Parse(new string(physical_min).Trim());
                charIndex += 8;

                char[] physical_max = getFixedLengthCharArrayFromHeader(signals, (i * 8) + (this.NumberOfSignalsInDataRecord * charIndex), 8);
                edf_signal.PhysicalMaximum = float.Parse(new string(physical_max).Trim());
                charIndex += 8;

                char[] digital_min = getFixedLengthCharArrayFromHeader(signals, (i * 8) + (this.NumberOfSignalsInDataRecord * charIndex), 8);
                edf_signal.DigitalMinimum = float.Parse(new string(digital_min).Trim());
                charIndex += 8;

                char[] digital_max = getFixedLengthCharArrayFromHeader(signals, (i * 8) + (this.NumberOfSignalsInDataRecord * charIndex), 8);
                edf_signal.DigitalMaximum = float.Parse(new string(digital_max).Trim());
                charIndex += 8;

                char[] prefiltering = getFixedLengthCharArrayFromHeader(signals, (i * 80) + (this.NumberOfSignalsInDataRecord * charIndex), 80);
                edf_signal.Prefiltering = new string(prefiltering);
                charIndex += 80;

                char[] samples_each_datarecord = getFixedLengthCharArrayFromHeader(signals, (i * 8) + (this.NumberOfSignalsInDataRecord * charIndex), 8);
                edf_signal.NumberOfSamplesPerDataRecord = int.Parse(new string(samples_each_datarecord).Trim());
                charIndex += 8;

                this.Signals.Add(edf_signal);
            }
        }