I have raw ecg voltage samples in csv format, for example:
time voltage (mV)
0.000 9.169110459
0.001 9.144672532
0.002 9.144672532
0.003 9.169110459
0.004 9.169110459
0.005 9.169110459
0.006 9.169110459
0.007 9.144672532
0.008 9.217986315
0.009 9.169110459
0.01 9.169110459
0.011 9.169110459
0.012 9.169110459
0.013 9.144672532
0.014 9.144672532
0.015 9.169110459
0.016 9.169110459
0.017 9.169110459
0.018 9.169110459
0.019 9.169110459
0.02 9.169110459
0.021 9.169110459
0.022 9.144672532
0.023 9.169110459
and would like to convert it to a DICOM file so that I can view it in an ecg viewer like ECG toolkit for C #: https://sourceforge.net/projects/ecgtoolkit-cs/
How do I go about this transformation? I did some search queries but did not find a tool that is able to write dicom files from raw data.
EDIT:
I ended up working with the SCP file as it was easier. I created the library above to create a scp file. Code below:
using System;
using System.Linq;
using ECGConversion;
using ECGConversion.ECGDemographics;
using ECGConversion.ECGSignals;
namespace SCPWriter
{
public static class CreateScpEcg
{
public static void CreateScpEcgFile(double[] voltages, int sampleRate, string directory, string patientId)
{
var rhythm = voltages;
var filePath = directory + patientId;
IECGFormat format = ECGConverter.Instance.getFormat("SCP-ECG");
if (format != null)
{
format.Demographics.Init();
format.Demographics.PatientID = patientId;
format.Demographics.LastName = "";
format.Demographics.TimeAcquisition = DateTime.Now;
AcquiringDeviceID acqID = new AcquiringDeviceID(true);
Communication.IO.Tools.BytesTool.writeString("MYDEVI", acqID.ModelDescription, 0, acqID.ModelDescription.Length);
format.Demographics.AcqMachineID = acqID;
var leadType = new LeadType[] { LeadType.I };
var rhythmAVM = 1;
var rhythmSPS = sampleRate;
Signals sigs = new Signals((byte)leadType.Length);
sigs.RhythmAVM = rhythmAVM;
sigs.RhythmSamplesPerSecond = rhythmSPS;
for (int i = 0; i < sigs.NrLeads; i++)
{
sigs[i] = new Signal();
sigs[i].Type = leadType[i];
sigs[i].Rhythm = rhythm.Select(Convert.ToInt16).ToArray();
sigs[i].RhythmStart = 0;
sigs[i].RhythmEnd = rhythm.Length - 1;
}
if (format.Signals.setSignals(sigs) != 0)
{
Console.Error.WriteLine("setSignals failed!");
return;
}
var outputFile = filePath + ".scp";
ECGWriter.Write(format, outputFile, true);
if (ECGWriter.getLastError() != 0)
{
Console.Error.WriteLine("Writing failed: {0}!", ECGWriter.getLastErrorMessage());
return;
}
}
}
}
}
NB: I was only interested in "lead I", but you can add more lines to this line: var leadType = new LeadType [] {LeadType.I}
NB: , sourceforge .