Esophageal pressure (Peso) is one of the most common and minimally invasive methods used to assess the respiratory and lung mechanics in patients receiving mechanical ventilation. However, the Peso measurement is contaminated by cardiogenic oscillations (CGOs), which cannot be easily eliminated in real-time. The field of study dealing with the elimination of CGO from Peso signals is still in the early stages of its development. In this study, we present an adaptive filtering-based method by constructing a reference signal based on the heart rate and sine function to remove CGOs in real-time. The proposed technique is tested using clinical data acquired from 20 patients admitted to the intensive care unit. Lung compliance ( QUOTE ) and esophageal pressure swings (△Pes) are used to evaluate the performance and efficiency of the proposed technique. The CGO can be efficiently suppressed when the constructional reference signal contains the fundamental, and second and third harmonic frequencies of the heart rate signal. The analysis of the data of 8 patients with controlled mechanical ventilation reveals that the standard deviation/mean of the QUOTE is reduced by 28.4–79.2% without changing the QUOTE and the △Pes measurement is more accurate, with the use of our proposed technique. The proposed technique can effectively eliminate the CGOs from the measured Peso signals in real-time without requiring additional equipment to collect the reference signal.