Пример #1
0
        static private ECG loadECGFromSignalTextFile(String signalFileName, int channelToLoad = 1)
        {
            String          signal       = signalFileName.Substring(0, signalFileName.Length - 4);
            FileStream      file         = new FileStream(signal + ".txt", FileMode.Open);
            StreamReader    streamReader = new StreamReader(file);
            List <ECGPoint> ecgPoints    = new List <ECGPoint>();
            string          line         = "";

            line = streamReader.ReadLine();
            int count = 0;

            while (!(line.Contains("0.000")))
            {
                if (line == null)
                {
                    break;
                }
                try
                {
                    line = streamReader.ReadLine();
                }
                catch (Exception)
                {
                    Console.WriteLine(ecgPoints.ToString());
                }
            }

            do
            {
                ECGPoint ecgPoint = new ECGPoint();
                ecgPoint.Value     = (double.Parse(line.Split('\t')[channelToLoad]));
                ecgPoint.TimeIndex = count / Convert.ToDouble(Frequency);
                ecgPoints.Add(ecgPoint);
            } while ((line = streamReader.ReadLine()) != null);
            file.Close();
            streamReader.Close();
            ECG ecg = new ECG();

            ecg.Name         = signalFileName;
            ecg.Points       = ecgPoints;
            ecg.SamplingRate = Frequency;
            ecg.Channel      = channelToLoad;
            return(ecg);
        }
Пример #2
0
        static private ECG loadECGFromSignalBinaryFile(String signalFileName, int channelToLoad = 1)
        {
            String          signal = signalFileName.Substring(0, signalFileName.Length - 4);
            FileStream      file = new FileStream(signal + ".dat", FileMode.Open);
            BinaryReader    binReader = new BinaryReader(file);
            List <ECGPoint> ecgPoints = new List <ECGPoint>();
            int             count = 0;
            short           flag = 0;
            long            low = 0, high = 0;

            byte[] buf = { 0, 0, 0 };

            for (int i = 0; i < file.Length / 3; i++)
            {
                for (short j = 1; j <= 2; j++)
                {
                    count++;
                    switch (flag)
                    {
                    case 0:
                        try
                        {
                            buf = binReader.ReadBytes(3);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        low  = buf[1] & 0x0F;
                        high = buf[1] & 0xF0;
                        if (channelToLoad == j)
                        {
                            if (low > 7)
                            {
                                ECGPoint ecgPoint = new ECGPoint();
                                ecgPoint.TimeIndex = count / Convert.ToDouble(Frequency);
                                ecgPoint.Value     = Convert.ToDouble(buf[0] + (low << 8) - 4096);
                                ecgPoints.Add(ecgPoint);
                            }
                            else
                            {
                                ECGPoint ecgPoint = new ECGPoint();
                                ecgPoint.TimeIndex = count / Convert.ToDouble(Frequency);
                                ecgPoint.Value     = Convert.ToDouble((buf[0] + (low << 8) - 1024) * 0.005);
                                ecgPoints.Add(ecgPoint);
                            }
                        }
                        flag = 1;
                        break;

                    case 1:
                        if (channelToLoad == j)
                        {
                            if (high > 127)
                            {
                                ECGPoint ecgPoint = new ECGPoint();
                                ecgPoint.TimeIndex = count / Convert.ToDouble(Frequency);
                                ecgPoint.Value     = Convert.ToDouble(buf[2] + (high << 4) - 4096);
                                ecgPoints.Add(ecgPoint);
                            }
                            else
                            {
                                ECGPoint ecgPoint = new ECGPoint();
                                ecgPoint.TimeIndex = count / Convert.ToDouble(Frequency);
                                ecgPoint.Value     = Convert.ToDouble((buf[2] + (high << 4) - 1024) * 0.005);
                                ecgPoints.Add(ecgPoint);
                            }
                        }
                        flag = 0;
                        break;
                    }
                }
            }
            file.Close();
            binReader.Close();
            ECG ecg = new ECG();

            ecg.Name         = signalFileName;
            ecg.Points       = ecgPoints;
            ecg.SamplingRate = Frequency;
            ecg.Channel      = channelToLoad;
            return(ecg);
            // look for HEA ATR DAT & CUST on path etc.
        }