当前位置:文档之家› 心电信号处理昆明理工大学

心电信号处理昆明理工大学

昆明理工大学信息工程与自动化学院学生实验报告(2016 —20 17 学年第二学期)课程名称:生物医学信号处理开课实验室:设备编号:实验日期:2018年5月30日一、实验目的1、对心电信号的记录、处理、心电信号的特点、心电信号的噪声抑制,工频干扰的抑制与基线纠漂有总体了解。

2、能利用MATLAB GUI设计简单的GUI程序。

二、实验原理1、心电信号的特点:心电信号具有近场检测的特点,离开人体表微小的距离,就基本上检测不到信号;心电信号通常比较微弱,至多为mV量级,且能量主要在几百赫兹以下;干扰即来自生物体内,如肌电干扰、呼吸干扰等,也来自生物体外,如工频干扰,信号拾取时因不良接地等引入的其他外来干扰等;干扰信号与心电信号本身频带重叠(如工频干扰等)。

2、工频干扰抑制:现在使用较多的方法是使用滤波器对工频干扰进行抑制。

3、基线漂移:基线漂移是因呼吸、肢体活动或运动心电图测试所引起的,故这样使得ECG信号的基准线呈现上下飘逸的情况。

三、实验内容1、对心电信号处理主程序:clear;close all;clc;load 100_ECG_0_20 //加载心电信号%%%Eliminate Baseline Drift //消除基线漂移s1=ECG_2; //把心电信号ECG-2赋给s1s2=smooth(s1,150); //利用移动平均法对s1做平滑处理ecgsmooth=s1-s2; //消除基线漂移%%%apply Wavelet Transform //应用小波变换[C,L]=wavedec(ecgsmooth,8,'db4'); //用db4对ecgsmooth进行8层分解,其中返回的近似和细节都存放在C中,L存放是近似和各阶细节系数对应的长度(阶数为4阶)[d1,d2,d3,d4,d5,d6,d7,d8]=detcoef(C,L,[1,2,3,4,5,6,7,8]); //提取小波的细节系数%%%Denoise //降噪,消除干扰[thr,sorh,keepapp]=ddencmp('den','wv',ecgsmooth); //返回小波除噪和压缩后的信号cleanecg=wdencmp('gbl',C,L,'db4',8,thr,sorh,keepapp);//通过门限阈值处理得到小波系数(执行降噪操作)%%%thresholding1 //取阈值max_value=max(cleanecg); //最大值(波峰)mean_value=mean(cleanecg); //最小值(波谷)threshold=(max_value-mean_value)/2; //最大值与最小值差的一半作为阈值%%%R detection algorithm//用R检测算法检测信号a5=appcoef(C,L,'db4',5);//取分解后的近似部分,也就是第5层低频系数C1=[a5;d5;d4;d3]; //L1=[length(a5);length(d5);length(d4);length(d3);length(cleanecg)];R_detect_signal=waverec(C1,L1,'db4'); //用二维小波分解的结果C1,L1重建信号R_detect_squared=R_detect_signal.^2; //对R检测信号求平方%%%Beat_Rate_Extraction_Algorithm //计算心率for a=1:length(R_detect_squared)if R_detect_squared(a)>thresholdR_detect_new(a)=R_detect_squared(a);ElseR_detect_new(a)=0;endendmean_R_detect=5*mean(R_detect_new);for q=1:length( R_detect_new)-1if R_detect_new(q)<mean_R_detectR_detect_new(q)=0;endendd=0;for b=1:length( R_detect_new)-1if ( R_detect_new(b)==0) & ( R_detect_new(b+1)~=0)d=d+1;indext(d)= b+1;endendfs_R_deetect=length(R_detect_new)/20;time=indext.*1/fs_R_deetect;ind=0;for z=1:length(time)-1ind=ind+1;time_diff(ind)=time(z+1)-time(z);endav_time=mean(time_diff);Square_Number=av_time/.2;beat_Rate=300/Square_Number;high=max(R_detect_new);subplot(411);plot(s1);title('Orginal Signal'); //绘制原信号波形图subplot(412);plot(s1-s2);title('Baseline drift Elimination'); //绘制消除基线漂移波形图subplot(413);plot(cleanecg);title('Main Signal'); //绘制消除噪声之后的波形图subplot(414);plot(R_detect_new);title('R detected Signal'); //绘制R检测算法检测信号的波形图text(length(R_detect_new)/2,high,['Beat Rate =',num2str(fix(beat_Rate))],'EdgeColor','red'); //显示心率图1 运行结果在此信号处理过程中用到的处理算法有小波分解以及小波信号重构,用了Daubechies(dbN)小波,Daubechies小波简写为dbN,N是小波的阶数。

此程序中db4,表示小波阶数为4。

其流程图下:图2小波算法流程图2、利用matlab GUI平台设计相关GUI程序①GUI界面设置图3 GUI界面设置图②GUI程序:function varargout = untitled1(varargin)gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @untitled1_OpeningFcn, ...'gui_OutputFcn', @untitled1_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin&&ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});endfunction untitled1_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject;guidata(hObject, handles);function varargout = untitled1_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output;%%设置下拉菜单function popupmenu1_Callback(hObject, eventdata, handles)load100_ECG_0_20a=get(handles.popupmenu1,'value');switch acase 1s1=ECG_1;s2=smooth(s1,150);ecgsmooth=s1-s2;case 2s1=ECG_2;s2=smooth(s1,150);ecgsmooth=s1-s2;End%%绘制原信号波形图,并将图线设置为红色function popupmenu1_CreateFcn(hObject, eventdata, handles)if ispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction pushbutton1_Callback(hObject, eventdata, handles)load100_ECG_0_20a=get( handles.popupmenu1,'value')switch acase 1s1=ECG_1;case 2s1=ECG_2;endsubplot(411);plot(s1,'--r');title('Orginal Signal');%%绘制基线漂移的波形图,图线设置为绿色function pushbutton2_Callback(hObject, eventdata, handles)load100_ECG_0_20a=get(handles.popupmenu1,'value');switch acase 1s1=ECG_1;s2=smooth(s1,150);case 2s1=ECG_2;s2=smooth(s1,150);endsubplot(412);plot(s1-s2,'--g');title('Baseline drift Elimination'); %%绘制进行小波变换降噪之后的主信号波形图function pushbutton3_Callback(hObject, eventdata, handles)load100_ECG_0_20a=get( handles.popupmenu1,'value')switch acase 1s1=ECG_1;s2=smooth(s1,150);ecgsmooth=s1-s2;case 2s1=ECG_2;s2=smooth(s1,150);ecgsmooth=s1-s2;end[C,L]=wavedec(ecgsmooth,8,'db4');[d1,d2,d3,d4,d5,d6,d7,d8]=detcoef(C,L,[1,2,3,4,5,6,7,8]);[thr,sorh,keepapp]=ddencmp('den','wv',ecgsmooth);cleanecg=wdencmp('gbl',C,L,'db4',8,thr,sorh,keepapp);subplot(413);plot(cleanecg);title('Main Signal');%%绘制进行R检测之后的波形图function pushbutton4_Callback(hObject, eventdata, handles)load100_ECG_0_20a=get( handles.popupmenu1,'value')switch acase 1s1=ECG_1;s2=smooth(s1,150);ecgsmooth=s1-s2;case 2s1=ECG_2;s2=smooth(s1,150);ecgsmooth=s1-s2;end[C,L]=wavedec(ecgsmooth,8,'db4');[d1,d2,d3,d4,d5,d6,d7,d8]=detcoef(C,L,[1,2,3,4,5,6,7,8]);[thr,sorh,keepapp]=ddencmp('den','wv',ecgsmooth);cleanecg=wdencmp('gbl',C,L,'db4',8,thr,sorh,keepapp);max_value=max(cleanecg);mean_value=mean(cleanecg);threshold=(max_value-mean_value)/2;a5=appcoef(C,L,'db4',5);C1=[a5;d5;d4;d3];L1=[length(a5);length(d5);length(d4);length(d3);length(cleanecg)]; R_detect_signal=waverec(C1,L1,'db4');R_detect_squared=R_detect_signal.^2;for a=1:length(R_detect_squared)if R_detect_squared(a)>thresholdR_detect_new(a)=R_detect_squared(a);elseR_detect_new(a)=0;endendmean_R_detect=5*mean(R_detect_new);for q=1:length( R_detect_new)-1if R_detect_new(q)<mean_R_detectR_detect_new(q)=0;endendd=0;for b=1:length( R_detect_new)-1if ( R_detect_new(b)==0) & ( R_detect_new(b+1)~=0)d=d+1;indext(d)= b+1;endendfs_R_deetect=length(R_detect_new)/20;time=indext.*1/fs_R_deetect;ind=0;for z=1:length(time)-1ind=ind+1;time_diff(ind)=time(z+1)-time(z);endav_time=mean(time_diff);Square_Number=av_time/.2;beat_Rate=300/Square_Number;high=max(R_detect_new);subplot(414);plot(R_detect_new);title('R detected Signal'); function pushbutton7_Callback(hObject, eventdata, handles) global R_detect_newd=0;for b=1:length( R_detect_new)-1if ( R_detect_new(b)==0) & ( R_detect_new(b+1)~=0)d=d+1;indext(d)= b+1;endendfs_R_deetect=length(R_detect_new)/20;time=indext.*1/fs_R_deetect;ind=0;for z=1:length(time)-1ind=ind+1;time_diff(ind)=time(z+1)-time(z);endav_time=mean(time_diff);Square_Number=av_time/.2;beat_Rate=300/Square_Number;high=max(R_detect_new);set(handles.edit6,'string',num2str(fix(beat_Rate))); //文本编辑框中显示心率function edit6_Callback(hObject, eventdata, handles)function edit6_CreateFcn(hObject, eventdata, handles)if ispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end图4 GUI界面运行结果图。

相关主题