The disclosed concept maintains that Qp=Qc−Qleak, where, Qp is the estimated patient flow, Qleak is the estimated leak and Qc is the measured total circuit flow. Qleak is given by a transfer function φ(χ) where x is a set of independent measured or fixed variables. The transfer function is thus Qleak=φ(χ). The transfer function (φ(χ) is adjusted given the constraint that, Qp shall be zero. The transfer function converges over time to accurately estimate the leak because over an extended time the mean patient flow will always be zero. In one example, φ(χ)=gorfPγ and the coefficient gorf is adapted until Qp is zero.