Robust and exact automatic P wave detection and delineation in the electrocardiogram (ECG) is still an interesting but challenging research topic. The early prognosis of cardiac afflictions such as atrial fibrillation and the response of a patient to a given treatment is believed to improve if the P wave is carefully analyzed during sinus rhythm. Manual annotation of the signals is a tedious and subjective task. Its correctness depends on the experience of the annotator, quality of the signal, and ECG lead. In this work, we present a wavelet-based algorithm to detect and delineate P waves in individual ECG leads. We evaluated a large group of commonly used wavelets and frequency bands (wavelet levels) and introduced a special phase free wavelet transformation. The local extrema of the transformed signals are directly related to the delineating points of the P wave. First, the algorithm was studied using synthetic signals. Then, the optimal parameter configuration was found using intracardiac electrograms and surface ECGs measured simultaneously. The reverse biorthogonal wavelet 3.3 was found to be optimal for this application. In the end, the method was validated using the QT database from PhysioNet. We showed that the algorithm works more accurately and more robustly than other methods presented in literature. The validation study delivered an average delineation error of the P wave onset of -0.32±12.41 ms when compared to manual annotations. In conclusion, the algorithm is suitable for handling varying P wave shapes and low signal-to-noise ratios.