基于MATLAB-GUI语音信号的采集分析系统.doc_第1页
基于MATLAB-GUI语音信号的采集分析系统.doc_第2页
基于MATLAB-GUI语音信号的采集分析系统.doc_第3页
基于MATLAB-GUI语音信号的采集分析系统.doc_第4页
基于MATLAB-GUI语音信号的采集分析系统.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

基于的语音信号采集分析系统前一阵子用MATLABGUI做了一个语音信号采集与分析的界面。功能包括录音、播放、时域、频域分析吧。也导入本地文件进行分析。效果如下:源码如下:function varargout = GUI_1(varargin)% GUI_1 MATLAB code for GUI_1.fig% GUI_1, by itself, creates a new GUI_1 or raises the existing% singleton*.% H = GUI_1 returns the handle to a new GUI_1 or the handle to% the existing singleton*.% GUI_1(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in GUI_1.M with the given input arguments.% GUI_1(Property,Value,.) creates a new GUI_1 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before GUI_1_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to GUI_1_OpeningFcn via varargin.% *See GUI Options on GUIDEs 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_1 % Last Modified by GUIDE v2.5 25-May-2015 20:52:27 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, GUI_1_OpeningFcn, . gui_OutputFcn, GUI_1_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT % - Executes just before GUI_1 is made visible.function GUI_1_OpeningFcn(hObject, , 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_1 (see VARARGIN) % Choose default command line output for GUI_1set(handles.axes_t_m,visible,off);set(handles.axes_fft_m,visible,off);set(handles.axes_t_w,visible,off);set(handles.axes_fft_w,visible,off);global local_yn;local_yn=0;% a=imread(yanda.jpg);% axes(handles.axes_t_m)% image(a);handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes GUI_1 wait for user response (see UIRESUME)% uiwait(handles.figure1); ha=axes(units,normalized,position,0 0 1 1);uistack(ha,down)II=imread(暖色.JPG);image(II)colormap grayset(ha,handlevisibility,off,visible,off);%- Outputs from this function are returned to the command line. function varargout = GUI_1_OutputFcn(, , 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 structurevarargout1 = handles.output; % - Executes on button press in pushbutton_luyin.function pushbutton_luyin_Callback(hObject, , handles)% hObject handle to pushbutton_luyin (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% global recObj;% keyboard;% global sex_flag% switch sex_flag% case 0% set(handles.axes_t_m,visible,on);% set(handles.axes_fft_m,visible,on);% set(handles.axes_t_w,visible,off);% set(handles.axes_fft_w,visible,off);% case 1% set(handles.axes_t_m,visible,off);% set(handles.axes_fft_m,visible,off);% set(handles.axes_t_w,visible,off);% set(handles.axes_fft_w,visible,off);% case 2% set(handles.axes_t_m,visible,off);% set(handles.axes_fft_m,visible,off);% set(handles.axes_t_w,visible,off);% set(handles.axes_fft_w,visible,off);% endglobal local_yn;local_yn=0;fs_chose=handles.fs_chose;nBits=8;nChannels=1;%canshu=fs_chose,nBits,nChannels;if(str2double(get(handles.et_time,String)=0) %添加str2double 后正常 set(handles.set_time,String,时间参数输入错误!); msgbox(认真点好吗亲 输入时间参数先。,错误提示,Icon); set(handles.set_time,BackgroundColor,red); pause(1); set(handles.set_time,BackgroundColor,default); set(handles.set_time,String,请输入录音时长);else %cla (handles.axes_t_m,reset); % set(handles.axes_t_m,visible,off); set(handles.pushbutton_luyin,BackgroundColor,green); set(handles.pushbutton_luyin,String,正在录音.); recObj = audiorecorder(fs_chose,nBits,nChannels); disp(Start speaking.) recordblocking(recObj, handles.recor_time); disp(End of Recording.); set(handles.pushbutton_luyin,BackgroundColor,yellow); set(handles.pushbutton_luyin,String,录音结束); %play(recObj); pause(1); %新加代码 加入语音识别-刘帅20150526% myRecording = getaudiodata(recObj);% y1=myRecording; % % L=length(y1);% NFFT = 2nextpow2(L); % Next power of 2 from length of y% Y = fft(y1,NFFT)/L;% % f = fs_chose/2*linspace(0,1,NFFT/2+1);% % keyboard;% a=0;% for i=1:fs_chose/2% % if (2*abs(Y)0.00015% if 2*abs(Y)(1e-5)% %if(i=2)% %msgbox(你个,性别提示,Icon);% a=a+1;% end% end% if a10% msgbox(你个,性别提示,Icon);% end% keyboard;% axes(handles.axes_fft_m);% plot(f,2*abs(Y(1:NFFT/2+1); %语音识别刘帅 20150526 set(handles.pushbutton_luyin,BackgroundColor,red); set(handles.pushbutton_luyin,String,点我录音); handles.recObj=recObj; guidata(hObject,handles); %更新handles里的数据end% % 回放录音数据% play(recObj);% % 获取录音数据% myRecording = getaudiodata(recObj);% % 绘制录音数据波形% plot(myRecording);%keyboard; % - Executes on button press in pushbutton_plot.function pushbutton_plot_Callback(hObject, , handles)% hObject handle to pushbutton_plot (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% 回放录音数据%set(handles.axes_t_m,visible,on);%set(handles.axes_fft_m,visible,on);global local_yn;global sex_flag;switch local_yn case 0 if(str2double(get(handles.et_time,String)=0) %添加str2double 后正常 msgbox(亲 别逗好吗?请录音或者选择本地文件先。 ,Error,Icon); %errordlg(亲 别逗好吗?请输入时间参数或者选择本地文件先。,Error,on); else switch sex_flag case 0 recObj=handles.recObj; % 获取录音数据 %myRecording = getaudiodata(recObj,uint8); myRecording = getaudiodata(recObj); d=myRecording; name=get(handles.et_savme,String); %audiowrite(name,d,8000); audiowrite(name,d,handles.fs_chose); %msgbox(数据保存成功,消息提示,Icon); % 绘制录音数据波形 axes(handles.axes_t_m); draw_m=plot(myRecording); title(时域信号); xlabel(t); ylabel(幅值); % Fs=16000; % fs=handles.fs_chose; %采集频率 y1=myRecording; % 一维矩阵 L=length(y1); % 计算元素个数 NFFT = 2nextpow2(L); % Next power of 2 from length of y 提高运算速度 Y = fft(y1,NFFT)/L; %傅里叶变换 NFFT级蝶形运算 ? f = fs/2*linspace(0,1,NFFT/2+1); % x轴点数 % Plot single-sided amplitude spectrum. axes(handles.axes_fft_m); draw_fft_m=plot(f,2*abs(Y(1:NFFT/2+1); title(频域信号) xlabel(Frequency (Hz) ylabel(|Y(f)|) % xFFT = fft(data); % % xfft = abs(xFFT); % % % Avoid taking the log of 0. % index = xfft = 0; % xfft(index) = 1e-17; % % mag = 20*log10(xfft); % % mag = mag(1:blockSize/2); % % f = (0:length(mag)-1)*Fs/blockSize; %f = f(:); % axes(handles.axes_fft_m); % draw_fft_m=plot(f(:,1),mag(:,1); % ylabel(Magnitude (dB); % xlabel(Frequency (Hz); % title(频谱图); % Fs=1000; % nbit=24; % wavwrite(myRecording,1000,24,test_1.wav); %MATLAB 写wav文件,看最大最小值 % myRecording_fft,Fs,nbits = wavread(test_1.wav); % MATLAB读wav文件,看最大最小值,预计是在-1和1之间 % N=length(myRecording_fft) % Fm=fft(myRecording_fft,N); % axes(handles.axes_fft_m); % draw_fft_m=plot(handles.axes_fft_m,100*abs(Fm); % title(频域信号); % xlabel(w); % ylabel(幅值); handles.draw_fft_m=draw_fft_m; guidata(hObject,handles); handles.draw_plot_m=draw_m; guidata(hObject,handles); case 1 recObj=handles.recObj; % 获取录音数据 myRecording = getaudiodata(recObj); % 绘制录音数据波形 axes(handles.axes_t_w); draw_w=plot(handles.axes_t_w,myRecording,m); ylabel(Amplitude); xlabel(Time ); title(时域信号); fs=handles.fs_chose; % y1=myRecording; % L=length(y1); NFFT = 2nextpow2(L); % Next power of 2 from length of y Y = fft(y1,NFFT)/L; f = fs/2*linspace(0,1,NFFT/2+1); % Plot single-sided amplitude spectrum. axes(handles.axes_fft_w); draw_fft_w=plot(f,2*abs(Y(1:NFFT/2+1),m); title(频域信号) xlabel(Frequency (Hz) ylabel(|Y(f)|) % xFFT = fft(data); % % xfft = abs(xFFT); % % % Avoid taking the log of 0. % index = xfft = 0; % xfft(index) = 1e-17; % % mag = 20*log10(xfft); % % mag = mag(1:blockSize/2); % % f = (0:length(mag)-1)*Fs/blockSize; % f = f(:); % axes(handles.axes_fft_w); % draw_fft_w=plot(f(:,1),mag(:,1); % ylabel(Magnitude (dB); % xlabel(Frequency (Hz); % title(频谱图); % Fw=fft(myRecording,4096); % axes(handles.axes_fft_w); % draw_fft_w=plot(handles.axes_fft_w,abs(Fw); % title(频域信号); % xlabel(w); % ylabel(幅值); handles.draw_fft_w=draw_fft_w; guidata(hObject,handles); handles.draw_plot_w=draw_w; guidata(hObject,handles); % case 2 % msgbox(妖孽!哪里逃,haha,Icon); end end case 1 FileName=handles.FileName; y1,fs=audioread(FileName); axes(handles.axes_t_m); draw_fft_m=plot(y1); ylabel(Amplitude); xlabel(Time ); title(时域信号); L=length(y1); %set(gca,ylim,0 2) % myRecording = getaudiodata(aa,uint8); NFFT = 2nextpow2(L); % Next power of 2 from length of y Y = fft(y1,NFFT)/L; f = fs/2*linspace(0,1,NFFT/2+1); % Plot single-sided amplitude spectrum. axes(handles.axes_fft_m); draw_fft_m=plot(f,2*abs(Y(1:NFFT/2+1); title(频域信号); xlabel(Frequency (Hz); ylabel(|Y(f)|); % Fs=16000; % %data=myRecording; % % blockSize=length(data); % xFFT = fft(data); % % xfft = abs(xFFT); % % % Avoid taking the log of 0. % index = xfft = 0; % xfft(index) = 1e-17; % mag = 20*log10(xfft); % % mag = mag(1:blockSize/2); % f = (0:length(mag)-1)*Fs/blockSize; % f = f(:); % axes(handles.axes_fft_m); % draw_fft_m=plot(f(:,1),mag(:,1); % ylabel(Magnitude (dB); % xlabel(Frequency (Hz); % title(频谱图);end % - Executes on button press in pushbutton_play.function pushbutton_play_Callback(hObject, , handles)% hObject handle to pushbutton_play (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global local_yn;%keyboard;switch local_yn case 0 if(str2double(get(handles.et_time,String)=0) %添加str2double 后正常 msgbox(亲 别逗好吗?请录音或者选择本地文件先。 ,Error,Icon); %errordlg(亲 别逗好吗?请输入时间参数或者选择本地文件先。,Error,on); else recObj_play=handles.recObj; play(recObj_play); set(hObject,BackgroundColor,green); set(hObject,String,正在播放); pause(handles.recor_time); set(hObject,BackgroundColor,yellow); set(hObject,String,播放完毕); pause(1); set(hObject,String,点我播放); guidata(hObject,handles); end case 1 y ,fs=audioread(handles.FileName); sound(y,fs);endfunction et_time_Callback(hObject, , handles)% hObject handle to et_time (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 et_time as text% str2double(get(hObject,String) returns contents of et_time as a double if(isempty(get(hObject,String) set(hObject,String,0); set(handles.set_time,String,时间参数输入错误!); pause(2); set(handles.set_time,String,请输入录音时长); guidata(hObject,handles);else input=str2double(get(hObject,String); handles.recor_time=input; guidata(hObject,handles);end % - Executes during object creation, after setting all properties.function et_time_CreateFcn(hObject, , )% hObject handle to et_time (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 during object creation, after setting all properties.function axes_t_m_CreateFcn(hObject, eventdata, handles)% hObject handle to axes_t_m (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 axes_t_m % - Executes on button press in rb_man.function rb_man_Callback(hObject, eventdata, handles)% hObject handle to rb_man (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 rb_man % - Executes on button press in rb_women.function rb_women_Callback(hObject, eventdata, handles)% hObject handle to rb_women (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 rb_women % - Executes on button press in rb_Neither.function rb_Neither_Callback(hObject, eventdata, handles)% hObject handle to rb_Neither (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) retur

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论