heartbeats
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
heartbeats [2010/05/28 03:10] – Some small additions jochen | heartbeats [2010/06/29 17:17] (current) – updated help jochen | ||
---|---|---|---|
Line 2: | Line 2: | ||
===== Motivation ===== | ===== Motivation ===== | ||
- | For many tasks, it is often helpful to collect secondary physiological measurements, | + | For many experimental |
===== Requirements ===== | ===== Requirements ===== | ||
The raw signal (ECG channel recording) must be available in a Matlab variable. For the purpose of this manual, this variable is called **data**. | The raw signal (ECG channel recording) must be available in a Matlab variable. For the purpose of this manual, this variable is called **data**. | ||
+ | The [[xff]] IO reading class now supports reading the following formats: | ||
+ | * ACQ (up until version <= 3.9.7) | ||
+ | * TXT (use ''< | ||
+ | and further formats might be added based on request and urgency. | ||
+ | |||
+ | In case the data is in a different format, you must ensure to first convert into one of the formats above or into a MAT file, which then can be read used like this: | ||
+ | |||
+ | <code matlab heartbeats_readmat.m> | ||
+ | load HPS1344_session1_ECG.mat; | ||
+ | |||
+ | % create new NTT (used for methods on data!) | ||
+ | ntt = xff(' | ||
+ | |||
+ | % store data from mat file in ntt | ||
+ | ntt.Data = data;</ | ||
===== Reference (help) ===== | ===== Reference (help) ===== | ||
Line 11: | Line 26: | ||
< | < | ||
- | FORMAT: | + | FORMAT: |
Input fields: | Input fields: | ||
Line 17: | Line 32: | ||
sig Sx1 numeric signal | sig Sx1 numeric signal | ||
opts optional settings | opts optional settings | ||
+ | | ||
| | ||
+ | | ||
+ | {' | ||
+ | {' | ||
+ | if .detlength is not given, will be set to 0.02 | ||
+ | if .skewdt is not given, will be set to 0.1 | ||
+ | {' | ||
+ | if .detlength is not given, will be set to 0.01 | ||
+ | if .skewdt is not given, will be set to 0.05 | ||
+ | {' | ||
+ | if .detlength is not given, will be set to 0.02 | ||
+ | if .skewdt is not given, will be set to 0.04 | ||
+ | {' | ||
+ | if .detlength is not given, will be set to 0.03 | ||
+ | if .skewdt is not given, will be set to 0.1 | ||
+ | {' | ||
+ | if .detlength is not given, will be set to 0.02 | ||
+ | if .skewdt is not given, will be set to 0.06 | ||
| | ||
| | ||
+ | | ||
| | ||
| | ||
- | | ||
| | ||
+ | | ||
+ | | ||
+ | | ||
| | ||
| | ||
- | .windsor | + | .skewdt |
+ | | ||
Output fields: | Output fields: | ||
Line 37: | Line 74: | ||
wgd guess whether window is good or not | wgd guess whether window is good or not | ||
wd windowed data (in 100Hz resolution, interpolated) | wd windowed data (in 100Hz resolution, interpolated) | ||
+ | hrv | ||
- | Note: this function is still preliminary</ | + | Note: this function is still preliminary, other options passed on to |
+ | computehrv (if 8th output is requested), with .hrvrfreq being | ||
+ | set to .resfreq</ | ||
===== Usage overview ===== | ===== Usage overview ===== | ||
Line 46: | Line 86: | ||
heartbeats(data, | heartbeats(data, | ||
- | This will perform the following steps: | + | This will perform the following steps (if no pre-defined beat positions are given): |
* windowed z-transform (in segment windows with configured stepsize, also works as low-pass filter!) | * windowed z-transform (in segment windows with configured stepsize, also works as low-pass filter!) | ||
* windsorizing (cutting off over-large peaks) | * windsorizing (cutting off over-large peaks) | ||
* filtering (low-pass, to get rid of very high frequency noise) | * filtering (low-pass, to get rid of very high frequency noise) | ||
- | * skew-flipping (so that peaks always are on the positive tail of the distribution) | + | * possible |
* segment-wise beat detection (maximum value position within each sub-segment where value > mean + 0.5 * skew) | * segment-wise beat detection (maximum value position within each sub-segment where value > mean + 0.5 * skew) | ||
+ | * if not enough beats are found (currently less than 6 per minute overall) the best general fit over the auto-correlation is computed and beats are completely re-estimated | ||
- | Next, the detected (or provided) beats will analyzed, and any irregularities | + | Next, the detected (or provided) beats will be analyzed |
+ | * the robust mean over the distance of beats (heartrate) is computed | ||
+ | * any beat closer together than 1/3 of that distance | ||
+ | * any gap larger than 3 times that distance is automatically filled up (at located within segments) | ||
+ | * each segment surrounding any given beat will be resampled to 101 values (fixed resolution) | ||
+ | * the mean over segments with a suitable length will be taken as the reference | ||
+ | * a t-statistic is computed for how much variance in each of the segments is accounted for (better scaled than r or F) | ||
+ | * all segments below the specified threshold (default t=25) will be marked as irregular | ||
- | {{:heartbeats_cleanup.png|heartbeats cleanup dialog}} | + | Any of these irregularities (that is to say, places where either the distance between beats is too small or too large or the shape of the detected beat does not match the mean signature) will be displayed, one by one, in a small dialog: |
+ | |||
+ | {{:heartbeats_cleanup_v2.png|heartbeats cleanup dialog}} | ||
+ | |||
+ | Some info on the controls: | ||
+ | * the larger time course plot shows an excerpt of the provided signal (data) around the detected irregularity | ||
+ | * the smaller time course plot gives the entire signal (noise estimate) along with indicators of irregularities (blue lines) and the current position (green line); this can be used to directly visit a problematic area by clicking into this smaller time course plot | ||
+ | * the list box contains the positions of detected (accepted) beats in the window of the larger time course excerpt | ||
+ | * the buttons below can be used to remove beats from the list and to navigate to the previous or following irregularity | ||
+ | * the checkbox below the buttons switches between raw and filtered timecourse (only available if filtering was performed initially) | ||
The operation is relatively simple: | The operation is relatively simple: | ||
* to add a beat in the stream, simply press the mouse button close to the desired peak location (which will be determined in a +/- 100ms window around the clicked spot) | * to add a beat in the stream, simply press the mouse button close to the desired peak location (which will be determined in a +/- 100ms window around the clicked spot) | ||
* to remove a beat (or several beats), select those in the dropdown box and press the " | * to remove a beat (or several beats), select those in the dropdown box and press the " | ||
- | * once all beats in this window are correct, | + | |
+ | | ||
- | If no more irregularities remain to be checked, the dialog will close automatically. If you wish, you can also manually close the dialog (prematurely) to go on to the next stage. | + | If no more irregularities remain to be checked |
In case the plotting has been enabled, the following two displays appear: | In case the plotting has been enabled, the following two displays appear: | ||
Line 72: | Line 130: | ||
{{: | {{: | ||
- | The second figure shows the entire signal over time in a 20Hz sampling (in blue) with the detected heart-rate super-imposed to control for flaws in the detection. This can be done by zooming in on a smaller piece of the signal: | + | The second figure shows the entire signal over time in a 20Hz sampling (in blue) with the detected heart-rate |
{{: | {{: | ||
+ | |||
+ | ==== Problems ==== | ||
+ | Sometimes, the data is **very** noisy (like this): | ||
+ | |||
+ | {{: | ||
+ | |||
+ | At this point, the function (heartbeats) does not yet have any pre-processing algorithms. After consultation with colleagues, I might decide to add those functions in a future version. | ||
===== Scripting ===== | ===== Scripting ===== | ||
Naturally, it is possible to script this function, save the pre-detected heartbeats (without manual interaction/ | Naturally, it is possible to script this function, save the pre-detected heartbeats (without manual interaction/ | ||
+ | For instance, if the raw signal looks like this | ||
+ | |||
+ | {{: | ||
+ | |||
+ | A two-pass detection scheme can be employed: | ||
+ | |||
+ | <code matlab heartbeats_crisp_detection.m> | ||
+ | data = xff(' | ||
+ | |||
+ | % then z-transform the third column (in our case) and take the 4th power | ||
+ | pdata = ztrans(data.Data(:, | ||
+ | |||
+ | % pre-detect beats | ||
+ | % since we used the 4th power, the skew detection threshold must be lowered | ||
+ | % and our signal has short spikes, so the detection length threshold also! | ||
+ | bp = heartbeats(pdata, | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | % then pass this along with the actual signal back in | ||
+ | [bp, bs, bf, bv, cp, wgd, wd] = heartbeats(data.Data(:, | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' |
heartbeats.txt · Last modified: 2010/06/29 17:17 by jochen