Main Content


Modify annotations in EDF or EDF+ file



    edfw = modifyAnnotations(edfw,annotationindices,tsal) modifies annotations in edfw with the annotations in tsal at the indices specified in annotationindices.


    collapse all

    Load a labeledSignalSet into the workspace. heartrates contains two electrocardiogram (ECG) signals from the MIT-BIH Arrhythmia Database [1] and a labels table for each signal. The sample rate is 250 Hz.

    load HeartRates

    Create an annotations timetable using the label values for the first signal in the labeled signal set.

    labels = getLabelValues(heartrates,1,'QRSregions')
    labels=41×2 table
           ROILimits       Value
        _______________    _____
        0.556     0.724     QRS 
        1.304       1.4     QRS 
         1.82     1.976     QRS 
        2.628     2.724     QRS 
        3.092     3.292     QRS 
        3.916      4.02     QRS 
        4.384     4.564     QRS 
        5.184     5.272     QRS 
        5.668     5.844     QRS 
        6.428     6.516     QRS 
        6.876     7.048     QRS 
        7.688     7.784     QRS 
        8.192     8.416     QRS 
        9.092     9.208     QRS 
        9.592     9.768     QRS 
        10.34    10.428     QRS 
    Onset = seconds(labels.ROILimits(:,1));
    Annotations = string(labels.Value);
    Duration = seconds(labels.ROILimits(:,2) - labels.ROILimits(:,1));
    tsal = timetable(Onset,Annotations,Duration);

    Create a new EDF+ file that contains a header, the first ECG signal in the labeled signal set, and the annotations.

    sig = getSignal(heartrates,1);
    sig = sig.y200;
    hdr = edfheader("EDF+");
    hdr.SignalLabels = "y200";
    hdr.NumDataRecords = 1;
    hdr.PhysicalMin = min(sig);
    hdr.PhysicalMax = max(sig);
    edfw = edfwrite("heartrate1.edf",hdr,sig,tsal,"InputSampleType","physical");

    Modify the annotation at every odd index to "skip". Display the modified annotations in edfw.

    mtsal = tsal(1:2:end,:);
    mtsal.Annotations = repelem("skip",21)';
    idx = 1:2:numel(tsal(:,1));
    edfw = modifyAnnotations(edfw,idx,mtsal);
    ans=41×2 timetable
          Onset      Annotations    Duration 
        _________    ___________    _________
        0.556 sec      "skip"       0.168 sec
        1.304 sec      "QRS"        0.096 sec
        1.82 sec       "skip"       0.156 sec
        2.628 sec      "QRS"        0.096 sec
        3.092 sec      "skip"         0.2 sec
        3.916 sec      "QRS"        0.104 sec
        4.384 sec      "skip"        0.18 sec
        5.184 sec      "QRS"        0.088 sec
        5.668 sec      "skip"       0.176 sec
        6.428 sec      "QRS"        0.088 sec
        6.876 sec      "skip"       0.172 sec
        7.688 sec      "QRS"        0.096 sec
        8.192 sec      "skip"       0.224 sec
        9.092 sec      "QRS"        0.116 sec
        9.592 sec      "skip"       0.176 sec
        10.34 sec      "QRS"        0.088 sec

    Input Arguments

    collapse all

    EDF or EDF+ file, specified as an edfwrite object.

    Annotation indices, specified as a numeric vector. The values in annotationindices must be row indices of the Annotations property.

    Data Types: double

    List of timestamped annotations, specified as a timetable containing these variables:

    • Onset — Time at which the annotation occurred, expressed as a duration indicating the number of seconds elapsed since the start time of the file. Use Onset to specify the RowTimes in the timetable.

    • Annotations — A string that contains the annotation text.

    • Duration — A duration scalar that indicates the duration of the event described by the annotation. If the file does not specify an annotation duration, this variable is returned as NaN.

    The number of rows in tsal must be equal to the number of elements in annotationindices.

    Output Arguments

    collapse all

    EDF or EDF+ file, returned as an edfwrite object.


    [1] Moody, G.B., and R.G. Mark. “The Impact of the MIT-BIH Arrhythmia Database.” IEEE Engineering in Medicine and Biology Magazine 20, no. 3 (June 2001): 45–50.

    [2] Kemp, Bob, Alpo Värri, Agostinho C. Rosa, Kim D. Nielsen, and John Gade. “A Simple Format for Exchange of Digitized Polygraphic Recordings.” Electroencephalography and Clinical Neurophysiology 82, no. 5 (May 1992): 391–93.

    [3] Kemp, Bob, and Jesus Olivan. "European Data Format 'plus' (EDF+), an EDF Alike Standard Format for the Exchange of Physiological Data." Clinical Neurophysiology 114, no. 9 (2003): 1755–1761.

    Version History

    Introduced in R2021a

    See Also




    External Websites