# ECGtask

Perform an specific task to an ECG signal. This document defines the standard interface that tasks must implement.

## Description

The ECGtask is an abstract class definition where the minimum interface requirements are specified, in order that your own tasks can be safely plugged into ECGwrapper objects. As an example of how to use this interface, see the derived classes for QRS detection and ECG delineation, among others that can be listed with the list_all_ECGtask function:

- QRS detection
- QRS correction
- ECG delineation
- ECG delineation correction
- ABP/PPG peak detection
- ABP/PPG peak correction
- Heartbeat classification
- Arbitrary tasks

These tasks are the core of this kit and you will probably refer to them before you extend the functionality with your own tasks.

## Properties

All tasks must implement the following properties with its attributes:

    properties(GetAccess = public, Constant)

`name` — The name of the task.

`target_units` — The signal units required by the task. Possible values are:

> ADCu, raw ADC samples.

> nV, uV, mV, V, voltage.

`doPayload` — Boolean. Does this task generates a payload to be stored ?

    properties(GetAccess = public, SetAccess = private)

`memory_constant` — A coefficient to indicate the ECGwrapper how big should be a batch processing part. The size of each part is calculated as

    user = memory;
    batch_size = memory_constant * user.MaxPossibleArrayBytes;

`started` — Boolean. Did the task executed the Start method ?

    properties(GetAccess = public, SetAccess = public)

`progress_handle` — is a handle to a progress_bar object, that can be used to track the progress within your function.

`tmp_path` — The path to store temporary data.

## Methods

All tasks must implement the following methods:

`Start` — The task initialization method.

This task initialize specific aspects of the task.

    Start(obj, ECG_header, ECG_annotations)

where the arguments are:

> ECG_header, is a struct with info about the ECG signal, See here for a description.

> ECG_annotations, Commonly QRS detections, signal quality annotations or other type of measurements included with the recordings. Some documentation about annotations in Physionet.

`Process` — The task core processing function.

This task is the responsible of do the actual work of the ECGtask. This mehtod is called by an ECGwrapper all the times needed to process the whole recording.

    payload = Process(ECG,
                      ECG_start_offset,
                      ECG_sample_start_end_idx,
                      ECG_header,
                      ECG_annotations,
                      ECG_annotations_start_end_idx )

where the arguments are:

> ECG, is a matrix size `[ECG_header.nsamp ECG_header.nsig]`

> ECG_start_offset, is the location of ECG(1,:) within the whole signal.

> ECG_header, is a struct with info about the ECG signal, See here for a description.

> ECG_annotations, Commonly QRS detections, signal quality annotations or other type of measurements included with the recordings. Some documentation about annotations in Physionet.

> ECG_annotations_start_end_idx, are the start and end indexes corresponding to the first and last element of ECG_annotations in the current iteration.

as a result, this method must produce a payload variable, that will be handled by the ECGwrapper object.

`Concatenate` — This method is responsible of the payload union after all the processing.

After the execution of all Process steps, each payload must be put together with this method. The ECGwrapper object will call this method once for each payload created, building a final payload.

    payload = Concatenate(plA, plB)

where the arguments are:

> plA and plB, are two payloads created with the Process method.

and as a result, this method creates payload, the union of plA and plB.

`Finish` — This task perform the last calculation over the whole payload.

After the concatenation of payloads, the whole payload is sent to this method to perform any final calculation.

    payload = Finish(obj, payload, ECG_header)

where the arguments are:

> payload, is the payload created with all the Concatenate method invocation.

> ECG_header, is a struct with info about the ECG signal, See here for a description.

As a result, the final payload is generated, which later will be stored by the ECGwrapper object.

## More About

- Physionet.org
- Telemetric and Holter ECG Warehouse (THEW)
- Pablo Laguna research group at University of Zaragoza
- Computing in Cardiology

## See Also

ECGwrapper | ECG_delineation | list_all_ECGtask