A method, including, while imaging a patient using an initial magnetic resonance imaging (MRI) sequence, generating an initial MRI reference signal in response to the initial MRI sequence using a reference sensor placed in proximity to the patient. The method further includes identifying, by locking on to the initial MRI reference signal, noise that will be generated in electrocardiograph (ECG) signals received from the patient, and computing a programmable correction to be applied to the ECG signals to reduce the noise. The method also includes applying the programmable correction to reduce the noise in the ECG signals, received from the patient, while imaging the patient using a subsequent MRI sequence and while locking on to a subsequent MRI reference signal generated in response to the subsequent MRI sequence using the reference sensor.