Saturday, November 2, 2013

ECG Viewer

{Under Construction}

 ECG Viewer is a simple MATLAB GUI for reviewing, processing, and annotating electrocardiogram
(ECG) data files. ECG Viewer offers an annotation database, ECG filtering, beat detection using
template matching, and inter-beat interval (IBI or RR) filtering. Program was created using
MATLAB 2008b.

Download ECGViewer from Sourceforge.net here: http://sourceforge.net/projects/ecgviewer/

Shortcut Keys
  Use the up and down arrow keys to jump to the next/previous IBI outlier.
  Use the left and right arrow keys to jump to the next/previous detection.
  You must click on somewhere on the GUI before using the arrow keys.
  Double click on annotations to see more details.
  Double click on file name to load the ECG.
Other
  Use the arrow buttons next to the “preview” button to automatically load the
previous/next ECG data file
  “Start Time” and “Length” options located above the list of ECG files are used to limit
the amount of data loaded from the ECG file. “Start time” represents the beginning
time. “Length” represents the length of data to load in reference to the starting time.
Start time + length = end time.
fdf

ECG Data
As of version 1.1.13, ECG Viewer can read MATLAB binary files (.mat) and ASCII text files (.txt). If using MATLAB binary files (.mat), the software will load the data and then try to find a variable named “ecg” or “ECG”. If not found, the software will use the first variable loaded from the .mat file.
The ECG data is expected to have one or two columns. If one column is used, this column must represent ECG amplitude in arbitrary units. If two columns are used, the first column represents time in units of seconds. The second column represents ECG amplitude in arbitrary units.
ECG Filtering
Two type of ECG filtering are currently available in ECG Viewer.
1. Fast Smooth – Filters ECG base using two moving average filters. User can specify the number of passes from 1x-3x. Low-pass filter (LPF) setting can be adjusted by changing the LPF span. Larger LPF spans eliminate a broader range of high frequency components. High-pass filter (HPF) setting can be adjusted by changing the HPF span. Smaller HPF spans eliminate a broader range of low frequency components. (this need rewording)
2. Wavelet – This filtering method used MATLAB’s wavelet toolbox. The ECG is first decomposition using wavelet decomposition. The user defines the wavelet family to use and the sub-bands (frequency bands) to remove. 
Beat Detection
Beat detection is accomplished using a correlation-based template matching algorithm.  A sliding window is passed across the ECG signal, and a correlation coefficient, rxy, is computed between the template and the ECG contained within each window of equal length. Here the correlation coefficient represents the similarity between template and ECG segment. This process produces a new data series containing correlation coefficients rxy. The correlation coefficient between two N length segments of x and y is computed using the following equation:
If the correlation, rxy, between template and ECG segment exceed a defined upper threshold value a detection flag is set to high (Figure.1-c). This flag is held in a high state until rxy drops below a defined lower threshold (Figure.1-d). A beat is set as the largest rxy peak between any high and low detection flag events (Figure.1-b).  Detected beats are marked with green circles. This double threshold method helps eliminate multiple peak detections within a close vicinity of one another.
Computational speed of template matching can be improved using the following three methods (see the function detectBeats() within ecgViewer.m and see matchTemplate.m ):
1. Skip Indexing - This method involves reducing the number of times the sliding window translates across the ECG signal. By translating every third ECG sample instead of indexing one sample, 1/3 as many correlation coefficients are computed. Skipped rxy values are replaced using cubic spline interpolation. 
2. Parallelization - This method involves parallelizing a portion of the template matching code for multi-core processor environments.
3. Combination - This method combines both the skip indexing and parallelized methods. 
Skipping samples, parallelizing code, and a combination of the two methods reduce computation time (17.2 s original) by approximately 64% (6.2 s), 58% (7.3 s), and 82% (3.16 s) respectively. These data are based on the results of 3 simulations of each technique using an ECG segment of 600,000 samples and a template of 161 samples in length.
Two types of detection methods exist on the ECG Viewer GUI:
1. Template Matching – standard template matching
2. Self  Template – This methods using the defined template file to create a new template base on the current ECG file. The current template is used to detect QRS complexes from the first 60,000 samples of ECG. These detected beats are then averaged together to create a “self template”. This self template is used in beat detection. NOTE: The sample length and template width may need to be modified for your preference.

Figure.1 – QRS detection using template matching. Plots include (a) example template used for QRS detection by template matching, (b) rat ECG with detected QRS complexes, (c) rxy data series and peaks detected using the double threshold technique, and (d) state of the detection flag used in the double threshold technique.

Building a template
ECG Viewer’s template matching marks beats as the center of a matched template. For example, if you make the center of your template correspond with the R-wave peak, then template matching will mark R-waves on your ECG data, etc.
Averaging several QRS templates together may help create a more universal template
IBI Filtering
IBI filtering is used to mark IBI “outliers”. If an outlier is detected based on the user selected criteria, the beat that initiated the IBI and the IBI itself is marked as an outlier on the plots. Outliers are marked by a filled red circle. Although the term filter is used in this section, no change to the original IBI occurs during ectopic interval detection.
Filter Types:
1. percentage filter – marks intervals that change by more than a user defined percentage (often 20%) from the previous interval [55].This method locates any sudden or abrupt IBI changes.
2. standard deviation filter –  marks outliers as being intervals that lie beyond the mean IBI by a user defined value of standard deviations (often 3 SD) [55].
3. median filter –  acts as an impulse rejection filter with threshold to delineate ectopic intervals [50]. The median filter of a random variable x of length N using a threshold of τ is given by 
 
4. above threshold filter – marks any interval lying above the user defined threshold limit as outliers
5. below threshold filter– marks any interval lying below the user defined threshold limit as outliers
6. custom filter – this was a personal filter used to ignore IBI near large spikes in the ECG signal. The first box defines the amplitude limit, and the second box defines the window width. Any IBI within the window width around ECG that has an amplitude above the limit is ignored.
Exporting
Two types of data can be exported using the export button located on the GUI within the export module. 
1. Export ECG – this button exports the currently loaded ECG file. File formats available for ECG exporting include MATLAB binary (.mat), 16-bit binary (.dat), text/ASCII (.txt), and Excel (.xls).
2. Export IBI – this button exports the IBI of the currently loaded ECG file. File formats available for IBI exporting include MATLAB binary (.mat), text/ASCII (.txt), and Excel (.xls).
The option labeled “Export current window only” tells ECG Viewer to only export the ECG or IBI currently displayed in the plots. In other words whatever you see on the screen is what gets exported.
File Annotations and Database
ECG Viewer allows users to annotate files and mark files as being “completed”.
These task can only be completed on the currently loaded ECG file.
Annotation can be created at any time point on the ECG file currently displayed by double clicking on the desired point on the ECG plot.
Annotations can be reviewed by double clicking on an annotation label within the annotation list. This list is located below the list of ECG files.
ECG files can be marked as being “complete” by loading the desired file and right clicking anywhere on the ECG plot.
To remove annotations you must load the Microsoft Access file and do it manually.
Before using the database feature the first time you must create a datasourse in your Windows environment. See http://MATLAB.izmiran.ru/help/toolbox/database/instal12.html#18933. This is only done once.

No comments:

Post a Comment