Hi,
Your approach does not seem to work whenever the spacing of breaths is inconsistent. In such cases using a fixed "MinPeakDistance" like "Fs*(RespRate)/2" might not capture both phases reliably. Here are some steps you can try out to fix this:
- Use the "MinPeakProminence" property of "findpeaks" function with a suitable prominence value to make the peak detection better. You can refer to this link for more information about the same: https://www.mathworks.com/help/signal/ref/findpeaks.html#buff2uu:~:text=MinPeakProminence%20%E2%80%94%20Minimum%20peak%20prominence
- Use noise reduction techniques like smoothing or filtering before using "findpeaks".
- The following link might also be useful: https://www.mathworks.com/help/signal/ug/peak-analysis.html