MATLAB: Why NAN happend when i use another signal

signal processingSignal Processing Toolbox

i am trying to detect S-wave in QRS complex and it works enough for me but i tryed for another ECG signal it dose not give me error buy the output of all procedure start from filtering to the end is NAn what is the wrong??

Best Answer

The signal you posted is not the signal in the plot you posted. (I do congratulate you on getting your R and S detection routines to work!)
I needed to do some analysis of the signal you posted, because you did not provide us with the sampling frequency (that appears to be 1kHz), and there are 423 ‘NaN’ values I had to dispose of that initially prevented me from calculating the fft.
You have significant amplitude 50Hz powerline noise in your signal (if I’m correct about the sampling frequency). You have to filter that out first. Since all important EKG information is far below that, a simple lowpass filter should work. I will leave the design and implementation of that filter to you, but the Signal Processing Toolbox can do everything you need.
Remember to always look at your data before you process it. At least plot it if that is appropriate, and if necessary, do an fft, summary statistics, or other appropriate analyses.
Filter your signal, and if you have problems finding the peaks in the filtered signal, post that signal, describe your problems, and we will do our best to help.