private static void Example2_Read_EDF_From_Base64(string edfBase64FilePath) { var edfBase64 = File.ReadAllText(edfBase64FilePath); var edfFile = new EDFFile(); edfFile.ReadBase64(edfBase64); edfFile.Save(@"C:\temp\edf_bytes.edf"); }
public void Test_WriteReadEDF_ShouldReturnSameData() { //Write an EDF file with two signals then read it and check the data is correct var edf1 = new EDFFile(); var ecgSig = new Signal(); ecgSig.Label.Value = "ECG"; ecgSig.SampleCountPerRecord.Value = 10; //Small number of samples for testing ecgSig.PhysicalDimension.Value = "mV"; ecgSig.DigitalMinimum.Value = -2048; ecgSig.DigitalMaximum.Value = 2047; ecgSig.PhysicalMinimum.Value = -10.2325; ecgSig.PhysicalMaximum.Value = 10.2325; ecgSig.TransducerType.Value = "UNKNOWN"; ecgSig.Prefiltering.Value = "UNKNOWN"; ecgSig.Reserved.Value = "RESERVED"; ecgSig.Samples = new List <short> { 100, 50, 23, 75, 12, 88, 73, 12, 34, 83 }; var soundSig = new Signal(); soundSig.Label.Value = "SOUND"; soundSig.SampleCountPerRecord.Value = 10;//Small number of samples for testing soundSig.PhysicalDimension.Value = "mV"; soundSig.DigitalMinimum.Value = -2048; soundSig.DigitalMaximum.Value = 2047; soundSig.PhysicalMinimum.Value = -44; soundSig.PhysicalMaximum.Value = 44.0; soundSig.TransducerType.Value = "UNKNOWN"; soundSig.Prefiltering.Value = "UNKNOWN"; soundSig.Samples = new List <short> { 11, 200, 300, 123, 87, 204, 145, 234, 222, 75 }; soundSig.Reserved.Value = "RESERVED"; edf1.Signals = new Signal[2] { ecgSig, soundSig }; var h = new Header(); h.RecordDurationInSeconds.Value = 1; h.Version.Value = "0"; h.PatientID.Value = "TEST PATIENT ID"; h.RecordID.Value = "TEST RECORD ID"; h.RecordingStartDate.Value = "11.11.16"; //dd.mm.yy h.RecordingStartTime.Value = "12.12.12"; //hh.mm.ss h.Reserved.Value = "RESERVED"; h.RecordCount.Value = 1; h.SignalCount.Value = (short)edf1.Signals.Length; h.Signals.Reserveds.Value = Enumerable.Repeat("RESERVED".PadRight(32, ' '), h.SignalCount.Value).ToArray(); edf1.Header = h; string edfFilePath = @"C:\temp\test1.EDF"; edf1.Save(edfFilePath); //Read the file back var edf2 = new EDFFile(edfFilePath); Assert.AreEqual(edf2.Header.Version.ToAscii(), edf1.Header.Version.ToAscii()); Assert.AreEqual(edf2.Header.PatientID.ToAscii(), edf1.Header.PatientID.ToAscii()); Assert.AreEqual(edf2.Header.RecordID.ToAscii(), edf1.Header.RecordID.ToAscii()); Assert.AreEqual(edf2.Header.RecordingStartDate.ToAscii(), edf1.Header.RecordingStartDate.ToAscii()); Assert.AreEqual(edf2.Header.RecordingStartTime.ToAscii(), edf1.Header.RecordingStartTime.ToAscii()); Assert.AreEqual(edf2.Header.Reserved.ToAscii(), edf1.Header.Reserved.ToAscii()); Assert.AreEqual(edf2.Header.RecordCount.ToAscii(), edf1.Header.RecordCount.ToAscii()); Assert.AreEqual(edf2.Header.SignalCount.ToAscii(), edf1.Header.SignalCount.ToAscii()); Assert.AreEqual(edf2.Header.Signals.Reserveds.ToAscii(), edf1.Header.Signals.Reserveds.ToAscii()); Assert.AreEqual(edf2.Signals[0].Samples.Count, edf1.Signals[0].Samples.Count); }
private static void Example1_Create_And_Save_EDF() { //Crreate an empty EDF file var edfFile = new EDFFile(); //Create a signal object var ecgSig = new EDFSignal(); ecgSig.Label.Value = "ECG"; ecgSig.NumberOfSamples.Value = 10; ecgSig.PhysicalDimension.Value = "mV"; ecgSig.DigitalMinimum.Value = -2048; ecgSig.DigitalMaximum.Value = 2047; ecgSig.PhysicalMinimum.Value = -10.2325; ecgSig.PhysicalMaximum.Value = 10.2325; ecgSig.TransducerType.Value = "UNKNOWN"; ecgSig.Prefiltering.Value = "UNKNOWN"; ecgSig.Reserved.Value = "RESERVED"; ecgSig.Samples = new short[] { 100, 50, 23, 75, 12, 88, 73, 12, 34, 83 }; //Set the signal edfFile.Signals = new EDFSignal[1] { ecgSig }; //Create the header object var h = new EDFHeader(); h.DurationOfDataRecord.Value = 1; h.Version.Value = "0"; h.PatientID.Value = "TEST PATIENT ID"; h.RecordID.Value = "TEST RECORD ID"; h.StartDate.Value = "11.11.16"; //dd.mm.yy h.StartTime.Value = "12.12.12"; //hh.mm.ss h.Reserved.Value = "RESERVED"; h.NumberOfDataRecords.Value = 1; h.NumberOfSignals.Value = (short)edfFile.Signals.Length; h.SignalsReserved.Value = Enumerable.Repeat("RESERVED".PadRight(32, ' '), h.NumberOfSignals.Value).ToArray(); //Set the header edfFile.Header = h; //Print some info Console.Write( "\nPatient ID:\t\t" + edfFile.Header.PatientID.Value + "\nNumber of signals:\t" + edfFile.Header.NumberOfSignals.Value + "\nStart date:\t\t" + edfFile.Header.StartDate.Value + "\nSignal label:\t\t" + edfFile.Signals[0].Label.Value + "\nSignal samples:\t\t" + String.Join(",", edfFile.Signals[0].Samples.Skip(0).Take(10).ToArray()) + "\n\n" ); //Save the file string fileName = @"C:\temp\example.edf"; edfFile.Save(fileName); //Read the file var f = new EDFFile(fileName); Console.ReadLine(); }