Abstract—Detection of the primary sound components in heart sound signal is the first step in automated diagnosis of cardiac abnormality. Although most existing heart sound detection algorithms perform well in normal signals, they usually have no effect on signals with heart murmurs. In this paper, an algorithm based on energy is proposed for robust detection of the first and second heart sound. It improved preprocessing and energy formula in envelope-based algorithm to overcome the interference of noises, which include heart murmurs and background noises, and can detect the accurate boundaries of the first and second heart sounds by constructing time gates. The algorithm has been tested using normal and abnormal clinical data and compared with the normalized average Shannon energy algorithm. The results show that the algorithm has over 96 percent correct ratio. That is superior to the normalized average Shannon energy algorithm.