A method, consisting of, while imaging a patientusing an initial magnetic resonance imaging (MRI)sequence, receiving an initial set of electrocardiograph(ECG) signals from the patient. The method includesidentifying initial noise in the initial set of ECGsignals arising from the initial MRI sequence, andcharacterizing the initial noise in terms of frequencycomponents thereof. The method further includesgenerating a relation between parameters defining theinitial MRI sequence and the frequency components,computing a filter by applying the relation to theparameters of a subsequent MRI sequence, and applying thecomputed filter to reduce noise in a further set of ECGsignals, received from the patient, while imaging thepatient using the subsequent MRI sequence.