Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. close all;clear;clc;
  2. [sig fs] = importZephyrData();
  3. esize=30
  4. sig = sig(floor(length(sig)/2-((fs*esize)/2)) : floor(length(sig)/2+((fs*esize)/2))-1);
  5.  
  6. N=length(sig);
  7. %fs=200;
  8. t=[0:N-1]/fs;
  9. figure(1);subplot(4,2,1);plot(sig)
  10. title('Original Signal')
  11.  
  12. %%
  13. % Low Pass Filter
  14.  
  15. b=1/32*[1 0 0 0 0 0 -2 0 0 0 0 0 1];
  16. a=[1 -2 1];
  17. sigL=filter(b,a,sig);
  18. subplot(4,2,2);plot(sigL)
  19. title('Low Pass Filter')
  20.  
  21.  
  22. %%
  23. % High Pass Filter
  24.  
  25. b=[-1/32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1/32];
  26. a=[1 -1];
  27. sigH=filter(b,a,sigL);
  28. subplot(4,2,3);plot(sigH)
  29. title('High Pass Filter')
  30.  
  31.  
  32. %%
  33. % Derivative Base Filter
  34.  
  35. b=[1/4 1/8 0 -1/8 -1/4];
  36. a=[1];
  37. sigD=filter(b,a,sigH);
  38. subplot(4,2,4);plot(sigD)
  39. title('Derivative Base Filter')
  40.  
  41.  
  42. %%
  43. % Squared
  44. sigD2=sigD.^2;
  45. subplot(4,2,5);plot(sigD2)
  46. title('Squared')
  47.  
  48.  
  49. %%
  50. qrsEx = sigD(1525:1600);
  51. [mpdict,~,~,longs] = wmpdictionary(numel(qrsEx),'lstcpt',{{'sym4',3}});
  52. figure
  53. plot(qrsEx)
  54. hold on
  55. plot(2*circshift(mpdict(:,11), [11 0]),'r')
  56. %axis tight
  57. legend('QRS Complex','Sym4 Wavelet')
  58. title('Comparison of Sym4 Wavelet and QRS Complex')
  59. %% This covers the passband shown to maximize QRS ener
  60. wt = modwt(sigD,5);
  61. wtrec = zeros(size(wt));
  62. wtrec(4:5,:) = wt(4:5,:);
  63. y = imodwt(wtrec,'sym4');
  64. %%
  65. y = abs(y).^2;
  66. [qrspeaks,locs] = findpeaks(y,t,'MinPeakHeight',0.0001,'MinPeakDistance',0.5);
  67.  
  68. figure
  69. plot(t,y)
  70. hold on
  71. plot(locs,qrspeaks,'ro')
  72. xlabel('Seconds')
  73. title('R Peaks Localized by Wavelet Transform with Automatic Annotations')
  74.  
  75. %%
  76. plot(tm(ann),y(ann),'k*')
  77. title('R peaks Localized by Wavelet Transform with Expert Annotations')
  78. %%
  79. figure
  80. plot(t,sigD2,'k--')
  81. hold on
  82. plot(t,y,'r','linewidth',1.5)
  83. plot(t,abs(sigD2).^2,'b')
  84. plot(t(ann),sigD2(ann),'ro','markerfacecolor',[1 0 0])
  85. set(gca,'xlim',[10.2 12])
  86. legend('Raw Data','Wavelet Reconstruction','Raw Data Squared', ...
  87. 'Location','SouthEast');
  88. xlabel('Seconds')
  89. %%
  90. [qrspeaks,locs] = findpeaks(sigD2.^2,t,'MinPeakHeight',0.35,...
  91. 'MinPeakDistance',0.150);
  92. %%
  93. % figure
  94. % plot(sig)
  95. % hold on
  96. % plot(-250*locs,sig(-250*locs),'ro')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement