Monitoring vital signs of neonates can be harmful and lead to developmental troubles. Ballistocardiography, a contactless heart rate monitoring method, has the potential to reduce pain. But signal processing is uneasy due to noise, inherent physiological variability and artifacts (e.g. respiratory amplitude modulation and body position shifts). We propose a new detection of heartbeats using a dynamic time warping (DTW) template matching method. A heartbeat template is automatically trained and the most similar potential heartbeats in the signal are classified as heartbeats. Data normalizing and DTW steps overcome amplitude and time variability issues. The DTW template matching algorithm has been tested on a 20 to 50 minutes-long BCG records of ten healthy adults in noisy conditions. It is suitable for medical, real-time and low-cost applications.