A method, including, while imaging a patient usingan initial magnetic resonance imaging (MRI) sequence,generating an initial MRI reference signal in response tothe initial MRI sequence using a reference sensor placedin proximity to the patient. The method further includesidentifying, by locking on to the initial MRI referencesignal, noise that will be generated inelectrocardiograph (ECG) signals received from thepatient, and computing a programmable correction to beapplied to the ECG signals to reduce the noise. Themethod also includes applying the programmable correctionto reduce the noise in the ECG signals, received from thepatient, while imaging the patient using a subsequent MRIsequence and while locking on to a subsequent MRIreference signal generated in response to the subsequentMRI sequence using the reference sensor.