function varargout = myGui(varargin)
% MYGUI MATLAB code for myGui.fig
% MYGUI, by itself, creates a new MYGUI or raises the existing
% singleton*.
%
% H = MYGUI returns the handle to a new MYGUI or the handle to
% the existing singleton*.
%
% MYGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYGUI.M with the given input arguments.
%
% MYGUI('Property','Value',...) creates a new MYGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before myGui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to myGui_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 myGui
% Last Modified by GUIDE v2.5 06-Nov-2022 13:02:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1; %保证只打开一个窗口,为0则可以打开多个窗口
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @myGui_OpeningFcn, ...
'gui_OutputFcn', @myGui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
%该结构描述了该GUI的状况,包括gui的名字、运行实例、初始化函数、输出函数、布局以及回调函数。
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
%分别取得figure和包含的控件的CreateFcn回调函数,创建各个控件。
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 myGui is made visible.
function myGui_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 myGui (see VARARGIN)
% Choose default command line output for myGui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes myGui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = myGui_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 myspeech1 Fs
Fs = 44100;
t = eval(get(handles.edit1,'String')); %录音时长
recObj = audiorecorder(Fs,16,1); %创建一个录音,调用麦克风
recordblocking(recObj,t); %开始录音
play(recObj);
myspeech1 = getaudiodata(recObj);
% --- 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 myspeech1
sound(myspeech1,44100);
% --- 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 myspeech1
axes(handles.axes1); %定位到坐标系1
plot((0:length(myspeech1)-1)/44100,myspeech1); %绘制语音信号波形
xlabel('t(s)');
ylabel('幅值');
legend('原始语音波形');
axes(handles.axes2);
Y = abs(fft(myspeech1,length(myspeech1))/(length(myspeech1))/2); %频谱分析
f = (0:length(myspeech1)/2-1)*44100/length(myspeech1); %频率
plot(f,Y(1:length(myspeech1)/2)); %绘制语音信号频谱图
xlabel('f(Hz)');
ylabel('幅值');
legend('原始语音频谱');
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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 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 myspeech x Bz Az wn
switch get(handles.popupmenu1,'Value')
case 1
x = filter(wn,1,myspeech);% 滤波
case 2
x = filter(Bz, Az, myspeech);
end
% --- 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 x
sound(x,44100);
% --- 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 x
axes(handles.axes3); %定位到坐标系3
plot((0:length(x)-1)/44100,x); %绘制语音信号波形
xlabel('t(s)');
ylabel('幅值');
axes(handles.axes4);
Y = abs(fft(x,length(x))/(length(x))/2); %频谱分析
f = (0:length(x)/2-1)*44100/length(x); %频率
plot(f,Y(1:length(x)/2)); %绘制语音信号频谱图
xlabel('f(Hz)');
ylabel('幅值');
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata res