How would I find the median RR interval in an ECG signal?
조회 수: 18 (최근 30일)
이전 댓글 표시
If I have an ECG signal (.mat) that is sampled at 500 samples per second over 100 seconds, how would one calculate the median RR interval using findpeaks?
댓글 수: 0
답변 (1개)
Star Strider
2022년 10월 30일
Perhaps this —
Fs = 500;
t = linspace(0, 100, 100*Fs)/Fs;
EKG = randn(size(t));
[pks, locs] = findpeaks(EKG, 'MinPeakProminence',5);
tv = t(locs);
RR = diff(tv);
RRmed = median(RR)
figure
histogram(RR)
xline(RRmed, '--', 'Median')
It would help to have the EKG record. I just used a random normal vector here.
.
댓글 수: 3
Star Strider
2022년 10월 30일
The ‘5’ is the 'MinPeakProminence' value, chosen to fit the random data in ‘EKG’.
Yopu have to choose it to be appropriate to your EKG vector so that it detects only the R-deflections and not the P or T deflections (or noise).
William Rose
2022년 11월 3일
If the EKG signal is clean, you can use findpeaks() to find the R waves and the times of the R waves ([pks,locs]). This is what @Star Strider, M.D., did. Their signal was Gaussian white noise with mean=0, sd=1. You will have to find the parameters for findpeaks() that give reasonable results, i.e. which actually find the R waves. Do this by testing your algorithm on a 30 second segment, and plotting the EKG and the [pks,locs] found with findpeaks(). Once it looks reasonable, do it with the full length signal. Again, plot the signal and the [pks,locs], to check for reasonableness. Then you find (N-1) R-R intervals as the difference in (N) successive R wave times. Plot the (N-1) RR intervals versus the time of the first N-1 R waves. Does the plot look reasonable? If a few RR intervals are twice a big as the majority, you probably missed a few R waves. If a few RR intervals are much shorter than realistic, you are getting some false detections. Once you have fixed thise issues by appropriate choice of parameters for findpeaks(), you can find the median of the vector of R-R intervals.
If you are getting NaN, it probably means findpeaks() didn't find any peaks. That would happen if you specify a threshold, or a minPeakProminence, of five, and your signal amplitude never exceeds 1, for example.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!