The invention relates to a method for automatic detection of atrial fibrillation and flutter. The solution is based on ECG analysis involving QRS complex detection and atrial fibrillation and flutter interval detection. Detection of atrial fibrillation and flutter detection requires the extraction of characteristics and classification of rr signals, which includes at least one analysis of local characteristics of the signals. The QRS detection and local rr signal characteristic analysis are performed by classifiers generated during machine learning.