Cardiac imaging and electrophysiological measurements yield vast amounts of data that typically need to be processed automatically. However, the detection and segmentation of calcium transients or action potentials is complicated by signal noise or signal drift, which may cause both false positive and negative segmentation. This article presents a simple but accurate ‘comb’ algorithm for detection of calcium transients and action potentials in such data where the pattern of activation is regular and its frequency is known. This corresponds either to cases where the cardiac preparation is paced externally, or where the preparation is beating in a stable rhythm. The prior knowledge of the heart rate is leveraged to overcome a broad range of artefacts and complications which arise in experimental data, such as different types of noise, signal drift, or alternans. The algorithm is simple to implement and has only a single free parameter, which is furthermore simple to set. A Matlab/Octave implementation of the comb algorithm is provided.