Atrial fibrillation (AF) is the most frequently encountered cardiac arrhythmia and is often associated with other cardiovascular and cerebrovascular diseases, such as ischemic heart disease, chronic heart failure, and stroke. Automatic detection of AF by analyzing electrocardiogram (ECG) signals has an important application value. Using the contaminated and actual ECG signals, it is not enough to only analyze the atrial activity of disappeared P wave and appeared F wave in the TQ segment. Moreover, the best analysis method is to combine nonlinear features analyzing ventricular activity based on the detection of R peak. In this paper, to utilize the information of the P-QRS-T waveform generated by atrial and ventricular activity, frequency slice wavelet transform (FSWT) is adopted to conduct time-frequency analysis on short-term ECG segments from the MIT-BIH Atrial Fibrillation Database. The two-dimensional time-frequency matrices are obtained. Furthermore, an average sliding window is used to convert the two-dimensional time-frequency matrices to the one-dimensional feature vectors, which are classified using five machine learning (ML) techniques. The experimental results show that the classification performance of the Gaussian-kernel support vector machine (GKSVM) based on the Bayesian optimizer is better. The accuracy of the training set and validation set are 100% and 93.4%. The accuracy, sensitivity, and specificity of the test set without training are 98.15%, 96.43%, and 100%, respectively. Compared with previous research results, our proposed FSWT-GKSVM model shows stability and robustness, and it could achieve the purpose of automatic detection of AF.