waveforms
Waveform data (ECG, hemodynamic, audio and the rest) as structs: a multiplex group of channels with their samples, and simple analysis of a channel.
import "github.com/amrshadid/go-dicom/waveforms" · pkg.go.dev
When to use it
When you read or write the Waveform Sequence (5400,0100). The types here are
what dataset.Dataset.GetWaveforms returns and AddWaveforms takes, and what
filereader.DICOMFile.GetWaveforms returns.
Key types and functions
| Name | What it is for |
|---|---|
WaveformGroup | One multiplex group: channels, samples, frequency, labels, units, [channel][sample] data. |
WaveformChannel | One channel with its minimum, maximum and mean. |
NewWaveformManager, WaveformManager | Groups by index. |
WaveformManager.GetChannels, WaveformManager.GetChannelSegment | A group's channels; a range of samples. |
WaveformManager.AnalyzeChannel | Minimum, maximum and mean of a channel. |
WaveformManager.DetectQRSComplex, WaveformManager.CalculateHeartRate | A threshold QRS detector and the rate from it. |
WaveformManager.ValidateWaveform | Channel and sample counts agree with the data. |
Example
// Put a two-channel waveform into a data set and read it back.
package main
import (
"encoding/binary"
"fmt"
"log"
"math"
"github.com/amrshadid/go-dicom/dataset"
"github.com/amrshadid/go-dicom/waveforms"
)
func main() {
const n = 500 // one second at 500 Hz
lead1, lead2 := make([]int16, n), make([]int16, n)
for i := range n {
lead1[i] = int16(1000 * math.Sin(2*math.Pi*float64(i)/n))
lead2[i] = lead1[i] / 2
}
group := &waveforms.WaveformGroup{
WaveformOriginality: "ORIGINAL",
NumberOfWaveformChannels: 2,
NumberOfSamples: n,
SamplingFrequency: 500,
MultiplexGroupLabel: "RHYTHM",
ChannelLabel: []string{"Lead I", "Lead II"},
WaveformData: [][]int16{lead1, lead2},
SampleInterpretation: "SS",
}
ds := dataset.NewDataset()
if err := ds.AddWaveforms([]*waveforms.WaveformGroup{group}, binary.LittleEndian); err != nil {
log.Fatal(err)
}
groups, err := ds.GetWaveforms(binary.LittleEndian)
if err != nil {
log.Fatal(err)
}
for _, g := range groups {
fmt.Printf("%s: %d channels, %d samples at %g Hz\n",
g.MultiplexGroupLabel, g.NumberOfWaveformChannels, g.NumberOfSamples, g.SamplingFrequency)
for c, samples := range g.WaveformData {
fmt.Printf(" channel %d: sample 125 = %d\n", c+1, samples[125])
}
}
}It builds two channels of a 500 Hz sine, writes them into a data set and reads
them back: RHYTHM: 2 channels, 500 samples at 500 Hz, then sample 125 of
each channel (1000 and 500).
Notes
- Samples are
int16; only 16-bit signed waveform data is modelled. - The QRS detector is a simple threshold, not a clinical algorithm.
Warning
Reading is limited. Channel labels are not read back: a group read from a
data set has labels Channel 1, Channel 2 and so on. On pydicom's
waveform_ecg.dcm, dataset.GetWaveforms returns an error and
filereader.DICOMFile.GetWaveforms returns no groups, although
HasWaveforms is true. Check the result before relying on it.