Electroencephalogram (EEG) signals, when recorded within the strong magnetic field of an MRI scanner are subject to various artifacts, of which the ballistocardiogram (BCG) is one of the prominent ones affecting the quality of the EEG. The BCG artifact varies slightly in shape and amplitude for every cardiac cycle making it difficult to identify and remove. This paper proposes a novel method for the identification and elimination of this artifact using the shape basis functions of the new dilated discrete Hermite transform. In this study, EEG data within and outside the scanner was recorded. On removal of the BCG artifact for the EEG data recorded within the scanner, a significant reduction in amplitude at the frequencies associated with the BCG artifact was observed. In order to quantitatively assess the efficacy of this method, BCG artifact templates were added to segments of EEG signals recorded outside the scanner. These signals, when filtered using the proposed method, had no significant difference (p<0.05) from the original signals, indicating that the technique satisfactorily eliminates the BCG artifact and does not introduce any distortions in the original signal. The method is computationally efficient for real-time implementation.