Co-registration of EEG (Electroencephalogram)-and fMRI (functional magnetic resonance imaging) remains a challenge due to the large artifacts induced on the EEG by the MR (magnetic resonance) sequence gradient and RF pulses. We present an algorithm, based on the average-subtraction method, which is able to correct EEG data for gradient and RF pulse artifacts. We optimized artifact reduction by correcting the misalignment of EEG and fMRI data samples, resulting from the asynchronous sampling of EEG and fMRI data, through interpolation of EEG data. A clustering algorithm is proposed to account for the variability of the pulse artifact. Results show that the algorithm was able to keep the spontaneous brain activity while removing gradient and pulse artifacts with only a subtraction of selectively averaged data. Pulse artifact clustering showed that most of the variability was due to the time jitter of the pulse artifact markers. We show that artifact reduction by average-subtraction is optimized by interpolating the EEG data to correct for asynchronously sampled EEG and fMRI data.