Time-frequency Analysis in Biology

This page demonstrates the use of our time-frequency analysis add-on package for Mathematica. For an introduction to time-frequency analysis, read our tutorial.

Biological example

Electroencephalograms (EEG) and electrocardiograms (ECG or EKG) are two important ways to record electrical activity in a patient. This example focuses on the ECG interpretation but the method of analysis is equally applicable to EEGs.

Read and downsample some ECG data for normal cardiac rythme and from a patient with partial epilepsy:

handle = OpenRead["ECG/normal.txt"] ;

Read[handle, {String, String}] ;

normalecg = {#〚1〛, #〚2〛} &/@ReadList[handle, {Number, Number, Number}] ;

Close[handle] ;

normalecg = Mean/@Partition[normalecg, 4] ;

handle = OpenRead["ECG/epilepsy.txt"] ;

Read[handle, {String, String}] ;

epilepsyecg = ReadList[handle, {Number, Number}] ;

Close[handle] ;

epilepsyecg = Mean/@Partition[epilepsyecg, 6] ;

Little information can be extracted from direct plots of the ECG data:

With[{f = Interpolation[normalecg]}, Plot[f[t], {t, normalecg〚1, 1〛, normalecg ...                                                                                           normal

[Graphics:HTMLFiles/tutorial_222.gif]

With[{f = Interpolation[epilepsyecg]}, Plot[1 - f[t], {t, epilepsyecg〚1, 1〛, e ...                                                                                         epilepsy

[Graphics:HTMLFiles/tutorial_224.gif]

Compute the TFRs over 5<t<55 seconds:

normaltfr = With[{f = Interpolation[normalecg]}, FunctionTFR[f[t], {t, normalecg〚1, 1 ... meter20, TemporalRange {5, 55}, SpectralRange {0, 2π 5}]] ;//Timing

{69.0645 Second, Null}

epilepsytfr = With[{f = Interpolation[epilepsyecg]}, FunctionTFR[f[t], {t, epilepsyecgӏ ... meter20, TemporalRange {5, 55}, SpectralRange {0, 2π 5}]] ;//Timing

{74.1497 Second, Null}

GetTFRωRange @ epilepsytfr

{0.0523861, 31.5081}

Each heartbeat is marked by a high-amplitude (red), short-duration signal component:

ContourPlot[Log @ Abs[normaltfr[t, 2π ν]], {t, 5, 55}, {ν, 0.06, 4.822}, Fram ...                                                                                           second

[Graphics:HTMLFiles/tutorial_232.gif]

ContourPlot[Log @ Abs[epilepsytfr[t, 2π ν]], {t, 5, 55}, {ν, 0.06, 3.316}, Fr ...                                                                                           second

[Graphics:HTMLFiles/tutorial_234.gif]

The ridge along ν=1.5 is the principal frequency of the heart beat. In both cases, the instantaneous frequency along this ridge is approximately constant. However, the ridge along ν=2.75 is approximately uniform for the normal patient and highly non-uniform in the case of the patient with partial epilepsy. The difference is very pronounced in the time-frequency representation and, consequently, time-frequency analysis can be very useful in the interpretation of ECG/EKG signals.