This work addresses the automatic segmentation of neonatal phonocardiogram (PCG) to be used in the artificial intelligence-assisted diagnosis of abnormal heart sounds. The proposed novel algorithm has a single free parameter - the maximum heart rate. The algorithm is compared with the baseline algorithm, which was developed for adult PCG segmentation. When evaluated on a large clinical dataset of neonatal PCG with a total duration of over 7h, an F1 score of 0.94 is achieved. The main features relevant for the segmentation of neonatal PCG are identified and discussed. The algorithm is able to increase the number of cardiac cycles by a factor of 5 compared to manual segmentation, potentially allowing to improve the performance of heart abnormality detection algorithms.