How to debug Error in Pan Tompkins?
2 次查看(过去 30 天)
显示 更早的评论
I am getting the following error when the AF signal is passed in Pan Tompkins algorithm.
Error using filtfilt>getCoeffsAndInitialConditions (line 181)
Data length must be larger than 18 samples.
Error in filtfilt (line 96)
[b,a,zi,nfact,L] = getCoeffsAndInitialConditions(b,a,Npts);
Error in pan_tompkin2 (line 194)
ecg_h = filtfilt(a,b,ecg);
I have downloaded AF Signals (MIT-BIH Arrhythmia Database as .mat) from physiobank-atm from physionet.org. Could you help in debugging it?
3 个评论
Walter Roberson
2016-4-14
Instructions on downloading: http://www.mathworks.com/matlabcentral/answers/10331-how-to-open-mit-bih-arrhythmia-database-file-in-matlab
Walter Roberson
2016-4-14
For the Arrhythmia database, which "record" are you downloading? Are you downloading MLII or V5 ? On the MATLAB side, how are you loading the data into MATLAB, and how are you passing the data into pan_tomkin2?
My suspicion is that you might be trying to pass the name of the .mat instead of the content of the .mat
Shraddha Joshi
2016-4-15
编辑:Walter Roberson
2016-4-15
I have attached a signal sample which I have downloaded along with Pan tompkins code I am using. Signal is downloaded as
In the Pan Tompkins code attached below, in the lines 118 and 153, the command i have used to load signals is,
ecg=load('100.mat')
instead of
ecg=load('ECG_sample_noisy.mat')
采纳的回答
Walter Roberson
2016-4-15
matstruct = load('100m.mat');
ecg = matstruct.val;
That is, you need to use the .val variable within the .mat. When you load() a .mat like that, returning a value, the result is a struct in which the fields are the names of the loaded variables.
21 个评论
Shraddha Joshi
2016-4-15
Sir, when I tried including the above instructions you said, in the lines 118 and 119 of the program attached below, I got following error:
Error using pan_tompkin2 (line 122) ecg must be a row or column vector
I am not getting where exactly to provide the above instructions in the original Pan Tompkin Algorithm code. Can u please help me?
Walter Roberson
2016-4-15
matstruct = load('100m.mat');
ecg1 = matstruct.val(1,:);
ecg2 = matstruct.val(2,:);
Now ecg1 is the MLII signal and ecg2 is the V5 signal; process whichever one is appropriate for your purpose.
Shraddha Joshi
2016-4-16
Thank You Sir. It did help in getting the output. One more help i needed, there are a few MITBIH Afib sample signals that I have downloaded which I have enclosed in the attached folder below. How can I pass all these sample signals one after the other through Pan Tompkins Algorithm and check and store their rr interval values?
Shraddha Joshi
2016-4-17
Sir could u please help regarding above query at the earliset? How can the code correction be done to read all the mitbih afib signals one after the other through Pan tompkins algorithm and for each signal the rr interval calculated should be stored in a register or array?
Walter Roberson
2016-4-17
fs = 360; %according to the .info files
dinfo = dir('*.mat');
filenames = {dinfo.name};
nfiles = length(filenames);
results = cell(nfiles, 1);
for K = 1 : nfiles
thisfile = filenames{K};
matstruct = load(thisfile);
ecgs = matstruct.val;
for rownum = 1 : size(ecgs,1)
ecg = ecgs(rownum, :);
results{K,rownum} = pan_tompkin2(ecg, fs, ... whatever);
end
end
Even better would be to go through the header files and read out the frequency, but I did not bother; all the ones I looked at were 360 Hz.
Shraddha Joshi
2016-4-17
编辑:Shraddha Joshi
2016-4-17
Sorry for the inconvenience Sir. And yes the frequency is 360Hz for all signals. I tried with the above code but the error I am getting is
Undefined function or variable "ecgs".
Error in pan_tompkin2 (line 130) for rownum=1:size(ecgs,1);
What is this ecgs and how can I define it?
Shraddha Joshi
2016-4-18
Is it possible to calculate sensitivity and specificity for the above signals? If so can u please tell me how to do so?
Walter Roberson
2016-4-18
Sensitivity and specificity of what? You get back the R-wave indices and not much else. Do you have information about where the R-waves "really" are that you can compare against?
Shraddha Joshi
2016-4-18
编辑:Walter Roberson
2016-4-18
According to the code u have sent before which is as below, we are storing the results in results{K,rownum}.
fs = 360; %according to the .info files
dinfo = dir('*.mat');
filenames = {dinfo.name};
nfiles = length(filenames);
results = cell(nfiles, 1);
for K = 1 : nfiles
thisfile = filenames{K};
matstruct = load(thisfile);
ecgs = matstruct.val;
for rownum = 1 : size(ecgs,1)
ecg = ecgs(rownum, :);
results{K,rownum} = pan_tompkin2(ecg, fs, ... whatever);
end
end
So as this results{K,rownum} gives information about RR intervals, can't we calculate Sensitivity and Specificity of the Afib signals we are passing? Or is there any other way from which we can calculate sensitivity and specificity of the signals?
Walter Roberson
2016-4-18
You cannot calculate those without some information about what the accurate classification is. You could, for example, synthesize some data and put it through and then compare the results to the known values.
Shraddha Joshi
2016-4-18
编辑:Walter Roberson
2016-4-18
Suppose if I check these rr intervals stored in results{k,rownum} with some standard rr interval range for different kind of arrhythmia based on decision rules and classify them as normal or abnormal ecg signals and again in abnormal as Afib or other arrhythmia; will i be able to calculate sensitivity and specificity then? If so, how exactly can i do it through code?
Walter Roberson
2016-4-18
No, you need some information known to be true, not information that just had a different approximate classification method used. That information an be known to be true because you synthesized the information, or it can be known to be true by expert analysis of the signals.
You have the additional difficulty that your signal bounds are probably slightly fuzzy rather than sample-for-sample exact. You are sampling at 360 Hz, so if you have an event that takes less than 1/720 of a second to start, it could might legitimately get associated with either the sample #K or sample #(K-1). An expert looking at the plot might point to one particular sample one time as being the boundary, and the same expert might point to an adjacent sample the next time as being the same boundary. Especially in the presence of noise, it is often impossible to say that a particular sample is exactly the right boundary. Right at the calculated boundary it probably does not matter much whether the sample is inside or outside the boundary -- but (for example) 10 samples inside the boundary if you haven't yet agreed the boundary is there, then You Have A Problem that needs to be measured.
Some classification methods account for this by generating a confidence in their calculation, and then the statistical measures can be weighted by the confidence. But you do not appear to have that situation here.
Shraddha Joshi
2016-4-19
So there is absolutely no way of determining sensitivity and specificity for the signals above program? At least by considering no.of heart beats? Or else could you please suggest any other way which would help me to calculate them? I really needed this calculation in order for further analysis with my project studies. Hoping for the help.
Shraddha Joshi
2016-4-19
Or is there a way to check if the above signals passed are atrial fibrillation or no, based on heart rate calculation from rr intervals obtained ?
Walter Roberson
2016-4-19
Without some objective truth or expert analysis, your system might as well just be playing NumberWang
Shraddha Joshi
2016-4-19
So are you trying to say that there is no way to calculate heart rate from rr intervals found?
Walter Roberson
2016-4-19
I do not know anything about calculating heart rate from ecg signals. I do not know what rr intervals are. I was responding about sensitivity and specificity: to calculate those, you need information known by construction or expert opinion to be true.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 ECG / EKG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)