A medical ventilator (10) performs a method including: receiving measurements of pressure of air inspired by or expired from a ventilated patient (12) operatively connected with the medical ventilatorreceiving measurements of air flow into or out of the ventilated patient operatively connected with the medical ventilatordividing a breath time interval into a plurality of fitting regions (60) and simultaneously estimating respiratory systems resistance and compliance or elastance, and respiratory muscle pressure in each fitting region by fitting to a time series of pressure and air flow samples in that fitting region. In one approach, the fitting includes parameterizing the respiratory muscle pressure by a continuous differentiable function, such as a polynomial function, over the fitting region.In another approach, the fitting is to an equation of motion of the lungs in each fitting region, while monotonicity constraints and inequalities bounding at least the respiratory muscle pressure Pmus(t) and respiratory systems resistence R and compliance C are applied to the respiratory muscle pressure in each region.