This paper presents a method to detect and correct anomalies in embedded systems. The proposed method consists of three phases: 1) Training, 2) Anomaly detection, and 3) Anomaly Correction. In the training phase, the method constructs different clusters so that each cluster has a number of similar members, similarity values of the members for a cluster to each others are not less than a predefined similarity threshold. The similarity values are calculated by various similarity functions. During detection phase, if an event in testing data does not belong to any cluster, an anomaly is detected. In correction phase, some similarity functions are used which select a suitable sequence that meets the required constrains to be a normal sequence. Evaluation of the proposed method has been done based on correction coverage and hardware overheads such as power consumption, area, and delay overhead. The window size of corrector and the number of injected anomalies varied between 3 and 5, 1 and 7, respectively. The results of experiments on 7000 benchmarks show that this correction method can correct 70.36% of anomalies on the average. Power consumption, area, and delay overhead in cluster-based method are on average 318.47µw, 2.98µm2, and 0.09 ns, respectively.