ECG signals are corrupted by several kinds of noise and artifacts, which negatively affect any subsequent analysis. In the literature, the only approach that can handle any noise and artifacts corrupting the ECG is linear time-invariant filtering. However, it suffers from some important limitations regarding effectiveness and computational complexity. In this paper we propose a novel framework for ECG signal preprocessing based on the notion of quadratic variation reduction. The framework is very general, since it can cope with all the different kinds of noise and artifacts that corrupt ECG records. It relies on a single algorithmic structure, thus enjoying an easy and robust implementation. Results show that the framework is effective in improving the quality of ECG, while preserving signal morphology. Moreover, it is very fast, even on long recordings, thus being perfectly suited for real-time applications and implementation on devices with reduced computational power, such as handheld devices.