ALGORITHM FOR AUTOMATIC DETECTION OF ECG WAVES