Detection of the QRS complex is regarded as a baseline procedure for the segmentation of electrocardiographic (ECG) signals, as it is usually the most distinctive component of the signal and with the largest amplitude. Commonly, from the detection of the R peak, a backward and forward search is carried out to find the other components, which are P-wave, T-wave, and sometimes U-wave. Therefore, the QRS complex detector as a heartbeat indicator is useful for obtaining the RR interval measurement, a parameter associated with the heart rate variability (HRV), which is involved in arrhythmia detection routines. Accordingly, it is imperative that the QRS complex can be identified from heterogeneous morphology, which can occur in arrhythmias such as flutter, as well as atrial and ventricular fibrillation. Unfortunately, many QRS detection algorithms do not work well in pathological heartbeats, where the morphology of the QRS complex changes radically, and very often, ectopic beats are presented. This paper addresses QRS detection by using a novel methodology consisting of a recursive estimation of the ECG signal envelope through the Kalman Filter and smoothness priors. This approach effectively allows the estimation of R peaks, with similar performance to other methods highlighted in the state of the art, as it considers a time-dependent adaptive threshold independent of the morphology of the heartbeat, in order to achieve a robust detection. For validating this methodology, the MIT-BH, ST-T, and AASC recordings were used. A global accuracy of 99.3% was achieved with a sensitivity value of 99.5%. The experimental results demonstrate the improvement of the proposed Kalman filter over other outstanding methods; showing that the performance of the methodology is stable both in the presence of powerline noise, such as baseline wandering, maintaining a high performance as the noise level increases.