Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close all;clear;clc;
- [sig fs] = importZephyrData();
- esize=30
- sig = sig(floor(length(sig)/2-((fs*esize)/2)) : floor(length(sig)/2+((fs*esize)/2))-1);
- N=length(sig);
- %fs=200;
- t=[0:N-1]/fs;
- figure(1);subplot(4,2,1);plot(sig)
- title('Original Signal')
- %%
- % Low Pass Filter
- b=1/32*[1 0 0 0 0 0 -2 0 0 0 0 0 1];
- a=[1 -2 1];
- sigL=filter(b,a,sig);
- subplot(4,2,2);plot(sigL)
- title('Low Pass Filter')
- %%
- % High Pass Filter
- 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];
- a=[1 -1];
- sigH=filter(b,a,sigL);
- subplot(4,2,3);plot(sigH)
- title('High Pass Filter')
- %%
- % Derivative Base Filter
- b=[1/4 1/8 0 -1/8 -1/4];
- a=[1];
- sigD=filter(b,a,sigH);
- subplot(4,2,4);plot(sigD)
- title('Derivative Base Filter')
- %%
- % Squared
- sigD2=sigD.^2;
- subplot(4,2,5);plot(sigD2)
- title('Squared')
- %%
- qrsEx = sigD(1525:1600);
- [mpdict,~,~,longs] = wmpdictionary(numel(qrsEx),'lstcpt',{{'sym4',3}});
- figure
- plot(qrsEx)
- hold on
- plot(2*circshift(mpdict(:,11), [11 0]),'r')
- %axis tight
- legend('QRS Complex','Sym4 Wavelet')
- title('Comparison of Sym4 Wavelet and QRS Complex')
- %% This covers the passband shown to maximize QRS ener
- wt = modwt(sigD,5);
- wtrec = zeros(size(wt));
- wtrec(4:5,:) = wt(4:5,:);
- y = imodwt(wtrec,'sym4');
- %%
- y = abs(y).^2;
- [qrspeaks,locs] = findpeaks(y,t,'MinPeakHeight',0.0001,'MinPeakDistance',0.5);
- figure
- plot(t,y)
- hold on
- plot(locs,qrspeaks,'ro')
- xlabel('Seconds')
- title('R Peaks Localized by Wavelet Transform with Automatic Annotations')
- %%
- plot(tm(ann),y(ann),'k*')
- title('R peaks Localized by Wavelet Transform with Expert Annotations')
- %%
- figure
- plot(t,sigD2,'k--')
- hold on
- plot(t,y,'r','linewidth',1.5)
- plot(t,abs(sigD2).^2,'b')
- plot(t(ann),sigD2(ann),'ro','markerfacecolor',[1 0 0])
- set(gca,'xlim',[10.2 12])
- legend('Raw Data','Wavelet Reconstruction','Raw Data Squared', ...
- 'Location','SouthEast');
- xlabel('Seconds')
- %%
- [qrspeaks,locs] = findpeaks(sigD2.^2,t,'MinPeakHeight',0.35,...
- 'MinPeakDistance',0.150);
- %%
- % figure
- % plot(sig)
- % hold on
- % plot(-250*locs,sig(-250*locs),'ro')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement