The electrocardiogram (ECG) is often contaminated with various noises including electromyographic, 60 Hz, respiratory and baseline wander (BW). The BW noise presents challenges in removal from the ECG by conventional filtering approaches because its frequency content overlaps with that of ECG signals. Removal of the BW noise is often preferred as a step before ECG signal processing. In this paper we present an algorithm for estimating and removing BW noise from a single-channel ECG signal, which can be implemented in real-time digital signal processing hardware and software. The algorithm uses the Pan & Tompkins R-wave detection method and places an interpolation point (i.e., a "T-P knot") at each R-R midpoint. It performs a cubic spline interpolation of the four most recently detected T-P knots to estimate the most recent segment of the BW noise. This most recent segment is then subtracted from the ECG signal to produce a "flattened" signal. The algorithm was implemented and tested in a pseudo real-time environment using MATLAB™, and test results are presented for simulated ECG and BW data as well as for actual ECG recordings from the PhysioNet/PhysioBank Fantasia database containing very large BW signal components. Correlations of 0.9959-0.9978 are shown for the estimated versus actual BW signals confirming the accuracy of the T-P knot algorithm.