The removal of unwanted noise from electrocardiogram (ECG) recordings is a difficult procedure in biomedical signal analysis. It alters the signal and affects the accurate interpretation of the signal. A major distortion produced while recording is due to muscle artifact (MA) or electromyographic (EMG) noise. To achieve a high-quality ECG recording by eliminating this MA noise, our research proposes a novel filtering technique using the grasshopper optimization algorithm (GOA) based variational mode decomposition (VMD) method with the dynamic time warping (DTW) distance concept. GOA is utilized to identify the best optimal parameters for the VMD process, and then the DTW technique is applied to discover the relevant modes that include MA noise. To successfully remove noise, these modes are denoised using the discrete wavelet transform (DWT) method. ECG signal analysis is performed on a real-time MIT-BIH arrhythmia database and is compared with the performance of recent existing techniques using signal characteristics such as signal-to-noise ratio (SNR), mean square error (MSE), correlation coefficient (CC), and so on. As an outcome of these computations, our proposed technique outperforms those existing methods when it comes to denoising MA noise.