An entrainment-based mechanical ventilator may be initially set to approximate the patient's spontaneous respiratory frequency, enabling the patient to entrain to the ventilator if the ventilator frequency matches the patient's spontaneous breathing frequency or is within a reasonable range from it. If the preset frequency of the ventilator is set too high or too low from the spontaneous frequency, the patient will fall out of phase and “fight” the ventilator. The ventilator phase relative to the patient's breathing effort indicates the difference between the ventilator frequency and spontaneous frequency. Based on the phase difference, a closed-loop control mechanism may continuously adjust the ventilator frequency to match the patient breathing frequency until the phase shift is within a preset limit. Patient-ventilator entrainment will occur when the ventilator frequency is within a certain range from the patient breathing frequency.