其他分享
首页 > 其他分享> > 【项目实战-MATLAB】:基于EMD的心音信号特征提取

【项目实战-MATLAB】:基于EMD的心音信号特征提取

作者:互联网

下载链接 https://download.csdn.net/download/qq_45047246/72786937

加载音频

在这里插入图片描述

傅里叶变换

MFCC特征提取

在这里插入图片描述

读入音频文件并将其转换为频率表示。
要提取mel频率倒谱系数,使用频域音频调用mfcc。
小波变换
wrcoef

从一维小波系数重构

x=wrcoef(type,c,l,wname)使用wname指定的小波,基于1-D信号的小波分解结构[c,l]重构type的系数向量。重构了最大分解层的系数。x的长度等于原始一维信号的长度。
在这里插入图片描述

EMD

[imf,residual]=emd(x)返回固有模态函数imf和对应于x的经验模态分解的残差信号residual。利用经验模态分解(emd)将复杂信号分解简化为有限个固有模态函数,以进行Hilbert谱分析。
emd生成与原始信号、前3个imf和残差的交互图。在命令窗口中生成的表格表示每个生成的IMF的sift迭代次数、相对公差和sift停止标准。使用IMF选择器有选择地查看生成的IMF、原始信号和残差。

在这里插入图片描述

以下是GUI页面的代码

function varargout = GUI(varargin)
% GUI MATLAB code for GUI.fig
%      GUI, by itself, creates a new GUI or raises the existing
%      singleton*.
%
%      H = GUI returns the handle to a new GUI or the handle to
%      the existing singleton*.
%
%      GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI.M with the given input arguments.
%
%      GUI('Property','Value',...) creates a new GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_OpeningFcn 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 GUI

% Last Modified by GUIDE v2.5 11-Apr-2021 08:41:51

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_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
% End initialization code - DO NOT EDIT


% --- Executes just before GUI is made visible.
function GUI_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 GUI (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = GUI_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 pushbutton1_Callback(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 str;
global s1;
global fs1;
[filename,pathname]=...
    uigetfile({'*.wav';'*.bmp';'*.gif'},'choose');
str=[pathname filename];
[s1,fs1] = audioread(str);%读取
axes(handles.axes1)
plot(s1)
title('心音信号')

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(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 s1;
global y;
win = hamming(1024,"periodic");
S = stft(s1,'Window',win,'OverlapLength',512);
y = mfcc(S,8000);
axes(handles.axes3)
plot(y)
title('心音信号--mel倒谱特征')


% --- 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 s1;
[c,l] = wavedec(s1,5,'db5');
%重构1~5层细节函数
d5 = wrcoef('d',c,l,'db5',5);
d4 = wrcoef('d',c,l,'db5',4);
d3 = wrcoef('d',c,l,'db5',3);
d2 = wrcoef('d',c,l,'db5',2);
d1 = wrcoef('d',c,l,'db5',1);
%重构1~5层近似函数
a5 = wrcoef('a',c,l,'db5',5);
a4 = wrcoef('a',c,l,'db5',4);
a3 = wrcoef('a',c,l,'db5',3);
a2 = wrcoef('a',c,l,'db5',2);
a1 = wrcoef('a',c,l,'db5',1);

axes(handles.axes4)
plot(a1)
axes(handles.axes5)
plot(d1)
axes(handles.axes6)
plot(a2)
axes(handles.axes7)
plot(d2)
axes(handles.axes8)
plot(a3)
axes(handles.axes9)
plot(d3)
axes(handles.axes10)
plot(a4)
axes(handles.axes11)
plot(d4)




% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global s1;
global fs1;
[imf,residual,info] = emd(s1,'Interpolation','pchip');
% 使用经验模态分解得到的imf分量创建Hilbert谱图。
axes(handles.axes24)
hht(imf,2000)
title('心音信号-EMD')
% 计算心率
locs = [s1(3:length(s1))];
delta_time=diff(locs);%每两次心跳时间间隔序列,去掉开头两条
heart_rate=60/mean(delta_time)%60/心跳一次平均消耗的时间
set(handles.edit2,'string',heart_rate)


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global s1;
global fs1;
P = abs(s1);
axes(handles.axes2)
plot(P);
title('傅里叶变换')


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global str;
global s2;
global fs2;
[filename,pathname]=...
    uigetfile({'*.wav';'*.bmp';'*.gif'},'choose');
str=[pathname filename];
[s2,fs2] = audioread(str);%读取
axes(handles.axes12)
plot(s2)
title('心音信号')


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global s2;
global fs2;
P = abs(s2);
axes(handles.axes13)
plot(P);
title('傅里叶变换')


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global s2;
global y2;
win = hamming(1024,"periodic");
S = stft(s2,'Window',win,'OverlapLength',512);
y2 = mfcc(S,8000);
axes(handles.axes14)
plot(y2)
title('心音信号--mel倒谱特征')


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global s2;
[c,l] = wavedec(s2,4,'db5');
%重构1~4层细节函数

d4 = wrcoef('d',c,l,'db5',4);
d3 = wrcoef('d',c,l,'db5',3);
d2 = wrcoef('d',c,l,'db5',2);
d1 = wrcoef('d',c,l,'db5',1);
%重构1~4层近似函数

a4 = wrcoef('a',c,l,'db5',4);
a3 = wrcoef('a',c,l,'db5',3);
a2 = wrcoef('a',c,l,'db5',2);
a1 = wrcoef('a',c,l,'db5',1);

axes(handles.axes15)
plot(a1)
axes(handles.axes16)
plot(d1)
axes(handles.axes17)
plot(a2)
axes(handles.axes18)
plot(d2)
axes(handles.axes19)
plot(a3)
axes(handles.axes20)
plot(d3)
axes(handles.axes21)
plot(a4)
axes(handles.axes22)
plot(d4)


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global s2;
global fs2;
[imf,residual,info] = emd(s2,'Interpolation','pchip');
% 使用经验模态分解得到的imf分量创建Hilbert谱图。
axes(handles.axes25)
hht(imf,2000)
title('心音信号-EMD')
% 计算心率
locs = [s2(3:length(s2))];
delta_time=diff(locs);%每两次心跳时间间隔序列,去掉开头两条
heart_rate=60/mean(delta_time)%60/心跳一次平均消耗的时间
set(handles.edit3,'string',heart_rate)


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



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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

标签:EMD,see,GUI,axes,hObject,handles,MATLAB,特征提取,eventdata
来源: https://blog.csdn.net/qq_45047246/article/details/122267309