In order to permit a brain computer efficient communication, it is important to dispose of an efficient algorithm to decode the brain electrical activity. We will focus our attention on an algorithm based on microstates segmentation of the brain electrical activity. First of all, we are going to use electroencephalogram measurements (EEG, 10/20 international system) to collect the electrical activity of the brain. Each sixteen electrodes of the EEG will sample the data at the same rate, forming a matrix of measures. The algorithm is based on the hypothesis that a particular mental activity will generate momentary detectable potential scalp maps (Event Related Potentials, ERP). A mental activity can therefore be seen as a sequential organization of scalp maps, called microstates. To find the best microstates representing a particular mental activity is an exiting challenge. We are going to express the sets of data obtained through EEG as time series of nonoverlapping microstates with different intensities. The algorithm will then converge to a set of microstates representing the data with minimum error. Another inherent problem is that of the ideal number of microstate. How many scalp maps should we use to represent our set of data? The cross validation method is the more adequate for resolving this kind of problems. Applying this method to the data will give us an approximate number of states with a certain error. Improvements of the algorithm are also introduced. There were necessary to guarantee better results and more efficiency. Results are presented in the Comparison section, in which the qualities of the algorithm are underlined by some results analysis. We also compute its complexity and have created an indicator to improve our utilisation of the algorithm. The appendix provides the mathematical demonstrations of the algorithm formulas and focuses its attention on trying to explain all the difficult to understand concepts.