We propose a new method for ventricular cancellation and atrial modelling in the ECG of patients suffering from atrial fibrillation. Our method is based on dictionary learning. It extends both the average beat subtraction and the sparse source separation approaches. Experiments on synthetic data show that this method can almost completely suppress the ventricular activity, but it generates some artifacts. Contrary to other ventricular cancellations methods, our approach also learns a model for the atrial activity.