Electrocardiogram (ECG), as a noninvasive electrical recording of the heart rhythm, is one of the most reliable diagnostic tools for identifying patients with suspected myocardial infarction (MI). We propose a novel detection algorithm based on the use of simple pattern matching techniques in order to increase the accuracy of MI detection. The algorithm classifies the waveforms into five fundamental types of ECG. It then improves the detections using temporal correlation between successive ECG beats for further corrections. ST elevation is then calculated as the difference in magnitudes between the isoelectric line and the ST point and used as an indication of MI. The algorithm was tested using 20 MI patient data and resulted in a true QRS detection rate of 98.9%. The algorithm successfully classifies 199 out of 220 leads in 20 data sets into the five major groups. This proved to be a key step towards improving the accuracy of the algorithm as most of the waveforms belong to these major groups.