/lib/Aubt/aubt_detecPQST.m

http://siento.googlecode.com/ · MATLAB · 82 lines · 37 code · 10 blank · 35 comment · 5 complexity · 08607dcdbbcff40b7d7c6ffdcdf0ae9c MD5 · raw file

  1. function [pind, qind, sind, tind] = aubt_detecPQST (signal, hz, rind)
  2. % Expects an ECG signal and a corresponding vector with the fiducial
  3. % locations of the r-waves as input and tries to detected the position of the
  4. % P and T waves and the Q and S peak. Therefore positive and negative peaks
  5. % on both sides of each r location are seeked. To achieve better results
  6. % this is done in the approximation of a wavelet decomposition.
  7. % Decomposition is done without downsampling. The algorithm is quite
  8. % similar to that proposed by S.C. Saxena, et al:
  9. %
  10. % "Feature extraction from ECG signals using
  11. % wavelet transforms for disease diagnostics",
  12. % International Journal of Systems Science,
  13. % 2002, volume 33, number 13, pages 1073–1085
  14. %
  15. % [pind, qind, sind, tind] = aubt_detecPQST (signal, hz, rind)
  16. %
  17. % input:
  18. % signal the ECG signal
  19. % hz sample rate of the signal
  20. % rind fiducial points of the r waves
  21. %
  22. % output:
  23. % pind a column vector containing the detected p wave indeces
  24. % qind a column vector containing the detected q peak indeces
  25. % sind a column vector containing the detected s peak indeces
  26. % tind a column vector containing the detected t wave indeces
  27. %
  28. %
  29. % 2005, Johannes Wagner <go.joe@gmx.de>
  30. order = 2;
  31. flow = [-0.001077301084996,0.004777257511011,0.000553842200994,-0.031582039318031,0.027522865530016,0.097501605587079,-0.129766867567096,-0.226264693965169,0.315250351709243,0.751133908021578,0.494623890398385,0.11154074335008]; % db6
  32. % tic
  33. len = length (signal);
  34. cA = aubt_lowdwt (signal, flow);
  35. for i = 2:order
  36. cA = aubt_lowdwt (cA, flow);
  37. end
  38. % org = 0.05
  39. qrswin = round (0.05 * hz);
  40. pwin = 0.25; % percent of rr interval
  41. twin = 0.4; % percent of rr interval
  42. for i = 1:length (rind)
  43. [maxval, maxind] = max (cA(max (1, rind(i)-qrswin):min (rind(i)+qrswin, len)));
  44. rind(i) = maxind + max (1, rind(i)-qrswin) - 1;
  45. end
  46. qind = zeros (length (rind)-2, 1, 'uint32');
  47. sind = zeros (length (rind)-2, 1, 'uint32');
  48. pind = zeros (length (rind)-2, 1, 'uint32');
  49. tind = zeros (length (rind)-2, 1, 'uint32');
  50. for i = 2:length (rind)-1
  51. % q peak
  52. r = rind(i);
  53. while cA(r) - cA(r-1) > 0
  54. r = r - 1;
  55. end
  56. qind(i-1) = r;
  57. % s peak
  58. r = rind(i);
  59. while cA(r) - cA(r+1) > 0
  60. r = r + 1;
  61. end
  62. sind(i-1) = r;
  63. % p peak
  64. qwinstart = round (qind(i-1) - pwin * (rind(i)-rind(i-1)));
  65. [maxval, maxind] = max (cA(qwinstart:qind(i-1)));
  66. pind(i-1) = qwinstart + maxind - 1;
  67. % t peak
  68. twinend = round (sind(i-1) + twin * (rind(i+1)-rind(i)));
  69. [maxval, maxind] = max (cA(sind(i-1):twinend));
  70. tind(i-1) = sind(i-1) + maxind - 1;
  71. end
  72. % toc