www.pudn.com > PulseProcessSystem.rar > PulseProcessSystem.asv, change:2013-01-11,size:8952b


%% Program Start
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 名称:医学信号处理课程设计——脉搏信号处理系统v1.0
%% 功能:对采集到的脉搏信号进行去噪等处理,然后提取出脉搏信号的周期,计算脉率及存档!
%% 作者肖国敏   学号:20121913024t
%% 单位:重庆大学生物医学工程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% 1                                                       系统界面生成
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = PulseProcessSystem(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @PulseProcessSystem_OpeningFcn, ...
                   'gui_OutputFcn',  @PulseProcessSystem_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
function PulseProcessSystem_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
function varargout = PulseProcessSystem_OutputFcn(hObject, eventdata, handles) 
%% 2                                                       脉搏信号导入
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function pushbutton1_Callback(hObject, eventdata, handles)%载入文件
[filename,filepath]=uigetfile('C:\Users\sharmee\Desktop\PulseProcessSystem\XG_MaiBo01.txt');
filename=[filepath,filename];
[t,Pluse_pre]=textread(filename,'%f%f','headerlines',1);%读入2个浮点值,并跳过文档的第1行
[m,n]=size(Pluse_pre);
n=3;
s3=Pluse_pre;
for i=1:1:n
    s1=Butter(s3);%巴特沃斯滤波器
    s2=Xnoise(s1);
    s3=xianbo(s2);
end
Pluse_post=s3;
date3=s3;

Pluse_post=s3;
handles.m=m;
handles.t=t;
handles.Pluse_pre=Pluse_pre;
handles.Pluse_post=Pluse_post;
handles.filepath=filepath;
handles.date3=date3;
guidata(hObject, handles);


%% 3                                                      原始信号回放
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 function pushbutton6_Callback(hObject, eventdata, handles) 
m=handles.m;
Pluse_pre=handles.Pluse_pre;
Pluse_post=handles.Pluse_post;
t=1:m-1000;
xmin1=min(Pluse_pre);
xmax1=max(Pluse_pre);

axes(handles.axes1); 
for j=800:100:5000
    
    plot(t,Pluse_pre(t));%title('原始脉搏信号回放');
    axis([j-800 800+j xmin1 xmax1]);grid on;
   pause(0.1)
end
guidata(hObject, handles);




%% 4                                                      处理后脉搏信号回放
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton7_Callback(hObject, eventdata, handles)
m=handles.m;
Pluse_pre=handles.Pluse_pre;
Pluse_post=handles.Pluse_post;
t=1:m-1000;
xmin1=min(Pluse_pre);
xmax1=max(Pluse_pre);

axes(handles.axes2); 
for j=800:100:5000
    
    plot(t,Pluse_post(t));%title('处理后脉搏信号回放);
    axis([j-800 800+j xmin1 xmax1]);grid on;
   pause(0.1)
end
guidata(hObject, handles);

%% 5                                                      脉率计算
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton3_Callback(hObject, eventdata, handles)

date3=handles.date3;
t=handles.t;

ge=max(size(date3));
t=t(1:ge,:);
%%%求取峰值
date4=zeros(max(size(date3)),1);
for i=1:max(size(date3));
    if date3(i)>0;
        date4(i)=date3(i);
    else
    date4(i)=0;
    end
end
for j=1:35;
    for i=1:size(date4)-j;
        if date4(i)<=date4(i+j);
            date4(i)=0;
        end
    end
end
for j=1:35;
    for i=1:size(date4)-j;
        if date4(i)>=date4(i+j);
           date4(i+j)=0;
        end
    end
end
%变为0-1序列
 n1=max(size(date4));
    for i=1:n1
        if date4(i)>=0.6
            date4(i)=1;
        else date4(i)=0;
        end
    end
%计算脉搏信号周期及脉搏率
t0=find(date4~=0);
t0_1=t0(2:size(t0)-1);
t0_2=t0(3:size(t0));
T=(t0_2-t0_1)*0.0025;
mailv=60./T;
mailv_max=max(mailv);
mailv_min=min(mailv);
mailv_average=mean(mailv);
mailv_std=std(mailv);%计算标准差
set(handles.edit2, 'String', mailv_average);
set(handles.edit3, 'String',mailv_std);
set(handles.edit4, 'String',mailv_min);
set(handles.edit5, 'String',mailv_max);
axes(handles.axes3);
count=max(size(mailv));

xlabel('Time / s');ylabel('Number / times');
for j=1:1:count-2
    set(handles.edit1,'String',mailv(j));
    plot((1:count),mailv(1:count),'-o');%title('预处理后的心电信号回放');
    axis([j-1 j+1 1 160]);grid on;hold on;
     plot([1,count],[100,100],'r','linewidth',2);
     plot([1,count],[60,60],'g','linewidth',2);
    pause(0.1);
end
handles.mailv=mailv;
guidata(hObject, handles);









%% 6                            滤波器设计
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 低通滤波器
function y=Butter(x)
fp=100;fs=200;Fs=400;
Rp=3;Rs=60;
Wp=2*pi*fp/Fs;    %滤波器性能指标
Ws=2*pi*fs/Fs;
Fs=Fs/Fs;%let Fs=1
wap=tan(Wp/2);was=tan(Ws/2);
[n,Wn]=buttord(wap,was,Rp,Rs,'s')%用于计算巴特沃斯数字滤波器的阶数N和3dB截止频率Wn。
[z,p,k]=buttap(n);
[bp,ap]=zp2tf(z,p,k);
[bs,as]=lp2lp(bp,ap,wap);
[bz,az]=bilinear(bs,as,Fs/2);
y=filter(bz,az,x);

%去噪
function data=Xnoise(d)
d1=d(1:48480);
[swa,swd]=swt(d1,5,'coif4');%计算等级N的信号X的平稳小波分解,使用'coif4'小波基。
[thr,sorh]=ddencmp('den','wv',d1);
dswd=wthresh(swd,sorh,thr);
data=iswt(swa,dswd,'coif4');

% 陷波器
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = xianbo(x)
wp=[0.12*pi,0.13*pi];ws=[0.124*pi,0.1255*pi];%调用参数wp,ws分别为数字滤波器的通带、阻带截止频率的归一化值,要求:0≤wp≤1,0≤ws≤1。1表示数字频率pi。
Ap=1;As=30;%分别为通带最大衰减和阻带最小衰减(dB)。
[N,Wc]=buttord(wp/pi,ws/pi,Ap,As);%用于计算巴特沃斯数字滤波器的阶数N和3dB截止频率wc。
[b,a]=butter(N,Wc,'stop');%巴特沃斯陷波器
y=filter(b,a,x);%filter是一维数字滤波器,输入X为滤波前序列,Y为滤波结果序列,B/A 提供滤波器系数,B为分子, A为分母 



%% 7                                                     数据存储——存储脉搏信号数据记录
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function pushbutton8_Callback(hObject, eventdata, handles)
file=handles.mailv;
fid=fopen('PulseRate.txt','wt');
[m,n]=size(file);
hhh=waitbar(0,'将脉搏率保存到当前目录PulseRate.txt文件中');
for i=1:1:m
   waitbar(i/m, hhh, '将脉搏率保存到当前目录PulseRate.txt文件中');
    for j=1:1:n
        if j==n
            fprintf(fid,'%g\n',file(i,j));
        else
            fprintf(fid,'%g\t',file(i,j));
        end
    end
   
end
waitbar(i/m, hhh, '数据保存完毕!');
pause(1);
 close(hhh); 
fclose(fid);



%% 8                                                     数据显示
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%动态脉率显示
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%脉率平均值
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%脉率标准差
function edit3_Callback(hObject, eventdata, handles)
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%脉率最小值
function edit4_Callback(hObject, eventdata, handles)
function edit4_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


%脉率最大值
function edit5_Callback(hObject, eventdata, handles)
function edit5_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end