the invention provides a method and apparatus for improved ventilator patient synchronization in which the most likely phase is determined on the basis of flow and rate of change of flow information using bayes &# 39 ; theorem or some similar formula for assessing conditional probability . in an identifying step 20 as shown in fig2 , according to the invention , the respiratory cycle is divided or partitioned into a number of distinct states , for example , early inspiration , mid - inspiration , late inspiration , early expiration , mid - expiration , late expiration , pause , sigh and cough . when the method and apparatus according to the invention are being used , flow and pressure observations are made continuously and at each time point in a measuring step 22 . in a calculating step 24 , probabilities or likelihoods are determined . the likelihood of the phase corresponding to each of the states is determined preferably using bayes &# 39 ; theorem as shown in equation 1 , supra . for example , in a system that distinguishes between six states , six calculations for each distinct state using equation 1 would be made . this evaluation may include an assessment of the prior likelihood of each of the identified states l ( h i ). however , these may be determined before use and / or adjusted during use . likelihoods of the distinct respiratory states occurring given flow and rate of change of flow observations l ( h i | f j ) are also determined . after these evaluations , in a determining step 26 , the patient &# 39 ; s phase is determined to be the phase which corresponds to the most likely state , e . g . the phase calculation with the highest probability or likelihood . this information may then be used by the apparatus to adjust the flow , volume or pressure of air being delivered to the patient in order to improve ventilator synchronization . the prior likelihood or prior probability of each state l ( h i ) depends upon the definition of the state and its relative duration . such a determination may be accomplished by a ratio of the duration of the state to the duration of a respiratory cycle . each state may not necessarily have the same duration . a simple system might divide the respiratory cycle into two states : inspiration and expiration . alternatively , a greater number of states within inspiration or expiration may be classified by the system . if the respiratory cycle led to sinusoidal flow vs . time curves , then it may be appropriate to divide the cycle into equal temporal subsections and assign each subsection as a state in which case , each state may be equally likely a priori . for example , if the duration of a hypothetical respiratory cycle was 6 seconds and the system distinguishes six states , then each state may be one second in duration , the first second being termed “ early inspiration ”, the next second “ mid - inspiration ” and so on . in this model , the different states may have the same prior likelihoods . thus , as illustrated in fig3 the likelihood of each state l ( h i ) is ⅙ as follows : increasing the number of states increases the potential accuracy of a system to track changes in respiratory state , however , this comes at an increasing computational cost . it may be computationally more efficient to have states of different duration . in one model of respiration , the states may be chosen on the basis of magnitude of flows , for example early flows from 0 up to ⅙th of the peak flow may be termed “ early inspiration ”. in such a system , for example , as shown in fig4 , again based upon a respiration cycle for a typical patient flow l ( h early — inspiration ) might be 4 / 48 where 4 approximates the duration of the state and 48 approximates the duration of the entire cycle , viewed as the intercept of the peak flow range and the flow cycle . similarly , a mid inspirational state determined from ⅚ to 6 / 6 of the peak flow might have a likelihood l ( h mid — inspiration ) equal to 11 / 48 . fig4 also shows a mid expiration state with l ( h mid — expiration ) equal to 9 / 48 . the remaining states may be determined in similar fashion . in another model of respiration , the rate of change of flow may be chosen as the basis for dividing the respiratory cycle . thus , an early inspiration state may be characterized by flow where the rate of change is in a range appropriate to classify the rate of change of respiration in its early stages . using for example a graph , the duration of a discrete portion of the respiratory cycle in that particular rate of change range divided by the duration of the entire cycle can then yield the prior probability of the particular state l ( h i ). an advantage of dividing the respiratory cycle on the basis of rate of change of flow is that those parts of the respiratory cycle where flow changes more rapidly may have more respiratory states assigned to them . in these latter two models , the different states may have different prior likelihoods . in one form of the invention , the number of states and their definitions may be adaptively refined depending upon the breath data . for example , where the flow rate is changing rapidly , the apparatus according to the invention can determine that it is appropriate to have more states to define that region . observation of breath data of patients over several nights leads to the conclusion that a cough is a priori less likely to occur than a breath , since patients breath more often than they cough . it may also be observed that a deep breath is more likely following a number of shallow breaths . patients are known to pass through a number of different stages during sleep , such as rem sleep . the nature of their breathing can change depending on the different stage of sleep and hence different types of breath are a priori more likely depending on the stage of sleep . to the extent to which a particular patient exhibits characteristic breaths , the system has the capability to learn these characteristics and adjust the prior likelihoods of different states to suit the patient as herein described . a discrete set of j observations for purposes of determining an observed probability function l ( f j | h i ) may be defined for a flow signal . similarly , a discrete set of observations of the derivative of flow may be defined . the function may be predefined or changed as a result of changing patient respiratory characteristics . the function may be defined by dividing the range of values for flow or derivative of flow into discrete sub - ranges and then comparing those sub - ranges to each state and assessing probability based upon a typical or previously observed respiratory flow curve &# 39 ; s relationship with that sub - range . for example , the flow signal may range from − 200 l / min to + 200 l / min . this may be divided into the following sub - ranges : − 200 to − 50 , − 50 to 0 , 0 to 50 , 50 to 200 l / min . noise in the flow signal defines the smallest division into which flow signals may be divided ( i . e ., there is no point in dividing the total range of flow signals into 1 l / min divisions if the noise level is 2 l / min ). the following table , labeled observation table 1 , gives an example of the likelihoods of the observations being made , given the various hypotheses being true for a system that distinguishes six states . in this example , there is a low likelihood that a large positive flow signal will be observed during the mid expiration phase . while observation table 1 includes the terms “ low ”, “ medium ” and “ high ” to describe the likelihoods or probabilities , in actual calculations these terms will be quantified in the ranges of 0 – 33 percent for low , 33 – 66 percent for medium and 66 – 100 percent for high . moreover , these probabilities need not be limited to three levels . generally , a change in the boundaries of the states leads to a change in the likelihood of each observation given the hypothesis that the patient is in a given respiratory state is true . alternatively , the probabilities may be determined from defined continuous likelihood density functions . fig5 shows sample breath data that is subdivided into 9 states ( shown with roman numerals ). note that states “ i ”, “ ii ” and “ v ” are relatively brief compared to states “ iii ” and “ vi ”. hence , everything else being equal , states “ iii ” and “ vi ” have relatively greater prior likelihoods than states “ i ”, “ ii ” and “ v ”. the figure also depicts a set of flow observations ( large positive to large negative ) as the observations relate to the classification of phase states . the observed probabilities l ( f j | h i ) may be determined from this graph . for example , the intercept or observation of a flow in the range of 80 – 100 ( large positive ) would suggest a high probability for state iii but low for states i , v , vi , vii , viii , ix . states ii and iv may have low to medium likelihoods as these cases are at the boundary of the large positive observation . in the following hypothetical example , a calculation of the phase probability or likelihood is demonstrated in accordance with the invention utilizing the simplified six classification system of fig3 in determining l ( hi ) and observation table 1 for determining l ( fj | hi ). the results are as follows : observed fact f : measured flow from flow signal is 150 so f j = f large — positive l ( f large — positive | h early — inspiration )= 0 . 25 ( assuming 0 . 25 = low ) l ( f large — positive | h mid — inspiration )= 0 . 75 ( assuming 0 . 75 = high ) l ( f large — positive | h late — inspiration )= 0 . 25 l ( f large — positive | h early — expiration )= 0 . 25 l ( f large — positive | h mid — expiration )= 0 . 25 l ( f large — positive | h late — expiration )= 0 . 25 l ⁡ ( h early_inspiration | f large_positive ) = 0 . 25 × 0 . 167 0 . 25 × 0 . 167 + 5 × ( 0 . 167 × 0 . 25 ) = 0 . 125 l ⁡ ( h mid_inspiration | f large_positive ) = 0 . 75 × 0 . 167 0 . 25 × 0 . 167 + 5 × ( 0 . 167 × 0 . 25 ) = 0 . 375 l ⁡ ( h late_inspiration | f large_positive ) = 0 . 25 × 0 . 167 0 . 25 × 0 . 167 + 5 × ( 0 . 167 × 0 . 25 ) = 0 . 125 l ⁡ ( h early_expiration | f large_positive ) = 0 . 25 × 0 . 167 0 . 25 × 0 . 167 + 5 × ( 0 . 167 × 0 . 25 ) = 0 . 125 l ⁡ ( h mid_expiration | f large_positive ) = 0 . 25 × 0 . 167 0 . 25 × 0 . 167 + 5 × ( 0 . 167 × 0 . 25 ) = 0 . 125 l ⁡ ( h late_expiration | f large_positive ) = 0 . 25 × 0 . 167 0 . 25 × 0 . 167 + 5 × ( 0 . 167 × 0 . 25 ) = 0 . 125 by comparing the calculated probabilities l ( h i | f j ) to find the most probable phase , it is apparent that in this simplified example the phase is early inspiration . with this determination , a system providing ventilatory support may automatically adjust the support to accommodate the patient &# 39 ; s phase , for example , by adjusting a pressure gain associated with the particular state of the determined phase . moreover , the probability for the phase l ( h i ) may be modified after calculations to improve subsequent determinations by adjusting l ( h i ) to equal or approach the determined phase likelihoods l ( h i | f j ) by a function of l ( h i | f j ). moreover , the likelihoods of each of the observations l ( f j | h i ) may be updated based upon recorded breath data representing a prior respiratory cycle or some average of the prior respiratory cycles . in accordance with the invention , a processor of a ventilator apparatus like that illustrated in fig1 is programmed with an algorithm that accomplishes the following preferred method : ( a ) update the prior likelihood for each state l ( h i ) ( b ) update the likelihood of each observation , given each state l ( f j | h i ) ( b ) calculate the likelihood l ( h i | f j ) for each state using bayes &# 39 ; theorem . the first time constant may be in the order of several typical breaths , for example 10 to 15 s . the second time constant is shorter , for example , 1 / 20th of the duration of a typical breath , or several hundred milliseconds . in one form , the apparatus according to the invention provides a training period when the patient is allowed to wear the mask in a relaxed environment . the flow and pressure in the mask are monitored and the device has the opportunity to learn some of the characteristics of the patient &# 39 ; s respiratory patterns . during this period adjustments to the functions for likelihoods p ( h i ) and p ( f j | h i ) for each state of the system can be made using l ( h i | f j ) and observed breath data and / or the partitioning of phase states may change . the respiratory characteristics of the patient will change when the patient falls asleep , however , the apparatus can monitor the transition to the sleep state and estimate probable parameters for the sleep state . while patient respiratory flow can be modeled as being generally sinusoidal , in reality , the data are more complicated . for example , fig6 and 7 show flow data from a person over periods of 1 minute and 10 seconds respectively . the data can be additionally complicated with the presence of noise , artefact , drift , sighs , coughs and other events . during the presence of flows of small absolute value , the effect of heart beat ( the so - called “ cardiogenic effect ”) on flow data can be identified . these complications , which may be termed “ non - idealities ”, mean that a simple automatic system may incorrectly decide phase . for example , with reference to fig7 , a system based purely on threshold values might conclude that the patient had moved to the inspiratory phase at approximately 2 seconds , and then a short while later , for example a hundred milliseconds , gone to the expiratory phase , and then switched back to the inspiratory phase once again . in a simplified automatic system , such a breath may complicate calculations of the length of a respiratory cycle and the volume of air inhaled or exhaled . hence there is a need for a method and apparatus which can accurately determine the phase of a respiratory cycle of a patient from complex flow data . there is a need for a method and apparatus which is less likely to be confused by non - ideal flow when determining the phase of the patient . one approach to solving the problem of dealing with non - idealities in flow data is to smooth the data , for example by low - pass filtering the data in the measuring step 22 . a low pass filter may be characterized by the time constant of the filter . a small time constant may mean that the amount of smoothing is small , but the system can respond more quickly . a larger time constant may mean that the data is smoother , but that the system does not respond as quickly . a very large time constant — essentially a long term average — may remove all phase information . hence there is a need to choose an appropriate time constant if the data are to be smoothed . furthermore , there may be an advantage in a system that learns from the flow data of the patient what an appropriate time constant may be . such a system can dynamically update the time constant if necessary . determining the derivative of noisy data can be particularly problematic . an algorithm for calculating a derivative may give very different results depending on the period over which the data is analyzed . for example with reference to fig7 , an algorithm which calculated the derivative of data over the region from 2 seconds to 2 . 1 seconds may give a negative value , while an algorithm which calculated the derivative over the region from 2 seconds to 2 . 5 seconds may give a near zero value . a turning point is a part of a curve where the slope of the curve changes between positive and negative , that is , the second derivative is zero . similarly , the data at the end of a respiratory cycle ( that is , after exhalation and before inhalation ) can be particularly non - ideal because of the presence of cardiogenic flow . as a result , the calculations for determining the derivative of flow at the end of a respiratory cycle can be problematic and error prone . to overcome this problem , an algorithm for determining phase in accordance with the invention may first determine whether the patient is likely to be near the end of a respiratory cycle ( for example , if the absolute value of a flow datum is small , hence distinguishing from peak inspiration and peak exhalation ). if the patient is likely to be near the end of a respiratory cycle , then a different time constant may be applied to the smoothing of data for the purposes of calculating a derivative . in a preferred embodiment , the time constant will be longer in the region near the end of the respiratory flow curve than at other regions , such as early to late inspiration and early to late expiration . furthermore , in an algorithm in accordance with the invention , the effect of the derivative in determining the phase of the patient &# 39 ; s respiratory cycle is given less weight in the region where derivative calculations are likely to be error prone , such as one or more of the following : the end of the respiratory cycle , peak inspiration , and peak expiration . furthermore , in an algorithm in accordance with an embodiment of the invention , an a priori likelihood function for the derivative of flow in the end of the respiratory cycle has a maximum at a low or zero value of flow and a minimum at large values of the derivative . in other words , in an algorithm in accordance with an embodiment of the invention , in this region , a low value of the derivative has a higher likelihood than a high value of the derivative . in a preferred embodiment of the invention , 12 bit flow data are collected at 50 hz . the data are low pass filtered with a time constant of 160 ms . as previously described , in a system in which phase is divided into several states , an algorithm in accordance with an embodiment of the invention may determine that the patient is in one of those states , for example the state with the largest likelihood or probability . alternatively the algorithm may determine that phase is part way between two adjacent states with high likelihoods . the algorithm may determine that the phase is closer to the one of the two states with the highest likelihood , for example , by weighting in accordance with the relative size of the likelihoods . hence if one state is 95 % likely and another is 70 % likely , the phase will be determined to be closer to the state which is 95 % likely . in this regard , phase may be determined as a continuous variable . for example , phase may vary from 0 to 1 depending on the state determined or depending on the proximity between two most likely states . alternatively or additionally , phase may be represented using polar coordinates and vary from 0 to 360 degrees , or 0 to 2 pi radians . to illustrate such a determination , phase may be calculated as a continuous variable φ . one way to estimate this from a series of posterior probabilities p i of n states s i is to associate each state with a standard phase φ s , i and weighting factor w i then calculate φ as ϕ = ∑ i = 1 n ⁢ ⁢ p i ⁢ w i ⁢ ϕ s , i another approach is to use the formulation of bayes theorem in terms of continuous random variables , which yields the following posterior density function ( assuming here that the information available about the patient is the instantaneous respiratory flow q ), and the estimate of φ is that value which maximizes the posterior density given the observed value q of patient flow ( this may be a local or global maximum ). in practice , the prior and conditional densities which are used to calculate the posterior density may be estimated from discrete data , possibly by using continuous interpolating functions such as piecewise linear or cubic spline functions . the posterior density function may then be calculated ( possibly piecewise ) analytically or via numerical methods , yielding a posterior density function which may thus be a continuous function of φ and q . if the posterior density is a continuous function , it follows that since flow q is a continuous function of time then the estimated phase φ is a continuous function of time . such a continuous phase variable may then be used to adjust ventilator support pressure . for example , if the pressure delivered to the patient is based on a continuous function π of phase , where p min and a are constants or slowly varying quantities , then an important consequence of the phase being a continuous function of time is that the pressure is a continuous function of time , which may be desirable for example in order to avoid the discomfort which may be associated with sudden changes in pressure delivered to the airway . of course , as the number of discrete states increases , the representation of phase may be regarded as a continuous , rather than discrete function . this may alleviate a need for the additional calculation of a continuous phase variable from the determined phase states . in this regard , although six and nine states have been identified in prior embodiments , by way of example , phase may be divided into as many as 128 or 256 states . in an algorithm in accordance with an embodiment of the invention , phase determinations may be enhanced by other phase related likelihoods . for example , consecutive phase states are more likely than non - consecutive phases . thus , a phase determination may be based in part upon the likelihood that the current state is the next consecutive state from a previously determined state . to illustrate such a process , suppose that it has been determined that the current phase state is early inspiration . if the next phase state is mid - inspiration , then mid - inspiration is a priori more likely than a non - consecutive state , such as late inspiration or an expiratory state . hence as phase progresses through the cycle , a priori likelihoods are adjusted in accordance with their consecutive status , for example by increasing the calculated probability of the next consecutive state . this is not to say that an algorithm in accordance with an embodiment of the invention cannot make a determination that a non - consecutive state will follow the current state , but simply that it is less likely to make such a determination . hence in an algorithm in accordance with an embodiment of the invention , phase “ cycling ”— where the algorithm flips back and forward between two states — is less likely . although the invention has been described with reference to particular embodiments , it is to be understood that these embodiments are merely illustrative of the application of the principles of the invention . thus , it is to be understood that numerous modifications may be made in the illustrative embodiments of the invention and other arrangements may be devised without departing from the spirit and scope of the invention .
a method and apparatus that provides an expert system for determining respiratory phase during ventilatory support of a subject . discrete phase states are partitioned and prior probability functions and observed probability functions for each state are defined . the probability functions are based upon relative duration of each state as well as the flow characteristics of each state . these functions are combined to determine phase probabilities for each state using bayes &# 39 ; theorem . the calculated probabilities for the states may then be compared to determine which state the subject is experiencing . a ventilator may then conform respiratory support in accordance with the most probable phase . to provide a learning feature , the probability functions may be adjusted during use to provide a more subject specific response that accounts for changing respiratory characteristics .