function varargout = yuyinchuli(varargin)
% YUYINCHULI M-file for yuyinchuli.fig
% YUYINCHULI, by itself, creates a new YUYINCHULI or raises the existing
% singleton*.
%
% H = YUYINCHULI returns the handle to a new YUYINCHULI or the handle to
% the existing singleton*.
%
% YUYINCHULI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in YUYINCHULI.M with the given input arguments.
%
% YUYINCHULI('Property','Value',...) creates a new YUYINCHULI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before yuyinchuli_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to yuyinchuli_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 yuyinchuli
% Last Modified by GUIDE v2.5 30-Jun-2014 21:47:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @yuyinchuli_OpeningFcn, ...
'gui_OutputFcn', @yuyinchuli_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 yuyinchuli is made visible.
function yuyinchuli_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 yuyinchuli (see VARARGIN)
% Choose default command line output for yuyinchuli
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes yuyinchuli wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = yuyinchuli_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 y;
varargout{1} = handles.output;
prompt = {'请确定录音时间(s):','设定录音频率:'};
dlg_title = '语音录制';
num_lines = 1;
def = {'5','44100'}; %默认值
ti = inputdlg(prompt,dlg_title,num_lines,def,'on');% 调出输入对话框
t=str2double(ti{1});
f=str2double(ti{2}); %录制固定时间的声音
y=wavrecord(t*f,f);
%将文件写入工作空间
wavwrite(y,f,'录音.wav');
%画出波形
axes(handles.axes1);
plot(y);
msgbox('录音完毕!','提示');
% --- 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 x; %全局变量声明
global Fs;
Fs=8000;%采样率8khz
[filename,pathname]=...
uigetfile('*.wav','读取语音文件');
str=[pathname filename];%合成路径+文件名
x=wavread(str);%读取语音
wavplay(x,44100);
x=x/max(x); %归一化
plot(handles.axes1,x,'k');%绘制语音波形
title('原语音波形');
% --- 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)
close(gcf)
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel1
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
global x; %全局变量声明
global fs;
global s;
global q;
str=get(hObject,'string');
axes(handles.axes1);
switch str
case'原语音'
sound(x,22050);
plot(x,'k');
title('原语音波形');
case '语音快进'
prompt = {'请输入快放倍数:'};
dlg_title = '快放';
num_lines = 1;
def = {'3'}; %默认值
ti = inputdlg(prompt,dlg_title,num_lines,def,'on');% 调出输入对话框
t=str2double(ti{1});
wavplay(x,22050*t);%播放处理后声音文件
plot(x,'r');%绘制语音波形
title('语音快放波形');
case '语音慢放'
prompt = {'请输入慢放倍数:'};
dlg_title = '慢放';
num_lines = 1;
def = {'3'}; %默认值
ti = inputdlg(prompt,dlg_title,num_lines,def,'on');% 调出输入对话框
t=str2double(ti{1});
wavplay(x,44100/t);%播放处理后声音文件
plot(x,'b');
title('语音慢放波形');
case '语音加噪'
n =length(x) %求出语音信号的长度
noise=0.03*randn(n,1);%随机函数产生噪声
size(x);
size(noise);
s=x+noise; %语音信号加入噪声
sound(s,44100);
plot(s,'g');
title('加噪后的语音波形');
case '语音去噪'
wpd=2*pi*50/1000;
wsd=2*pi*70/1000;%确定截止频率
Btd=wsd - wpd; %计算过渡带宽
wcd=(wsd+wpd)/2/pi;%计算3db截止频率
Md=ceil(6.6*pi/Btd);
hnd=fir1(Md,wcd);
yyd=filter(hnd,1,s);
sound(yyd,44100); %去噪后
YYd=fft(yyd);
plot(abs(YYd));
title('滤波后的频域波形');
end;
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in text3.
function text3_Callback(hObject, eventdata, handles)
% hObject handle to text3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)