【信号处理】基于HMM的睡眠状态检测matlab源码

在每个睡眠阶段采集检测目标的睡眠生理信号,睡眠生理信号包括心率信号和呼吸信号;对呼吸信号进行预处理得到呼吸轮廓信号;对心率信号进行预处理得到心率周期的均匀时间序列;分别提取呼吸轮廓信号和均匀时间序列的特征信息,并根据预设的训练样本集获取该睡眠生理信号对应的先验知识;根据特征信息和先验知识以及检测目标的目标特征生成特征集合,并通过主成分分析法从特征集合中确定最优特征子集合得到检测样本;将检测样本与样本集训练得到的检测模型进行匹配,并根据匹配结果输出睡眠呼吸障碍检测信息。 

``` function varargout = SleepStatus(varargin) % SLEEPSTATUS MATLAB code for SleepStatus.fig % SLEEPSTATUS, by itself, creates a new SLEEPSTATUS or raises the existing % singleton. % % H = SLEEPSTATUS returns the handle to a new SLEEPSTATUS or the handle to % the existing singleton. % % SLEEPSTATUS('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SLEEPSTATUS.M with the given input arguments. % % SLEEPSTATUS('Property','Value',...) creates a new SLEEPSTATUS or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before SleepStatusOpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to SleepStatusOpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help SleepStatus

% Last Modified by GUIDE v2.5 21-Oct-2020 17:16:55

% Begin initialization code - DO NOT EDIT guiSingleton = 1; guiState = struct('guiName', mfilename, ... 'guiSingleton', guiSingleton, ... 'guiOpeningFcn', @SleepStatusOpeningFcn, ... 'guiOutputFcn', @SleepStatusOutputFcn, ... 'guiLayoutFcn', [] , ... 'guiCallback', []); if nargin && ischar(varargin{1}) guiState.gui_Callback = str2func(varargin{1}); end

if nargout [varargout{1:nargout}] = guimainfcn(guiState, varargin{:}); else guimainfcn(guiState, varargin{:}); end % End initialization code - DO NOT EDIT

% --- Executes just before SleepStatus is made visible. function SleepStatus_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to SleepStatus (see VARARGIN)

% Choose default command line output for SleepStatus handles.output = hObject;

set(handles.text2,'string','Sleep status detector','foregroundcolor','b','fontsize',20);

set(handles.pushbutton1,'String','打开文件'); set(handles.pushbutton2,'String','播放且判断'); set(handles.pushbutton3,'String','停止');

set(handles.edit1,'String','实时判断结果'); set(handles.edit2,'String','过往判断结果'); set(handles.edit2,'Max',10); set(handles.edit2,'Min',0);

cla(handles.axes1); cla(handles.axes2);

global player timercounter accuratetime nlast nlast1 allresult num player=[]; timercounter =0; accuratetime = 0; nlast =2; nlast1 =2; num =1; allresult={}; % Update handles structure guidata(hObject, handles);

% UIWAIT makes SleepStatus wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = SleepStatus_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure varargout{1} = handles.output;

% --- Executes on button press in pushbutton1. function pushbutton1Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global wavfilename timercounter allresult num [FileName,PathName] = uigetfile('*.wav','Select the wav-file'); if FileName==0 wavfilename =[]; return end wavfilename = [PathName,FileName]; [x,fs] = audioread(wavfilename); x = mean(x,2); axes(handles.axes1); plot(x); ylim([-1 1]); timercounter = 0; accuratetime =0; allresult={}; set(handles.edit2,'string',''); num = 1;

% --- Executes on button press in pushbutton2. function pushbutton2Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global wavfilename tAxis player myStruct startminute start_seconds if isempty(wavfilename) return end %default

durT = 3060; %seconds fs = 32000; durS = fsdurT; %samples

[x,fs] = audioread(wavfilename); x = mean(x,2); durT = size(x,1)/fs; durS = size(x,1);

dt = 1/fs; tAxis = dt:dt:durT;

frameRate = 25; %fps frameT = 1/frameRate;

mag = 1;

axes(handles.axes1); cla(handles.axes1); plot(tAxis, x); ylim([-mag mag]) xlim([0 durT]) xlabel('Time [s]')

playHeadLoc = 0; % hold on; ax = plot([0 playHeadLoc], [-mag mag], 'r', 'LineWidth', 2);

player = audioplayer(x, fs); myStruct.playHeadLoc = playHeadLoc; myStruct.frameT = frameT; myStruct.ax1 = handles.axes1; myStruct.ax2 = handles.axes2; myStruct.edit1 = handles.edit1; myStruct.edit2 = handles.edit2; tmr1 = timer('ExecutionMode', 'FixedRate', ... 'Period', 0.5, ... 'TimerFcn', {@timerCallback}); % tmr2 = timer('ExecutionMode', 'FixedRate', ... % 'Period', 0.1, ... % 'TimerFcn', {@timerCallback2}); handles.timer1 = tmr1; % handles.timer2 = tmr2;

guidata(hObject, handles);

starttime = clock(); startseconds = starttime(6); startminute = start_time(5);

start(tmr1); % start(tmr2);

playblocking(player); % play(player); if ~isplaying(player)
stop(handles.timer1); % stop(handles.timer2); end

% function timerCallback2(hObj, eventdata) % global accuratetime % accuratetime = accurate_time + 0.1;

function timerCallback(hObj, eventdata) global wavfilename myStruct tAxis timercounter accuratetime startminute startseconds nlast nlast1 allresult num [x1,fs] = audioread(wavfilename); x1= mean(x1,2); lengthmax = length(x1);

% timercounter = accuratetime;

starttime = clock(); seconds = starttime(6); minute = start_time(5);

timercounter = (minute*60+seconds)-(startminute*60+startseconds); % disp(timercounter) axes(myStruct.ax1); plot(tAxis,x1); line([timercounter timercounter],[-1 1],'color','r');

axis([tAxis(1) tAxis(end) -1 1]);

time1 = timer_counter; time2 = time1 + 1;%1s

idx1 = fix(fstime1); idx2 = fix(fstime2); if (idx1<1) idx1 = 1; end if(idx1>=lengthmax) idx1 = lengthmax; end if(idx2>=lengthmax) idx2 = lengthmax; end if(idx1>=idx2) return end x1 = x1([idx1:idx2]); axes(myStruct.ax2); plot(x1,'color',[1, 0.6732, 0]); axis([1 1*fs+1 -.5 .5]);

%判断结果 load hmm.mat addpath (genpath('HMMall'),'-end');

warning('off'); classfolder={'NormalBreathe','FastBreathe','Snore'}; ResultStr = classfolder; k = x1; datacell = MFCC(k,fs); % size(datacell) datacell = datacell'; for j=1:size(hmm,2) HMM = hmm{j};
loglik(j) = mhmm_logprob(datacell,HMM.prior, HMM.transmat, HMM.mu, HMM.Sigma, HMM.mixmat);%计算概率 end

[d,n] = max(loglik);

% fprintf('文件名:%s,识别结果:%s\n', [classfolder{i},'\',fname],char(ResultStr{n})); njudge = nlast1;%延迟1秒 if njudge ==1 set(myStruct.edit1,'string',[num2str(time1),' s: ',char(ResultStr{njudge})]); set(myStruct.edit1,'string',[num2str(time1),' s: ',char(ResultStr{njudge})]); set(myStruct.edit1,'foregroundcolor','r'); set(myStruct.edit1,'fontsize',20); allresult{num} = num2str(time1); num = num+1; set(myStruct.edit2,'string',allresult); set(myStruct.edit2,'foregroundcolor','r'); elseif(njudge==2) set(myStruct.edit1,'string',[num2str(time1),' s: ',char(ResultStr{njudge})]); set(myStruct.edit1,'foregroundcolor','g'); set(myStruct.edit1,'fontsize',20); else set(myStruct.edit1,'string',[num2str(time1),' s: ',char(ResultStr{njudge})]); set(myStruct.edit1,'foregroundcolor','b'); set(myStruct.edit1,'fontsize',20); end nlast1 = nlast; nlast = n; %结果留着下下次显示

rmpath (genpath('HMMall'));

warning('on'); % timercounter = accuratetime; % timercounter = timercounter + 0.5;

function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global player if ~isempty(player) stop(player); stop(handles.timer1); % stop(handles.timer2); end

% --- Executes when user attempts to close figure1. function figure1_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure delete(hObject); global player if ~isempty(player) stop(player); stop(handles.timer1); % stop(handles.timer2); end

function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double

% --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end ```

🎈 部分理论引用网络文献,若有侵权联系博主删除
👇 关注我领取海量matlab电子书和数学建模资料

🎁 私信完整代码和数据获取及论文数模仿真定制

🌈 各类智能优化算法改进及应用
生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化、背包问题、 风电场布局、时隙分配优化、 最佳分布式发电单元分配、多阶段管道维修、 工厂-中心-需求点三级选址问题、 应急生活物质配送中心选址、 基站选址、 道路灯柱布置、 枢纽节点部署、 输电线路台风监测装置、 集装箱调度、 机组优化、 投资优化组合、云服务器组合优化、 天线线性阵列分布优化、CVRP问题、VRPPD问题、多中心VRP问题、多层网络的VRP问题、多中心多车型的VRP问题、 动态VRP问题、双层车辆路径规划(2E-VRP)、充电车辆路径规划(EVRP)、油电混合车辆路径规划、混合流水车间问题、 订单拆分调度问题、 公交车的调度排班优化问题、航班摆渡车辆调度问题、选址路径规划问题、港口调度、港口岸桥调度、停机位分配、机场航班调度、泄漏源定位
🌈 机器学习和深度学习时序、回归、分类、聚类和降维

2.1 bp时序、回归预测和分类

2.2 ENS声神经网络时序、回归预测和分类

2.3 SVM/CNN-SVM/LSSVM/RVM支持向量机系列时序、回归预测和分类

2.4 CNN|TCN|GCN卷积神经网络系列时序、回归预测和分类

2.5 ELM/KELM/RELM/DELM极限学习机系列时序、回归预测和分类
2.6 GRU/Bi-GRU/CNN-GRU/CNN-BiGRU门控神经网络时序、回归预测和分类

2.7 ELMAN递归神经网络时序、回归\预测和分类

2.8 LSTM/BiLSTM/CNN-LSTM/CNN-BiLSTM/长短记忆神经网络系列时序、回归预测和分类

2.9 RBF径向基神经网络时序、回归预测和分类

2.10 DBN深度置信网络时序、回归预测和分类
2.11 FNN模糊神经网络时序、回归预测
2.12 RF随机森林时序、回归预测和分类
2.13 BLS宽度学习时序、回归预测和分类
2.14 PNN脉冲神经网络分类
2.15 模糊小波神经网络预测和分类
2.16 时序、回归预测和分类
2.17 时序、回归预测预测和分类
2.18 XGBOOST集成学习时序、回归预测预测和分类
2.19 Transform各类组合时序、回归预测预测和分类
方向涵盖风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、用电量预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断
🌈图像处理方面
图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知
🌈 路径规划方面
旅行商问题(TSP)、车辆路径问题(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问题、 充电车辆路径规划(EVRP)、 双层车辆路径规划(2E-VRP)、 油电混合车辆路径规划、 船舶航迹规划、 全路径规划规划、 仓储巡逻
🌈 无人机应用方面
无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配、无人机安全通信轨迹在线优化、车辆协同无人机路径规划
🌈 通信方面
传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化、水声通信、通信上传下载分配
🌈 信号处理方面
信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化、心电信号、DOA估计、编码译码、变分模态分解、管道泄漏、滤波器、数字信号处理+传输+分析+去噪、数字信号调制、误码率、信号估计、DTMF、信号检测
🌈电力系统方面
微电网优化、无功优化、配电网重构、储能配置、有序充电、MPPT优化、家庭用电
🌈 元胞自动机方面
交通流 人群疏散 病毒扩散 晶体生长 金属腐蚀
🌈 雷达方面
卡尔曼滤波跟踪、航迹关联、航迹融合、SOC估计、阵列优化、NLOS识别
🌈 车间调度
零等待流水车间调度问题NWFSP置换流水车间调度问题PFSP混合流水车间调度问题HFSP 、零空闲流水车间调度问题NIFSP、分布式置换流水车间调度问题 DPFSP、阻塞流水车间调度问题BFSP
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab科研辅导帮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值