function varargout = GUI_2(varargin)
% GUI_2 MATLAB code for GUI_2.fig
% GUI_2, by itself, creates a new GUI_2 or raises the existing
% singleton*.
%
% H = GUI_2 returns the handle to a new GUI_2 or the handle to
% the existing singleton*.
%
% GUI_2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_2.M with the given input arguments.
%
% GUI_2('Property','Value',...) creates a new GUI_2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_2_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_2
% Last Modified by GUIDE v2.5 29-Jan-2022 11:02:32
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_2_OpeningFcn, ...
'gui_OutputFcn', @GUI_2_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_2 is made visible.
function GUI_2_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_2 (see VARARGIN)
% Choose default command line output for GUI_2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI_2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_2_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);%读取
figure(1)
s1=s1(1:3000,:);
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);
figure(3)
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~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);
figure(4)
subplot(811)
plot(a1)
title('小波变换')
subplot(812)
plot(d1)
subplot(813)
plot(a2)
subplot(814)
plot(d2)
subplot(815)
plot(a3)
subplot(816)
plot(d3)
subplot(817)
plot(a4)
subplot(818)
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');
emd(s1)
title('心音信号-EMD')
% 计算心率
locs = [s1(3:length(s1))];
delta_time=diff(locs);%每两次心跳时间间隔序列,去掉开头两条
heart_rate=60/mean(delta_time)%60/心跳一次平均消耗的时间
set(handles.edit1,'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=fft(s1);
P = abs(p);
figure(2)
plot(P);
xlabel('频率')
ylabel('幅值')
title('傅里叶变换')
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 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 s2;
global fs2;
[filename,pathname]=...
uigetfile({'*.wav';'*.bmp';'*.gif'},'choose');
str=[pathname filename];
[s2,fs2] = audioread(str);%读取
figure(7)
s2=s2(1:3000,:);
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=fft(s2);
P = abs(p);
figure(8)
xlabel('频率')
ylabel('幅值')
title('傅里叶变换')
plot(P);
% --- 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 fs2;
global y;
win = hamming(1024,'periodic');
S = stft(s2,'Window',win,'OverlapLength',512);
y = mfcc(S,8000);
figure(9)
plot(y)
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
% ha