A method is provided of analyzing a cardiac electrogram using a computer. In one step, a determination is made as to a plurality of cycle lengths between a plurality of activation peaks of the cardiac electrogram. In another step, a determination is made as to whether a mean of the plurality of cycle lengths meets at least one criteria. The method may be used to iteratively adjust a detection threshold level for detecting atrial fibrillation based on the cardiac electrogram.