A method for controlling a mechanical ventilator that is supplying medical gas to a patient via an endotracheal tube. A pressure is measured from a patient end of an endotracheal tube. The pressure at the patient end of the endotracheal tube is used to create an improved endotracheal tube resistance model such that the medical gas supplied by the mechanical ventilator may be compensated for the resistance of the endotracheal tube thereby providing increased control over the medical gas that is delivered to the patients lungs. Additionally, if an obstruction in the patients airway is detected, the location of the obstruction may be targeted such that the proper remedial treatment or procedure is selected by a clinician.