A hidden Markov model (HMM) is employed to improve noise robustness when tracking the dominant frequency of atrial fibrillation (AF) in the electrocardiogram (ECG). Following QRST cancellation, a sequence of observed frequency states is obtained from the residual ECG, using the short-time Fourier transform. Based on the observed state sequence, the Viterbi algorithm retrieves the optimal state sequence by exploiting the state transition matrix, incorporating knowledge on AF characteristics, and the observation matrix, incorporating knowledge of the frequency estimation method and signal-to-noise ratio (SNR). The tracking method is evaluated with simulated AF signals to which noise, obtained from ECG recordings, has been added at different SNRs. The results show that the use of HMM improves performance considerably by reducing the rms error associated with frequency tracking: at 4-dB SNR, the rms error drops from 0.2 to 0.04 Hz.