There is provided a method of controlling a mechanical ventilator. The method may include the steps of receiving a measurement of transthoracic impedance of a patient obtained during chest compressions, determining a timing for a mechanical ventilator to provide a ventilation based on the measurement of transthoracic impedance, and sending a signal to control the mechanical ventilator based on the determined timing. There is also provided an apparatus for performing the method.