A method and medical device for identifying a cardiac waveform that includes sensing cardiac signals, determining a plurality of RR-intervals in response to the sensed cardiac signals, determining R-waves associated with the plurality of RR-intervals, determining P-waves in response to the determined R-waves, determining parameters associated with each P-wave, determining relative changes of the P-waves in response to the determined parameters, determining whether each of the P-waves match within a match threshold in response to the determined relative changes, and generating a P-wave template in response to each of the P-waves matching within the match threshold.