This article is to propose an algorithm for improving T-wave ends location during atrial fibrillation (AF). The traditional algorithms do not take the irregular baseline fibrillation of AF into consideration, so their location accuracy is relatively low. Based on simple assumptions that AF is a random signal while T waves and QRS complexes are deterministic signals, we suggest a novel method to suppress f wave for improving location of T-wave ends during AF. We firstly define a new cardiac cycle and then match R peaks and T peaks in the three adjacent cardiac cycles. Finally, we suppress the interference of the f wave by averaging. When evaluating with the PhysioNet QT database and simulated AF signals in terms of the mean and the standard deviation of the T-wave ends location errors, the proposed algorithm improves the performance of existing popular methods. Besides, the clinical significance of the proposed method is illustrated.