Ejemplo n.º 1
0
        public void LoadSignal()
        {
            lastTime    = 0;
            inputBuffer = new InputBuffer();
            // Open the file dialog to show the file
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt = ".txt";                                            // Default file extension
            dlg.Filter     = "MIT Arrhythmia File (*.txt, *.dat)|*.txt; *.dat"; // Filter files by extension
            dlg.Title      = "Select PhysioBank MIT-BIH Arrhytmia Signal";


            // Show open file dialog box
            bool result = (bool)dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Get file informations
                string filePath      = dlg.FileName;
                string fileName      = System.IO.Path.GetFileName(filePath);
                string fileExtension = System.IO.Path.GetExtension(filePath);
                string directoryPath = System.IO.Path.GetDirectoryName(filePath);
                string headerFile    = directoryPath + "\\" + fileName.Remove(fileName.IndexOf('.'), fileName.Length - fileName.IndexOf('.')) + ".hea";

                /* u svrhe testiranja
                 * InputBuffer ib1 = new InputBuffer();
                 * ib1.Open(filePath, 1, FileType.BINARY);
                 * for (int i = 0; i < 20; i++)
                 *  MessageBox.Show(ib1.ReadOne().ToString());*/


                // Determine file type
                FileType type = FileType.BINARY;
                if (fileExtension == ".txt" || fileExtension == ".TXT")
                {
                    type = FileType.TEXT;
                }



                // Open the buffer

                if (inputBuffer.prepareBinaryInfo(filePath))
                {
                    InputDataProperties iba = new InputDataProperties(inputBuffer.recDescription);
                    iba.ShowDialog();
                    if (iba.fc)
                    {
                        try
                        {
                            short channelForm = Convert.ToInt16(iba.channelToRead);
                            inputBuffer.Open(filePath, channelForm, type);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("Error opening record file");
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }



            // Init timer
            dispatcherTimer       = new DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            //dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, (int)TimeSpan.FromSeconds(1.0/F).TotalMilliseconds);


            // Init plot
            PlotModel model = new PlotModel {
                Title = "EKG Signal"
            };

            lineSeries = new OxyPlot.Series.LineSeries();
            model.Series.Add(lineSeries);

            linearAxisY                    = new LinearAxis();
            linearAxisY.MajorStep          = 0.5;
            linearAxisY.MinorStep          = 0.1;
            linearAxisY.MajorGridlineStyle = LineStyle.Solid;
            linearAxisY.MinorGridlineStyle = LineStyle.Dot;
            linearAxisY.Title              = "Voltage";
            linearAxisY.Unit               = "mV";
            linearAxisY.IsPanEnabled       = false;
            linearAxisY.IsZoomEnabled      = false;

            model.Axes.Add(linearAxisY);

            linearAxisX                    = new LinearAxis();
            linearAxisX.MajorStep          = 0.2;
            linearAxisX.MinorStep          = 0.04;
            linearAxisX.MajorGridlineStyle = LineStyle.Solid;
            linearAxisX.MinorGridlineStyle = LineStyle.Dot;
            linearAxisX.Position           = AxisPosition.Bottom;
            linearAxisX.Title              = "Time";
            linearAxisX.Unit               = "s";
            linearAxisX.IsPanEnabled       = false;
            linearAxisX.IsZoomEnabled      = false;

            model.Axes.Add(linearAxisX);


            MainWindow.Instance.EKG_Plot.Model = model;
        }
Ejemplo n.º 2
0
 public abstract void read(InputBuffer ib, int channel);
Ejemplo n.º 3
0
        public override void read(InputBuffer ib, int channel)
        {
            long fileLength = 0;

            try
            {
                file   = new FileStream(filename, FileMode.Open);
                reader = new BinaryReader(file);
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.ToString());
            }
            decimal timeStep = 1 / samplingFrequency;


            fileLength = file.Length;
            short flag = 0;
            Int64 low = 0, high = 0;

            byte[] buf = new byte[] { 0, 0, 0 };
            for (int i = 0; i < fileLength / 3; i++)
            {
                for (short j = 1; j <= 2; j++)
                {
                    switch (flag)
                    {
                    case 0:
                        try
                        {
                            buf = reader.ReadBytes(3);
                        }
                        catch (Exception e2)
                        {
                            return;
                        }
                        low  = buf[1] & 0x0F;
                        high = buf[1] & 0xF0;
                        if (channel == j)
                        {
                            if (low > 7)
                            {
                                while (!ib.Write(sampleNum * timeStep, convertValue(buf[0] + (low << 8) - 4096, zeroADC, channelGain)))
                                {
                                    ;
                                }
                            }
                            else
                            {
                                while (!ib.Write(sampleNum * timeStep, convertValue((buf[0] + (low << 8)), zeroADC, channelGain)))
                                {
                                    ;
                                }
                            }
                        }
                        flag = 1;
                        break;

                    case 1:
                        if (channel == j)
                        {
                            if (high > 127)
                            {
                                while (!ib.Write(sampleNum * timeStep, convertValue(buf[2] + (high << 4) - 4096, zeroADC, channelGain)))
                                {
                                    ;
                                }
                            }
                            else
                            {
                                while (!ib.Write(sampleNum * timeStep, convertValue((buf[2] + (high << 4)), zeroADC, channelGain)))
                                {
                                    ;
                                }
                            }
                        }
                        flag = 0;
                        break;
                    }
                }
            }
            stop();
        }