コード例 #1
0
        /// <summary>
        /// Set AVM for all signals
        /// </summary>
        /// <param name="avm">preferred multiplier</param>
        public void SetAVM(double avm)
        {
            if (avm != 0.0)
            {
                int nrLeads = this.NrLeads;

                for (int i = 0; i < nrLeads; i++)
                {
                    ECGTool.ChangeMultiplier(this[i].Rhythm, this.RhythmAVM, avm);
                    ECGTool.ChangeMultiplier(this[i].Median, this.MedianAVM, avm);
                }

                if (this.RhythmAVM != 0.0)
                {
                    this.RhythmAVM = avm;
                }

                if (this.MedianAVM != 0.0)
                {
                    this.MedianAVM = avm;
                }
            }
        }
コード例 #2
0
ファイル: SCPFormat.cs プロジェクト: zxy30/ECGToolkit
        public int getSignalsToObj(Signals signals)
        {
            if (signals != null)
            {
                if (((ISignal)_Default[3]).getSignalsToObj(signals) != 0)
                {
                    return(2);
                }

                short[][] medianData = null;
                if (((ISignal)_Default[4]).getSignalsToObj(signals) == 0)
                {
                    SCPSection5 median = (SCPSection5)_Default[5];

                    if (median == null)
                    {
                        return(4);
                    }

                    medianData = median.DecodeData((SCPSection2)_Default[2], signals.MedianLength);

                    signals.MedianAVM = median.getAVM();
                    signals.MedianSamplesPerSecond = median.getSamplesPerSecond();

                    for (int loper = 0; loper < signals.NrLeads; loper++)
                    {
                        signals[loper].Median = medianData[loper];
                    }
                }
                else
                {
                    // this will make sure that Decoding of rhythm data will work also for strange files
                    signals.MedianAVM              = 0;
                    signals.MedianLength           = 0;
                    signals.MedianSamplesPerSecond = 0;
                }

                SCPSection6 rhythm     = (SCPSection6)_Default[6];
                short[][]   rhythmData = rhythm.DecodeData((SCPSection2)_Default[2], (SCPSection3)_Default[3], (SCPSection4)_Default[4], signals.MedianSamplesPerSecond);
                signals.RhythmAVM = rhythm.getAVM();

                if (rhythmData == null)
                {
                    return(8);
                }

                if ((medianData != null) &&
                    (((SCPSection3)_Default[3]).isMediansUsed()))
                {
                    // check this because corpuls ECG are in violation of this rule, but don't use median subtraction
                    if (((signals.MedianSamplesPerSecond % signals.RhythmSamplesPerSecond) != 0) ||
                        ((signals.MedianSamplesPerSecond / signals.RhythmSamplesPerSecond) < 1) ||
                        ((signals.MedianSamplesPerSecond / signals.RhythmSamplesPerSecond) > 4))
                    {
                        return(16);
                    }

                    if (signals.RhythmAVM <= signals.MedianAVM)
                    {
                        ECGTool.ChangeMultiplier(medianData, signals.MedianAVM, signals.RhythmAVM);
                        signals.MedianAVM = signals.RhythmAVM;
                    }
                    else
                    {
                        ECGTool.ChangeMultiplier(rhythmData, signals.RhythmAVM, signals.MedianAVM);
                        signals.RhythmAVM = signals.MedianAVM;
                    }

                    signals.RhythmSamplesPerSecond = signals.MedianSamplesPerSecond;

                    ((SCPSection4)_Default[4]).AddMedians((SCPSection3)_Default[3], rhythmData, medianData);
                }
                else
                {
                    signals.RhythmAVM = rhythm.getAVM();
                    signals.RhythmSamplesPerSecond = rhythm.getSamplesPerSecond();

                    // Begin: special correction for SCP-ECG by corpuls (part 2)
                    if ((_Default[5] != null) &&
                        _Default[5].Works())
                    {
                        SCPSection5 medianSpecial = (SCPSection5)_Default[5];

                        signals.MedianLength           = 1000;
                        signals.MedianAVM              = medianSpecial.getAVM();
                        signals.MedianSamplesPerSecond = medianSpecial.getSamplesPerSecond();

                        medianData = medianSpecial.DecodeData((SCPSection2)_Default[2], signals.MedianLength);

                        if (medianData != null)
                        {
                            for (int loper = 0; loper < signals.NrLeads; loper++)
                            {
                                signals[loper].Median = medianData[loper];
                            }
                        }
                        else
                        {
                            signals.MedianLength           = 0;
                            signals.MedianAVM              = 0;
                            signals.MedianSamplesPerSecond = 0;
                        }
                    }
                    // End: special correction for SCP-ECG by corpuls (part 2)
                }

                for (int loper = 0; loper < signals.NrLeads; loper++)
                {
                    signals[loper].Rhythm = rhythmData[loper];
                }

                return(0);
            }
            return(1);
        }
コード例 #3
0
ファイル: SCPFormat.cs プロジェクト: zxy30/ECGToolkit
        public int setSignals(Signals signals)
        {
            if ((signals != null) &&
                (signals.NrLeads > 0))
            {
                // Decide wich encoding to use.
                switch (_EncodingType)
                {
                case EncodingType.None:
                    ((SCPSection2)_Default[2]).UseNoHuffman();
                    break;

                case EncodingType.OptimizedHuffman:
                    // not implemented!
                    ((SCPSection2)_Default[2]).UseStandard();
                    break;

                case EncodingType.DefaultHuffman:
                default:
                    ((SCPSection2)_Default[2]).UseStandard();
                    break;
                }

                if (((ISignal)_Default[3]).setSignals(signals) != 0)
                {
                    return(2);
                }

                SCPSection5 median = (SCPSection5)_Default[5];
                median.setAVM(signals.MedianAVM);
                median.setSamplesPerSecond(signals.MedianSamplesPerSecond);

                SCPSection6 rhythm = (SCPSection6)_Default[6];
                rhythm.setAVM(signals.RhythmAVM);
                rhythm.setSamplesPerSecond(signals.RhythmSamplesPerSecond);

                short[][] rhythmData = new short[signals.NrLeads][];
                short[][] medianData = new short[signals.NrLeads][];
                for (int loper = 0; loper < signals.NrLeads; loper++)
                {
                    if (signals[loper].Rhythm == null)
                    {
                        return(4);
                    }
                    rhythmData[loper] = signals[loper].Rhythm;
                    if ((medianData == null) ||
                        (signals[loper].Median == null))
                    {
                        medianData = null;
                    }
                    else
                    {
                        medianData[loper] = signals[loper].Median;
                    }
                }

                if (medianData != null)
                {
                    if (((ISignal)_Default[4]).setSignals(signals) != 0)
                    {
                        return(8);
                    }

                    if (signals.MedianSamplesPerSecond < signals.RhythmSamplesPerSecond)
                    {
                        median.setSamplesPerSecond(signals.RhythmSamplesPerSecond);
                        ECGTool.ResampleSignal(medianData, signals.MedianSamplesPerSecond, signals.RhythmSamplesPerSecond, out medianData);
                    }

                    if (median.EncodeData(medianData, (SCPSection2)_Default[2], (ushort)((signals.MedianLength * signals.MedianSamplesPerSecond) / 1000), (_EncodingType == EncodingType.None ? (byte)0 : _DifferenceDataSection5Used)) != 0)
                    {
                        return(16);
                    }

                    if (signals.QRSZone != null)
                    {
                        if (signals.RhythmAVM <= signals.MedianAVM)
                        {
                            ECGTool.ChangeMultiplier(medianData, signals.MedianAVM, signals.RhythmAVM);
                        }
                        else
                        {
                            ECGTool.ChangeMultiplier(rhythmData, signals.RhythmAVM, signals.MedianAVM);
                            rhythm.setAVM(signals.MedianAVM);
                        }
                    }

                    ECGTool.ResampleSignal(rhythmData, signals.RhythmSamplesPerSecond, median.getSamplesPerSecond(), out rhythmData);

                    if (_QRSSubtractionSupport &&
                        (signals.QRSZone != null))
                    {
                        ((SCPSection3)_Default[3]).setMediansUsed(true);
                        ((SCPSection4)_Default[4]).SubtractMedians((SCPSection3)_Default[3], rhythmData, medianData);
                    }
                }

                if (_BimodalCompressionUsed &&
                    (_BimodalCompressionRate > 0) &&
                    (medianData != null) &&
                    (signals.QRSZone != null))
                {
                    // Bimodal Compression must be set in set section 6.
                    rhythm.setBimodal(true);
                    rhythm.setSamplesPerSecond(signals.MedianSamplesPerSecond / _BimodalCompressionRate);

                    // Determine QRS zones for bimodal compression
                    GlobalMeasurements global;
                    ((IGlobalMeasurement)_Default[7]).getGlobalMeasurements(out global);
                    ((SCPSection4)_Default[4]).setProtected(global, median.getSamplesPerSecond(), _BimodalCompressionRate, ((SCPSection3)_Default[3]).getMinBegin(), ((SCPSection3)_Default[3]).getMaxEnd());
                }

                if (rhythm.EncodeData(rhythmData, (SCPSection2)_Default[2], (SCPSection3)_Default[3], (SCPSection4)_Default[4], signals.MedianSamplesPerSecond, (_EncodingType == EncodingType.None ? (byte)0 : _DifferenceDataSection6Used)) != 0)
                {
                    return(32);
                }
                return(0);
            }
            return(1);
        }
コード例 #4
0
        public int setSignals(Signals signals)
        {
            if ((signals != null) &&
                (signals.NrLeads != 0) &&
                (signals.RhythmAVM > 0) &&
                (signals.RhythmSamplesPerSecond > 0))
            {
                if (_DummyHeader.setSignals(signals) != 0)
                {
                    return(2);
                }

                // Determine minimum start.
                int minstart = int.MaxValue;
                for (int lead = 0; lead < signals.NrLeads; lead++)
                {
                    if (signals[lead] != null)
                    {
                        minstart = Math.Min(minstart, signals[lead].RhythmStart);
                    }
                }

                int samplesBeforeResample = (int)(_DummyHeader.getNrSamplesPerLead() * signals.RhythmSamplesPerSecond) / 500;

                short[] position = new short[NeededLeads.Length];
                for (int find = 0; find < NeededLeads.Length; find++)
                {
                    int p = 0;
                    for (; p < signals.NrLeads; p++)
                    {
                        if ((signals[p] != null) &&
                            (signals[p].Type == NeededLeads[find]) &&
                            (signals[p].Rhythm != null))
                        {
                            break;
                        }
                    }
                    if (p == signals.NrLeads)
                    {
                        p = -1;
                    }
                    position[find] = (short)p;
                }

                short[][] data = new short[_DummyHeader.getNrLeads()][];
                for (int lead = 0; lead < _DummyHeader.getNrLeads(); lead++)
                {
                    if (position[lead] != -1)
                    {
                        data[lead] = new short[samplesBeforeResample];
                        for (int sample = signals[position[lead]].RhythmStart; sample < signals[position[lead]].RhythmEnd; sample++)
                        {
                            data[lead][sample - minstart] = signals[position[lead]].Rhythm[sample - signals[position[lead]].RhythmStart];
                        }
                    }
                }


                for (int lead = 0; lead < _DummyHeader.getNrLeads(); lead++)
                {
                    if (data[lead] == null)
                    {
                        if ((NeededLeads[lead] == LeadType.III) &&
                            (data[6] != null) &&
                            (data[7] != null))
                        {
                            data[lead] = ECGTool.CalculateLeadIII(data[6], 0, data[6].Length, data[7], 0, data[7].Length, data[6].Length);
                        }
                        else
                        {
                            return(4);
                        }
                    }
                }

                ECGTool.ResampleSignal(data, samplesBeforeResample, signals.RhythmSamplesPerSecond, 500, out data);
                ECGTool.ChangeMultiplier(data, signals.RhythmAVM, 2.5);

                if (_Data.Encode(data, (int)_DummyHeader.getNrSamplesPerLead()) != 0)
                {
                    return(8);
                }

                return(0);
            }
            return(1);
        }