Exemple #1
0
        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);
        }
Exemple #2
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);
        }