We describe a clustering algorithm based on continuous Hidden Markov Models (HMM) to automatically classify both electrocardiogram (ECG) and intracranial pressure (ICP) beats based on their morphology. The algorithm detects, classifies and labels each beat based on morphology. In order to avoid the numerical problems with classical Expectation-Maximization (EM) algorithm we apply a novel method of simulated annealing (SIM) for HMM optimization. We show that better results are achieved using simulated annealing approach.