function varargout = untitled(varargin) % UNTITLED M-file for untitled.fig % UNTITLED, by itself, creates a new UNTITLED or raises the existing % singleton*. % % H = UNTITLED returns the handle to a new UNTITLED or the handle to % the existing singleton*. % % UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in UNTITLED.M with the given input arguments. % % UNTITLED('Property','Value',...) creates a new UNTITLED or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled_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 untitled % Last Modified by GUIDE v2.5 17-May-2018 22:35:32 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_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 untitled is made visible. function untitled_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 untitled (see VARARGIN) % Choose default command line output for untitled handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = untitled_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) R = audiorecorder( 44100,16 ,1 );%创建一个保存音频信息的对象,它包含采样率,时间和录制的音频信息等等。 %44100表示采样为44100Hz(可改为8000, 11025, 22050等,此数值越大,录入的声音质量越好 %相应需要的存储空间越大),16为用16bits存储,2为两通道即立体声(也可以改为1即单声道)。 record(R);%开始录音 pause(5);%录音5s stop(R);%结束录音 %play(R);%播放声音 myspeech = getaudiodata(R);%得到以n*2列数字矩阵存储的刚录制的音频信号。 axes(handles.axes1);%在axes1中绘制 plot(myspeech);%绘制声音波形 %audiowrite(myspeech.wav,44100,16,'1');%将录入的声音转化为wav文件 %filename = 'handel.wav'; audiowrite('myspeech.wav',myspeech,44100); % --- 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) [y,Fs]=audioread('myspeech.wav'); y = y*10; sound(y,Fs); % --- 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) axes(handles.axes2);%在axes2中绘制 [Y,FS]=audioread('myspeech.wav'); Y = Y*30; Y = Y(:,1); L=length(Y); t=(0:L-1)/FS; %figure('NumberTitle', 'off', 'Name', '分析图像'); %subplot(2,1,1); %plot(t,Y); %title('信号时域波形图'); % xlabel('t/s'); %ylabel('振幅'); %subplot(2,1,2); f=FS/L*(0:round(L/2)-1); y=abs(fft(Y)); y=y(1:round(L/2)); plot(f,y); axis([0 10000 0 max(y)]); title('信号的频谱图'); xlabel('频率/HZ'); ylabel('幅度'); T=length(f); h=y(1:round(0.00453*T)*220); m=f(1:round(0.00453*T)*220); h=reshape(h,round(0.00453*T),220); h=max(h); x=linspace(0,max(m),220); U=mean(h); H=h/U; if max(h(40:60))<260 %disp(' 这是首【钢琴】') set(handles.edit1,'string','钢琴') elseif sum(y(1:round(0.0167*T)))/sum(y(round(0.0207*T):round(0.068*T)))>0.5 %disp(' 这是首【吉他】') set(handles.edit1,'string','吉他') elseif (max(h(50:200))>130) set(handles.edit1,'string','口琴') else %disp(' 这是首【小提琴】') set(handles.edit1,'string','小提琴') end % --- Executes on selection change in listbox3. function listbox3_Callback(hObject, eventdata, handles) % hObject handle to listbox3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox3 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox3 % --- Executes during object creation, after setting all properties. function listbox3_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox 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 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 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) axes(handles.axes2);%在axes2中绘制 [FileName,pname] = uigetfile('*.wav','select wave file'); %[P,Fs]=audioread(fname);%P为声压,Fs,采样率,N, 数据量 [Y,FS]=wavread(FileName); Y = Y(:,1); L=length(Y); t=(0:L-1)/FS; %figure('NumberTitle', 'off', 'Name', '分析图像'); %subplot(2,1,1); %plot(t,Y); %title('信号时域波形图'); %xlabel('t/s'); %ylabel('振幅'); %subplot(2,1,2); f=FS/L*(0:round(L/2)-1); y=abs(fft(Y)); y=y(1:round(L/2)); plot(f,y); axis([0 10000 0 max(y)]); title('信号的频谱图'); xlabel('频率/HZ'); ylabel('幅度'); T=length(f); h=y(1:round(0.00453*T)*220); m=f(1:round(0.00453*T)*220); h=reshape(h,round(0.00453*T),220); h=max(h); x=linspace(0,max(m),220); U=mean(h); H=h/U; if max(h(45:60))<80 %disp(' 这是首【钢琴】') set(handles.edit1,'string','钢琴') elseif sum(y(1:round(0.0267*T)))/sum(y(round(0.0227*T):round(0.068*T)))>0.5 %disp(' 这是首【吉他】') set(handles.edit1,'string','吉他') elseif (max(h(55:70))>60) set(handles.edit1,'string','口琴') else %disp(' 这是首【小提琴】') set(handles.edit1,'string','小提琴') 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) axes(handles.axes1);%在axes1中绘制 [FileName,pname] = uigetfile({'*.wav';'*.mp3';'*.wma';'*.*'},'select wave file'); %[P,Fs]=audioread(fname);%P为声压,Fs,采样率,N, 数据量 [Y,FS]=audioread(FileName); plot(Y); axes(handles.axes2);%在axes2中绘制 Y = Y(:,1); L=length(Y); t=(0:L-1)/FS; %figure('NumberTitle', 'off', 'Name', '分析图像'); %subplot(2,1,1); %plot(t,Y); %title('信号时域波形图'); %xlabel('t/s'); %ylabel('振幅'); %subplot(2,1,2); f=FS/L*(0:round(L/2)-1); y=abs(fft(Y)); y=y(1:round(L/2)); plot(f,y); axis([0 10000 0 max(y)]); title('信号的频谱图'); xlabel('频率/HZ'); ylabel('幅度'); T=length(f); h=y(1:round(0.00453*T)*220); m=f(1:round(0.00453*T)*220); h=reshape(h,round(0.00453*T),220); h=max(h); x=linspace(0,max(m),220); U=mean(h); H=h/U; if max(h(40:60))<290 %disp(' 这是首【钢琴】') set(handles.edit1,'string','钢琴') elseif sum(y(1:round(0.0217*T)))/sum(y(round(0.0377*T):round(0.258*T)))>0.5 %disp(' 这是首【吉他】') set(handles.edit1,'string','吉他') elseif (max(h(55:70))>200) set(handles.edit1,'string','口琴') else %disp(' 这是首【小提琴】') set(handles.edit1,'string','小提琴') 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) [FileName,pname] = uigetfile({'*.wav';'*.mp3';'*.wma';'*.*'},'select wave file'); fs=44100; [y,fs]=audioread(FileName); axes(handles.axes1);%在axes1中绘制 plot(y); axes(handles.axes2);%在axes1中绘制 xlabel('Time (s)') ylabel('Amplitude') title('Time Domain') Nsamples = length(y); t = (1/fs)*(1:Nsamples) ; y_fft = abs(fft(y)); y_fft = y_fft(1:Nsamples/2); f = fs*(0:Nsamples/2-1)/Nsamples; %subplot(2,1,2); plot( f, y_fft) xlim([0 5000]) xlabel('Frequency (Hz)') ylabel('Amplitude') title('Frequency Domain') A=y_fft(1:50000); B=y_fft(300000: 500000); a=3000;b=1500;c=5000; I=find(A>=a);J=find(A>=c);K=find(B>=b); N=length(I);M=length(K);Q=length(J); if (N>=1&&Q>=3&&M<=1) fprintf('钢琴') set(handles.edit1,'string','钢琴') else if (N>=1&&M>=1) set(handles.edit1,'string','萨克斯') fprintf('萨克斯') else set(handles.edit1,'string','小提琴') fprintf('小提琴') end end
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算