# How to detect S wave peaks in ecg

While there are plenty of methods to detect R peaks it appears that detecting S peaks is less discussed. Is there a recommended way of detecting S peaks?

Additionally, could you recommend an implementation in python?

• I know extremely little about this to provide any valuable insight, but doesn't the S wave always immediately follow the R wave (in the opposite direction)? Such that if you can detect the R wave you can use that information to more accurately locate the S wave? More of a question since I am not in the biomedical field. Mar 18 '20 at 2:28
• It does and I also think that detecting the R wave gives much information towards detecting the S wave. My concern is that this is more complex than it seems. Mar 23 '20 at 21:19

If you are using Python you could try this:

def S_point(signal, R_peaks):

num_peak=R_peaks.shape
S_point_list=list()
for index in range(num_peak):
i=R_peaks[index]
cnt=i
if cnt+1>=signal.shape:
break
while signal[cnt]>signal[cnt+1]:
cnt+=1
if cnt>=signal.shape:
break
S_point_list.append(cnt)
return np.asarray(S_point_list)


If you allready have the R-peaks then you can use the signal and the R-peaks to get the S_points with this function

S_points=S_point(signal,R_peaks)


And finaly plot it like this

plt.plot(signal)
plt.plot(R_peak,signal[R_peak], 'yo')
plt.plot(S_points,signal[S_points], 'ro') • Thank you for the detailed answer. So you're essentially looking for the nearest point to the right of the R-peak where the downward trend stops. What if this single switch point is a bug somehow and the actual trend continues downward? Is there a common practice for smoothing / checking a window instead of single values? Apr 21 '20 at 12:36