How to find Peak to Peak delay?
조회 수: 2 (최근 30일)
이전 댓글 표시
How to find peak to peak delay of below shown ECG signals?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153077/image.jpeg)
The code to plot above ECG signal is
load 16786m; figure(); plot(val(1,:));
I also want to find peak to peak delay of another ECG signal shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153078/image.jpeg)
The code to plot above signal is
load 100m; figure(); plot(val(1,:));
Will the same code detect peak distances for both ECGs?
댓글 수: 2
채택된 답변
Star Strider
2016년 1월 6일
Using my own code:
D = load('16786m.mat'); % Read EKG File
EKG = D.val/200; % Gain From the ‘info’ File
Fs = 128; % Fs From the ‘info’ File
tv = linspace(0,size(EKG,2),size(EKG,2))/Fs; % Time Vector
[pks,t] = findpeaks(EKG(1,:), Fs, 'MinPeakHeight',1); % See ‘findpeaks’ Documentation
RR = diff(t); % RR Intervals (sec)
BBRate = 1./RR; % Beat-To-Beat Rate (Beats/sec)
Rate = mean(BBRate); % Mean Rate (Beats/sec)
figure(1)
plot(tv,EKG(1,:)) % Plot EKG
hold on
plot(t, pks, '+r') % Plot R Peaks
hold off
grid
xlabel('Time (s)')
ylabel('Amplitude (mV)')
legend('EKG', 'R', 'Location','SE')
댓글 수: 4
Star Strider
2016년 1월 6일
편집: Star Strider
2016년 1월 7일
My pleasure!
There’s a ‘Gain’ scaling value in the .info file:
Source: record nsrdb/16786 Start: [11:48:00.000]
val has 2 rows (signals) and 1280 columns (samples/signal)
Duration: 0:10
Sampling frequency: 128 Hz Sampling interval: 0.0078125 sec
Row Signal Gain Base Units
1 ECG1 200 0 mV
2 ECG2 200 0 mV
To convert from raw units to the physical units shown
above, subtract 'base' and divide by 'gain'.
For 16786, it’s 200, but it may change for others. One possibility for making making a ‘universal’ code might be to do something like this:
Gain = 200; % Gain From the ‘info’ File
Base = 0; % Baseline Value From ‘info’ File
EKG = (D.val-Base)/Gain; % Base & Gain Scaled EKG
Fs = 128; % Fs From the ‘info’ File
EKG_1 = EKG(1,:); % Choose Trace To Study
. . .
[pks,idx] = findpeaks(EKG_1, 'MinPeakHeight',max(EKG_1)/3);
See if the ‘1/Gain’ threshold works. (It would work in 16786.) There are several other options with findpeaks, but EKGs can vary considerably in morphology and RR intervals, so I hesitate to use other than the 'MinPeakHeioght' threshold values. I chose to divide the maximum by 3 in order to correct for any electrical alternans that may exist. Choose the value that works best for you. Any value between 2 and 3 should work. If there is considerable baseline drift, it will be necessary for you to design a Butterworth bandpass filter with a passband of about [5 45] Hz and a stopband of about [1 50] Hz. See How to design a lowpass filter for ocean wave data in Matlab? for my filter design and implementation procedure.
—————————————————————————————————————————————————
EDIT — GetEKGinfo
I’m certain this can be made more efficient, but it’s the best I can come up with just now. (At least some of the inefficiency is the result of my needing to set different variables in order to troubleshoot it, and some of it is just due to fatigue at this point.) It was quite definitely an educational experience for me!
It gets the information from the .info files and returns necessary information for plotting and analysing the EKG records. I only tested it on ‘16786m.info’, but if the others are all of similar format, it should work for them as well. The idea is to make my code more flexible, so that you can use it without having to look up and extract the .info data manually.
First, you need to save it in your MATLAB path as GetEKGinfo.m.
To use it in my code, the function call is:
[NrEKGs,EKG_RecLen,Gain,Base,Fs] = GetEKGinfo('16786m')
where ‘NrEKGs’ is the number of EKG records in the .mat file, ‘EKG_RecLen’ is the length of each EKG, and ‘Gain’, ‘Base’ and ‘Fs’ for each have already been defined. You can call the function in my code, and then assign the returned variables as necessary.
function [recnrs,reclen,gain,base,Fs] = GetEKGinfo(info_file_prefix)
fidi = fopen([info_file_prefix '.info']);
k1 = 0;
while ~feof(fidi)
k1 = k1 + 1;
Line{k1} = fgets(fidi);
units1 = strfind(Line{k1}, 'val has');
if ~isempty(units1)
[recst1,recend1] = regexp(Line{k1}, '\d*');
recnrs = str2num(Line{k1}(recst1(1):recend1(1)+1));
reclen = str2num(Line{k1}(recst1(2):recend1(2)));
end
units2 = strfind(Line{k1}, 'Sampling frequency:');
if ~isempty(units2)
[recst2,recend2] = regexp(Line{k1}, '\d*');
Fs = str2num(Line{k1}(recst2(1):recend2(1)+1));
end
units3 = strfind(Line{k1}, 'Row');
if ~isempty(units3)
for k2 = 1:recnrs
k1 = k1 + k2;
Line{k1} = fgets(fidi);
[recst3,recend3] = regexp(Line{k1}, '\d*');
gain(k2) = str2num(Line{k1}(recst3(3):recend3(3)));
base(k2) = str2num(Line{k1}(recst3(4):recend3(4)));
end
end
end
fclose(fidi);
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!