The diffusion of wearable sensors enables the monitoring of heart physiology in real-life contexts. Wearable technology is characterized by important advantages but also by technical limitations that affect the quality of the collected signals in terms of movement artifacts and presence of noise. Therefore specific signal processing algorithms are required to cope with the lower quality and different characteristic of signals collected with wearable sensor units. Here we propose and validate a pipeline to detect heartbeats in cardiac signals, extract the Inter Beat Intervals (IBI) and compute the Heart Rate Variability (HRV) indicators from wearable devices. In particular, we describe the novel Derivative-Based Detection (DBD) algorithm to estimate the beat position in Blood Volume Pulse (BVP) signals and the Reverse Combinatorial Optimization (RCO) algorithm to identify and correct IBI extraction errors. The pipeline is first validated on data from clinical-grade sensors, then on a benchmark dataset including examples of movement artifacts in a real-life context. The accuracy of the DBD algorithm is assessed in terms of precision and recall of the detection; error in the IBI values is quantified by root mean square error. The reliability of HRV indicators is evaluated by the Bland-Altman ratio. The DBD algorithm performs better than a state-of-art algorithm for both medical-grade and wearable devices. However, as already found in similar studies, worse reliability is found with the BVP signal in computing frequency domain HRV indicators, in particular with wearable devices.