Artefacts can pose a big problem in the analysis of electrocardiogram (ECG) signals. Even though methods exist to reduce the influence of these contaminants, they are not always robust. In this work a new algorithm based on easy-to-implement tools such as autocorrelation functions, graph theory and percentile analysis is proposed. This new methodology successfully detects corrupted segments in the signal, and it can be applied to real-life problems such as for example to sleep apnea classification.