A method, consisting of, while imaging a patient using an initial magnetic resonance imaging (MRI) sequence, receiving an initial set of electrocardiograph (ECG) signals from the patient. The method includes identifying initial noise in the initial set of ECG signals arising from the initial MRI sequence, and characterizing the initial noise in terms of frequency components thereof. The method further includes generating a relation between parameters defining the initial MRI sequence and the frequency components, computing a filter by applying the relation to the parameters of a subsequent MRI sequence, and applying the computed filter to reduce noise in a further set of ECG signals, received from the patient, while imaging the patient using the subsequent MRI sequence.