A method includes retrieving a signal that measures an activity of a cardiac system. A heart beat model is created based on the retrieved signal, and heart beats are detected using the heart beat model. The model can be trained using a machine learning technique and also respiratory cycle phase information can be used in training the model. A related algorithm, apparatus and computer program are also included.