Ejemplo n.º 1
0
        private float[] ReadSignalFile(string fileName)
        {
            var signalSamples = new List <float>();

            if (File.Exists(fileName))
            {
                string ext = Path.GetExtension(fileName).Replace(".", "");

                if (ext.ToUpper() == "CSV" || ext.ToUpper() == "TXT")
                {
                    using (var reader = new StreamReader(fileName)) {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            float sample;
                            if (float.TryParse(line, out sample))
                            {
                                signalSamples.Add(sample);
                            }
                        }
                    }
                }

                if (ext.ToUpper() == "EDF")
                {
                    var edfFile = new EDFFile();
                    edfFile.Open(fileName);
                    if (edfFile.Signals.Length >= 1)
                    {
                        for (int i = 0; i < edfFile.Signals[0].Samples.Length; i++)
                        {
                            //NOTE: Resolution may be different for each ECG sensor
                            float resolution = 1.8f;
                            var   sample     = edfFile.Signals[0].Samples[i] * resolution;
                            signalSamples.Add(sample);
                        }
                    }
                }
            }

            return(signalSamples.ToArray());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Example1_Create_And_Save_EDF();

            //if(args.Length >= 1)
            //Example2_Read_EDF_From_Base64(args[0]);

            // Read and dump some data

            if (args.Count() == 0)
            {
                Console.WriteLine("Error: Expecting path to folder as argument!");
                // Exit code?
                return;
            }

            string        filepath = args[0];
            DirectoryInfo d        = new DirectoryInfo(filepath);

            foreach (FileInfo fileInfo in d.GetFiles("*.edf"))
            {
                Console.WriteLine("======== EDF: " + fileInfo.Name + "========");

                DateTime mark = DateTime.Now;
                //

                EDFFile edf         = null;
                int     signalIndex = -1;

                if (args.Count() == 1)
                {
                    // No signal index specified, read the whole file
                    edf = new EDFFile(fileInfo.FullName);
                }
                else
                {
                    // Signal specified, just read that one signal
                    using (edf = new EDFFile())
                    {
                        edf.Open(fileInfo.FullName);
                        // Read specified signals
                        for (int i = 1; i < args.Count(); i++)
                        {
                            Console.WriteLine("Reading signal: " + args[i]);
                            EDF.Signal signal = edf.ReadSignal(args[i]);
                            if (signal == null)
                            {
                                Console.WriteLine("ERROR: Signal " + args[i] + " not found");
                            }
                        }
                    }
                }


                // Print loading time
                TimeSpan runTime = DateTime.Now - mark;
                Console.WriteLine("Load time: " + runTime.TotalSeconds.ToString("0.00") + " s");

                // Print headers
                Console.WriteLine(edf.Header.ToString());

                // Print signals intro
                if (signalIndex < 0)
                {
                    // Print all signal
                    foreach (EDF.Signal s in edf.Signals)
                    {
                        Console.WriteLine(s.ToString());
                    }
                }
                else
                {
                    // Print the signal we loaded
                    Console.WriteLine(edf.Signals[signalIndex].ToString());
                }


                Console.WriteLine("=========================================\n");


                //Console.WriteLine("Scaled sample test: " + edf.Signals[31].ScaledSample(0));

                //TODO: Test saving files, I guess we would need to fix recording writing function
            }



            Console.ReadLine();
        }