通过计算心电R波波峰对应时间的一阶差分,得到HRV特征信号。
HRV(i)=R(i+1)-R(i)
其中,i为R波位置的采样点,R(x)为x点的采样时间,即R(x)=x/f
hrvy=diff(rvalue)*(1/800);
subplot(2,1,1);
plot(x);
hold on;
plot(rvalue,x(rvalue),'r^');
subplot(2,1,2);
lenhrv=length(hrvy);
plot(1:lenhrv,hrvy,'b');
SDNN=std(hrvy,1);%SDNN
rrdx=abs(diff(hrvy));
rMSSD=rms(rrdx);%rMSSD
nn50=find(rrdx>0.05);
pNN50=length(nn50)/length(rrdx);%pNN50
hrvy=diff(rvalue)*(1/800);
lenhrv=length(hrvy);%HRV的采样点数(5min内)
fs=lenhrv/300;%HRV的采样频率
nfft=lenhrv;
window=hamming(100);
noverlap=20;
range='onesided';
[Pxx,f]=pwelch(hrvy,window,noverlap,nfft,fs,range);
subplot(2,1,2)
plot(f,(Pxx),'b');
hold on;
plot([0.04,0.04],[0,1],'r');
area(f(f>=0.04&f<=0.15),Pxx(f>=0.04&f<=0.15),'FaceColor','r');
plot([0.15,0.15],[0,1],'r');
ylim([0 0.04]);
subplot(2,1,1);
plot(hrvy);
HRV序列Poincare散点图
(参考自HRV非线性分析PoincarePlot:SD1,SD2计算算法)
sdx=hrvy;
sdx(end)=[];
sdy=hrvy;
sdy(1)=[];
figure(3);
subplot(2,1,1);
scatter(sdx,sdy,5,'filled');
ee=[];
for i=1:length(sdx)
e=abs(sdx(i)-sdy(i))/sqrt(2);
if e>0.1
ee=[ee;i];
end
end
for i=1:length(ee)
sdx(ee(i))=NaN;
sdy(ee(i))=NaN;
end
sdx(isnan(sdx))=[];
sdy(isnan(sdy))=[];
sd1=std(sdy-sdx)/sqrt(2);
sd2=std(sdy+sdx)/sqrt(2);
subplot(2,1,2);
scatter(sdx,sdy,3,'filled');
h=refline(1,0);
set(h,'color','red');
hold on;
ecc=axes2ecc(sd2,sd1);
[elat,elon]=ellipse1(0.6,0.6,[sd2 ecc],45);
plot(elat,elon);
(参考自基于小波熵的Matlab程序)
wpt=wpdec(hrvy,4,'db3');
plot(wpt);
for i=1:2^4
E(i)=sum(abs(wprcoef(wpt,[4,i-1])).^2);
end
E1=sum(E);
dim=length(E);
for i=1:dim
p(i)=E(i)/E1;
end
shang=-sum(p.*log(p));
完整代码
converted = table2array(converted);
testy=converted(1:240000,4);%5min
[swa,swd]=swt(testy,5,'db3');%平稳小波变换
%[swa,swd] = swt(X,N,'wname')中,X为变换对象,N为分解层数,matlab要求X的长度为2^N的整数倍
swd1=swd(1,:);%分解出的各层高频细节信号。下同
swd2=swd(2,:);
swd3=swd(3,:);
swd4=swd(4,:);
swd5=swd(5,:);
m1=abs(swd1);
me1=median(m1);
o1=me1/0.6754;
thr1=o1*(2*log(2000))^0.5;%对各层进行噪声的方差估计,确定各层信号的阈值门限。下同
m2=abs(swd2);
me2=median(m2);
o2=me2/0.6754;
thr2=o2*(2*log(2000))^0.5;
m3=abs(swd3);
me3=median(m3);
o3=me3/0.6754;
thr3=o3*(2*log(2000))^0.5;
m4=abs(swd4);
me4=median(m4);
o4=me4/0.6754;
thr4=o4*(2*log(2000))^0.5;
m5=abs(swd5);
me5=median(m5);
o5=me5/0.6754;
thr5=o5*(2*log(2000))^0.5;
y1=wthresh(swd1,'h',thr1);%对各层进行硬阈值处理。下同
y2=wthresh(swd2,'h',thr2);
y3=wthresh(swd3,'h',thr3);
y4=wthresh(swd4,'h',thr4);
y5=wthresh(swd5,'h',thr4);
swd(1,:)=y1;
swd(2,:)=y2;
swd(3,:)=y3;
swd(4,:)=y4;
swd(5,:)=y5;
x=iswt(swa,swd,'db3');
%——心电信号去噪完成后——
yabs=abs(x);
sigtemp=x;
siglen=length(x);
sigmax=[];
for i=1:siglen-2
if (x(i+1)>x(i)&x(i+1)>x(i+2))|(x(i+1)thr
rvalue=[rvalue;sigmax(i,2)];
end
end
rvalue_1=rvalue;
%排除误检,如果相邻两个极大值间距小于0.4s,则去掉幅度较小的一个
lenvalue=length(rvalue);
i=2;
while i<=lenvalue
if (rvalue(i)-rvalue(i-1))*(1/800)<0.3
if yabs(rvalue(i))>yabs(rvalue(i-1))
rvalue(i-1)=[];
else
rvalue(i)=[];
end
lenvalue=length(rvalue);
i=i-1;
end
i=i+1;
end
lenvalue=length(rvalue);
% 在原信号上精确校准
for i=1:lenvalue
if (x(rvalue(i))>0)
k=(rvalue(i)-5):(rvalue(i)+5);
[a,b]=max(x(k));
rvalue(i)=rvalue(i)-6+b;
else
k=(rvalue(i)-5):(rvalue(i)+5);
[a,b]=min(x(k));
rvalue(i)=rvalue(i)-6+b;
end
end
hrvy=diff(rvalue)*(1/800);
lenhrv=length(hrvy);%HRV的采样点数(5min内)
fs=lenhrv/(240000/800);%HRV的采样频率
SDNN=std(hrvy,1);%SDNN
rrdx=abs(diff(hrvy));
rMSSD=rms(rrdx);%rMSSD
SDSD=std(rrdx,1);%SDSD
nn50=find(rrdx>0.05);
pNN50=length(nn50)/length(rrdx);%pNN50
nfft=lenhrv;
window=hamming(lenhrv);
noverlap=10;
range='onesided';
[Pxx,f]=pwelch(hrvy,window,noverlap,nfft,fs,range);
subplot(2,1,2)
plot(f,(Pxx),'b');
hold on;
plot([0.04,0.04],[0,1],'r');
area(f(f>=0.04&f<=0.15),Pxx(f>=0.04&f<=0.15),'FaceColor','r');
plot([0.15,0.15],[0,1],'r');
%xlim([0.02,1]);
%ylim([0 0.2]);
subplot(2,1,1);
plot(hrvy);
tp=bandpower(Pxx,f,'psd');
plf=bandpower(Pxx,f,[0.04,0.15],'psd');
phf=bandpower(Pxx,f,[0.15,0.4],'psd');
lfhf=plf/phf;
figure(2);
subplot(2,1,1);
plot(x);
hold on;
plot(rvalue,x(rvalue),'r^');
subplot(2,1,2);
plot(hrvy);
sdx=hrvy;
sdx(end)=[];
sdy=hrvy;
sdy(1)=[];
figure(3);
subplot(2,1,1);
scatter(sdx,sdy,5,'filled');
ee=[];
for i=1:length(sdx)
e=abs(sdx(i)-sdy(i))/sqrt(2);
if e>0.1
ee=[ee;i];
end
end
for i=1:length(ee)
sdx(ee(i))=NaN;
sdy(ee(i))=NaN;
end
sdx(isnan(sdx))=[];
sdy(isnan(sdy))=[];
sd1=std(sdy-sdx)/sqrt(2);
sd2=std(sdy+sdx)/sqrt(2);
subplot(2,1,2);
scatter(sdx,sdy,3,'filled');
h=refline(1,0);
set(h,'color','red');
hold on;
ecc=axes2ecc(sd2,sd1);
[elat,elon]=ellipse1(0.6,0.6,[sd2 ecc],45);
plot(elat,elon);
wpt=wpdec(hrvy,4,'db3');
plot(wpt);
for i=1:2^4
E(i)=sum(abs(wprcoef(wpt,[4,i-1])).^2);
end
E1=sum(E);
dim=length(E);
for i=1:dim
p(i)=E(i)/E1;
end
shang=-sum(p.*log(p));