Area Tags - UVA-CAMA/NICUHDF5Viewer GitHub Wiki
I have received a few questions about how the area tags work. Of course, the area could be computed a bunch of different ways - I am not saying this is THE way to compute the area - just that this is the way we did it in the BAP. You can write your own method to do it your way!
The area tags are computed primarily using the threshtags2.m function.
With BAP 2.0, I made a mistake in the threshtags2.m algorithm, and the area calculation is slightly off, as described here. In BAP 2.1 going forward, the area will be computed as described below.
Let's assume we have some sample SpO2% data that looks like this:
x = [79,78,77,81,82,81,80,81];
xt = 1:8;
and we are running a desaturation algorithm with a threshold of T=80;
If we plot the data, we get this:
plot(xt,x)
hold on
xlabel('Time')
ylabel('SpO2%')
title('How NOT to calculate the area')
hold off
Now, this graph above shows how we do NOT calculate the area! A better way to look at the data to understand what we compute is like this:
scatter(xt,x)
hold on
xlabel('Time')
ylabel('SpO2%')
title('A better way to think about how we calculate the area')
hold off
Now, we need to draw a few lines on this graph to get a fuller understanding:
The threshold T is a red horizontal line at 80 and you can see we compute the area based on rectangles instead of triangles.
Let's take a look at the area below 80 for this example:
On the flip side, what if we wanted the area above 80? What would that look like?
Note that the area graph extends beyond xt=8! See the red 9 in the figure above!
Now looking at the code for threshtags.m, I see that there are a few different input options, namely negthresh
and lessequal
- what are these?
If you look at the comments at the top of the file you will see that:
- negthresh: should be set 1 if you want to identify events that drop below and threshold and 0 if you want to identify events above a threshold
- lessequal: set to 1 for < or >. Set to 2 for <= or >=.
So how do negthresh and lessequal affect our area calcultion?
let's pass in the following parameters into threshtags2.m
T = 80;
pmin = 1;
tmin = 0;
negthresh = see table below
lessequal = see table below
[tag,tagname]=threshtags2(x,xt,T,pmin,tmin,negthresh,lessequal)
This is how the tag variable is affected by changing negthresh and lessequal
negthresh | lessequal | Start | Stop | Duration | Number points | Area | Extrema | |
---|---|---|---|---|---|---|---|---|
events > T | 0 | 1 | 4 | 6 | 3 | 3 | 4 | 82 |
8 | 8 | 1 | 1 | 1 | 81 | |||
events < T | 1 | 1 | 1 | 3 | 3 | 3 | 6 | 77 |
events >= T | 0 | 2 | 4 | 8 | 5 | 5 | 5 | 82 |
events <= T | 1 | 2 | 1 | 3 | 3 | 3 | 6 | 77 |
7 | 7 | 1 | 1 | 0 | 80 |
Things to note:
- In the above table, each row gives the information for a single tag. In the events > T case, there are two rows because two tags are generated. Apologies if this explanation table is confusing in any way because of the multiple events.
- Duration is equivalent to Stop - Start + sampling period!
- The area of an event can be zero in the <= or >= case