Class SCPECG


  • public class SCPECG
    extends java.lang.Object

    A class to encapsulate an entire SCP-ECG object.

    Typically this class would be used to read an SCP-ECG object from a file, and to do something with the decompressed waveform data values. For example:

    try {                   
            BinaryInputStream i = new BinaryInputStream(new BufferedInputStream(new FileInputStream(arg[0])),false);        // always little endian
            SCPECG scpecg = new SCPECG(i,verbose);
            short[][] data = scpecg.getDecompressedRhythmData();
            BinaryOutputStream o = new BinaryOutputStream(new BufferedOutputStream(new FileOutputStream(arg[1])),false);    // little endian
            // write interleaved raw little endian data
            int numberOfChannels = data.length;
            int nSamplesPerChannel = data[0].length;        // assume all the same
            for (int sample=0; sample<nSamplesPerChannel; ++sample) {
                    for (int lead=0;lead<numberOfChannels; ++lead) {
                            o.writeSigned16(data[lead][sample]);
                    }
            }
            o.close();
    }
    catch (Exception e) {
            e.printStackTrace(System.err);
    }
     

    One might want to dump the entire contents of the instance as a string, as follows:

    System.err.print(scpecg);
     

    or perhaps to display the contents as a JTree:

    ApplicationFrame af = new ApplicationFrame();
    JScrollPane scrollPane = new JScrollPane();
    SCPTreeBrowser browser = new SCPTreeBrowser(scpecg,scrollPane);
    af.getContentPane().add(scrollPane);
    af.pack();
    af.setVisible(true);
     
    • Constructor Detail

      • SCPECG

        public SCPECG​(BinaryInputStream i,
                      boolean verbose)
               throws java.io.IOException

        Read an SCP-ECG object from an input stream.

        As errors are encountered, they are described on stderr.

        The sections are also validated as they are read, and Section 0 is validated against the other sections.

        Parameters:
        i - the input stream (should have been opened as little endian)
        verbose - if true, then the progress of the read is described
        Throws:
        java.io.IOException
    • Method Detail

      • getDecompressedRhythmData

        public short[][] getDecompressedRhythmData()

        Get the decompressed rhythm data.

        This includes undecimating and adding in any reference beat.

        Note that interpolation and filtering are NOT applied in the current implementation.

        Returns:
        arrays of samples for each lead
      • getDecompressedReferenceBeatData

        public short[][] getDecompressedReferenceBeatData()

        Get the decompressed reference beat data.

        Returns:
        arrays of samples for each lead
      • toString

        public java.lang.String toString()

        Dump the object as a String.

        Overrides:
        toString in class java.lang.Object
        Returns:
        the object as a String
      • getSection1

        public Section1 getSection1()
      • getSection2

        public Section2 getSection2()
      • getSection3

        public Section3 getSection3()
      • getSection4

        public Section4 getSection4()
      • getSection7

        public Section7 getSection7()
      • getSection10

        public Section10 getSection10()
      • getNumberOfLeads

        public int getNumberOfLeads()

        Get the number of leads.

        Returns:
        the number of leads
      • getNumbersOfSamples

        public long[] getNumbersOfSamples()

        Get the number of samples for each lead.

        Returns:
        an array of the number of samples for each lead
      • getDecompressedRhythmDataSampleTimeInterval

        public int getDecompressedRhythmDataSampleTimeInterval()

        Get the sample time interval that will be applicable to the decompressed rhythm data.

        Note that this is the value after undecimation if the rhythm data was decimated; specifically in such cases it will be the sample time interval of the reference beat.

        Returns:
        the sample time interval in microSeconds
      • getNamedField

        public java.lang.String getNamedField​(java.lang.String fieldName)

        Get the concatenated values of all the occurences of a named field from Section 1 as a String.

        Returns:
        the values as a String
      • getLeadNames

        public java.lang.String[] getLeadNames()

        Get the names of the leads from Section 3.

        Returns:
        the names of the leads
      • getLeadNumbers

        public int[] getLeadNumbers()

        Get the numbers of the leads from Section 3.

        Returns:
        the numbers of the leads (using the codes in the standard and encoded in the data)
      • getSectionIterator

        public java.util.Iterator getSectionIterator()

        Get an Iterator over all the sections.

        Returns:
        an iterator of objects of type Section
      • main

        public static void main​(java.lang.String[] arg)

        For testing.

        Parameters:
        arg - one, two or three arguments, the input filename, optionally a output raw data filename, and optionally a text dump filename