Apnea Board Forum - CPAP | Sleep Apnea
R? program, sliding windows and OSCAR's FR zero-axis - Printable Version

+- Apnea Board Forum - CPAP | Sleep Apnea (https://www.apneaboard.com/forums)
+-- Forum: Public Area (https://www.apneaboard.com/forums/Forum-Public-Area)
+--- Forum: Software Support Forum (https://www.apneaboard.com/forums/Forum-Software-Support-Forum)
+--- Thread: R? program, sliding windows and OSCAR's FR zero-axis (/Thread-R-program-sliding-windows-and-OSCAR-s-FR-zero-axis)



R? program, sliding windows and OSCAR's FR zero-axis - 2SleepBetta - 04-23-2021

Is there a program simpler than R freeware and its add-ons that would numerically integrate VAuto-BRP-edf file flow rate curve data within a specified sliding (or "rolling"?) window width? A search shows that R has a program in its related TTR support for analyzing data in sliding windows (SWA). There are other programs, of course. Always MATLAB.

In relation to that question and my aim to determine the areas between the FR curve and its zero axis, I ask the following (dumb?) question: How does OSCAR determine the location for the zero axis for the Flow Rate (FR) graphs?  Maybe it looks at balancing the scatter (using least squares?)  above and below a line through the y=0=FR  accidentals that do occur. Just curious.

In working on a couple of simple FL vs FR examples, I wanted the zero flow coordinates (abscissas and ordinates) in the BRP-edf file to be handy for easy numerical integration of FR data curve's "t" and "y>0" coordinates--at least for all of those time-values within brief neighborhoods up to and including an FL event. 

Having to prorate/interpolate to find the zero-point values at changes of y-value signs was a pain. I did it slowly with two childishly simple (brute force) formulas, having forgotten what little I once knew about Excel VBA and macros. Even stumbling for a time,  Huh  stumbling with "+" and "-" signs longer than I care to admit, to write a simple formula to interpolate for coordinate values between opposite signs.

I have been groping, along with others (see sheepless's recent thread on FL) to gain a clearer understanding of what a Resmed flow limit (FL) flag means, in mathematical and airflow terms, as those flags  are presented by OSCAR from  VAuto and AirSense Autoset devices.

Please help with any constructive comment or criticisms you have on approaching either the topic or my comments about the matter, the latter here and elsewhere.

A couple more after-thought but important details I'd like to know:

Does Resmed use a certain number of inspiratory waves--how many?--or use a fixed time duration--how long?--for the width of its sliding window sampling for FL effects. The larger of my two little naive tests was for a fixed time, just to get a feel for all that is involved. Only one of those tests had a meaningful result: a lone M-tipped inspiratory  flow delivered 11% less air than each of its almost uniformly normal, near-neighbor, preceding breaths. This test was an instance of a wide window with just one anomalous inspiratory curve profile to evaluate.

Thank you for looking at this, 

2SB


RE: R? program, sliding windows and OSCAR's FR zero-axis - kappa - 04-23-2021

My reading is that OSCAR does no interpretation of the FlowRate data captured by ResMed - it just extracts it from the edf file. The ResMed firmware on the PAP is doing all of the heavy lifting to model pressure, flow, leaks (expected due to mask vents plus real leaks), etc.

I would have thought that average flow (excluding leaks) should be zero, so perhaps that is used to determine the total leak rate, then the expected vent leak (based on pressure) is deducted to determine other leaks. But I'm not sure if that is reflected in the data.

Your M-tipped inhalation might have been a larger breath for some reason and will have a corresponding larger exhale (or set of exhales) nearby.

The Flow Limit calculation is some heuristic style calculation of the flatness of the inspiration which tries to deal with various idiosyncrasies of breathing flow rates such as cardiogenic artifacts, initial inrush, etc.


RE: R? program, sliding windows and OSCAR's FR zero-axis - 2SleepBetta - 04-25-2021

kappa wrote as inside quotation marks:

"I would have thought that average flow (excluding leaks) should be zero, so perhaps that is used to determine the total leak rate, then the expected vent leak (based on pressure) is deducted to determine other leaks. But I'm not sure if that is reflected in the data."  Things I need to examine and see in the relevant curves and data.

"Your M-tipped inhalation might have been a larger breath for some reason and will have a corresponding larger exhale (or set of exhales) nearby." I don't notice that in the attached graphic. That inhalation does show (visual judgment only, here) a longer dwell or inhalation time, (possibly prolonged by an effect from interference with flow?).

"The Flow Limit calculation is some heuristic style calculation of the flatness of the inspiration which tries to deal with various idiosyncrasies of breathing flow rates such as cardiogenic artifacts, initial inrush, etc." Yes.

Bold fonts, above, mark 2SleepBetta's inserted responses. 

Thank you for helpful comments, kappa.

                                                      **********************************||||||*******************************

I revisited the longer flow sequence I used in finding the 11% reduction for the M-tip. Then, thinking of Resmed algorithms' shorter-duration sliding windows, I limited two summations of inspiratory flows to those five and those two shown before the M-tip. 

The Mi-tip volume losses relative to those averaged flows were 8.4 and 7.8 percent. (No interpolations were done for unlogged 0-values lying between changes of flow value signs between inhalation and exhalation. Estimated maximum error, for these waveforms, was less than 0.4%.)

Leak was zero throughout the period and extended beyond it. Thanks to kappa's mentioning leak effects, I'll try to choose further examples with that same 0-leak simplification until better prepared for the general case. But I suppose built-in mask leak should be recognized too, though for a time I'll ignore it.

In trying to get a toe hold on the problem at hand, I chose the single M-tip in the cleanest environment with like inhalation waves and only one rectangular FL flag. Evaluation of several variations of isolated anomalies (among "normals") will, I expect, help understand more confused multiple influences in the usual significant instances. 

 [attachment=31726]


RE: R? program, sliding windows and OSCAR's FR zero-axis - biorn - 04-25-2021

Leaks are unknow bellow the normal leaks rate considered by resmed  ≈ 24L/min

For the zero line I mean it's just =0 in oscar. Or from the min/max physical value in the edf file.

The sliding is due to resmed record all data each 2s and flow rate + pressure mask each 40ms.


RE: R? program, sliding windows and OSCAR's FR zero-axis - 2SleepBetta - 04-26-2021

(04-25-2021, 09:46 AM)biorn Wrote: Leaks are unknow bellow the normal leaks rate considered by resmed  ≈ 24L/min

For the zero line I mean it's just =0 in oscar. Or from the min/max physical value in the edf file.

The sliding is due to resmed record all data each 2s and flow rate + pressure mask each 40ms.

Thanks for your helpful reply, biorn. I want to be sure I understand your points. EDF FR files are huge and handling them in Excel with my laptop is maddeningly slow, so its best to be working in the correct direction.


--A couple responses and questions and a couple of additional remarks are thrown in on the topic:

I believe you mean that leaks below some value number, as is apparently specified by Resmed somewhere, are undetected or are unreported if detected. Further, you may mean that leaks above 24 L/sec cause other sleep detections and measures to be absent, less certain or wrong.  Do I understand you correctly?

As kappa suggested above, the total of all airflow volumes , having flowed in and out, should be zero (as shown by OSCAR) after allowing for any built-in leak provisions (of mask design) as well as allowing for device detected mask-seal and lip leaks.  



--Regarding the FL sampling and reporting we see from Resmed as reported by OSCAR:  

As I have understood you, you have seen specifications or other evidence that the Resmed algorithm detecting FL looks at successive contiguous 2-second blocks of airflow time. So far, I have not looked in the correct place to find that information. (If you recall your source for the info please point me toward it; there may be additional useful information there.)  So, accordingly, we know--correct?--that the algorithm does not look at a new 2-second wide sliding window every 0.04 seconds and then report (logs ) a summarizing/overall value every two seconds (at/on the clock's whole-second-mark ticks).


--Other minor observations from my data as seen in OSCAR (I don't know about ResScan):

The OSCAR FL bar graph flags: 

My merge of the PLD and BRP edf file data, for FL and FR, into one time ordered array will  graphically portray a single FL with a series of narrow vertical bars at just the beginning of each 2-second interval; that continuous series of bars with (FL scale no.) gaps between them continues for that FL value for some multiple of 2 seconds. Apparently OSCAR and other software displaying FL put a horizonal bar across the tops of the set of FR-bar values and then omits all the interior bar indicators after adding a closing vertical bar to mark the end for the final 2-second datum value.

The narrowest FL indicator flag I've seen spanned 2 seconds of the graph , as expected, and all flags are some multiple of 2 seconds wide. The vast majority of my flags span a 12 second width.

Most long runs of such widely separated FL as I still have will run for long periods, all starting on an even number of seconds. But at other times in the same sleep session there will be long runs of FL starting from an odd second.  Those start differences have not been mixed, occurring in only long runs of the same.


RE: R? program, sliding windows and OSCAR's FR zero-axis - biorn - 04-26-2021

-Global knowledge: the cpap record data into edf file. data are signal composed by value each x sec (pressure mask and flow rate 0.04 sec and the rest 2sec) or by events with starttime info and duration (ca oa etc..)

-Leaks: cpap survey leaks with secret magic algoritm xd, and report value like all value under 24 are zero and value over 24 are realvalue - 24. (be carefull 24L/min is what I read somewhere not what I know)

-The OSCAR FL bar graph flags : in the file you just have the coordonate of a point each x second, so oscar and other software just join the consecutives points with a line to make a graph)


I thing I missed nothing. My english isn't good, sorry.


RE: R? program, sliding windows and OSCAR's FR zero-axis - multicast - 04-27-2021

One may ask which physical event corresponds to flow = 0.  Isn't it the end of exhalation/beginning of inhalation?  In this case it's the time where the flow rate has an inflection point where the flow rate changes its curvature from right to left.  In case there's no leakage present the areas above and below the zero line should be equal.

Hence in the attached picture

[attachment=31778]

the "physical" zero line would be around -5.  Determine the zero line is a sort of oracle.


RE: R? program, sliding windows and OSCAR's FR zero-axis - 2SleepBetta - 04-27-2021

1. @multicast:

I've noticed  that small difference, .5 here, and it is partly why I asked the question about the zero axis. Your comment prompted taking a look at that OSCAR drawn image again and to look for anything graphed that correlated with the variation in that small difference. The first and last inflows begin at or closest to zero of the 11 waves, most of which are past the inflection point where there is that.5 difference. MV starts, rises and falls gradually for the spread: 9.01. 9.25 and 8.94, the 9.25 lies in the later half the exhale before the M-tip.

I don't know what to make of it--about this, and often, about my other nit picking details about trivia lying   Dont-know alongside my rabbit trails.

The inflection points dropped slightly lower, sagged, as the MV rose, as if 180 degrees out of phase. Will be glancing at this in other curves, just in passing and out of curiosity. I'm guessing it is just a small variation occurring in relation to TV and related MV changes and it may reflect certain compromises in approximations of measurements recorded--leakage possibly. 


2. Here are new-to-me and FL-relevant findings from ApneaBoard's own resources. Please pardon the sloppy graphics work and do consult the underlying links for more Resmed information as well as for more about other manufacturers' xPAP blowers:

[attachment=31794]

http://www.apneaboard.com/forums/Thread-How-does-Flow-Limitation-affect-pressure?pid=159321#pid159321 - a relevant AB post that includes the full chart about machine-algorithm detection and responses.

PAP Technology - Apnea Board Wiki - FL and more info

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4629962/table/t2-mder-8-425/