Diagnosing cardiac conditions require careful examination of an electrocardiogram (ECG). However, a significant issue arises when capturing an ECG due to interference from various noises. Noises like power line interference (PLI) and muscle artifact (MA) change the morphology, making it difficult to interpret the original signal. Our research proposes an improved variational mode extraction (IVME) technique using a Heap-based optimization (HBO) algorithm and an automatic wavelet interval-dependent thresholding (AWIT) method to eliminate such noises. First, HBO uses the envelope entropy spectrum (EES) as the objective function to find the best fitness value for optimizing the VME parameter, known as penalty factor α. Then, we extract a specific mode using the optimal α value in VME to accurately remove PLI from the signal. Finally, the AWIT method automatically computes the intervals and their respective threshold values to remove excessive MA noise from the PLI-filtered ECG signal. We evaluate the efficiency of ten random real-time ECG signals from the MIT-BIH arrhythmia database. The result analysis proves that our algorithm can accurately extract the mode containing PLI and eradicate MA from the noisy ECG signal. It also shows improvement in signal parameters like signal-to-noise ratio (SNR improvement ), mean square error (MSE), and correlation coefficients (CC) with 36.7968 dB, 0.00030901, and 99.7278%, respectively.