BAB V PENUTUP
5.2. Saran
BAB V PENUTUP
5.1. Kesimpulan
Dalam hasil penelitian klasifikasi burung berdasarkan suara kicau burung menggunakan jaringan syaraf tiruan propagasi balik dapat disimpulkan sebagai berikut :
1. Hasil percobaan beberapa kombinasi feature dan arsitektur jaringan untuk klasifikasi jenis burung, sebagai berikut :
a. Penggunaan feature mean sebagai input sudah cukup untuk menghasilkan model jaringan yang baik.
b. Pada 3 fold cross validation, feature mean menghasilkan akurasi sebesar 85,28%, pada 5 fold cross validation menghasilkan akurasi sebesar 98,61%, dan pada 10 fold cross validation menghasilkan akurasi sebesar 99,17% dengan menggunakan 1 hidden layer 10 neuron.
c. Akurasi tertinggi didapatkan pada 13 koefisien mfcc dengan 2 hidden layer, 10 neuron hidden layer 1 dan 30 neuron hidden layer 2.
2. Model jaringan syaraf tiruan yang dihasilkan sudah mampu mengklasifikasikan jenis burung berdasarkan suara kicaunya dengan baik karena setelah dilakukan klasifikasi data tunggal dengan data di luar data pelatihan, sistem mampu mengklasifikasikannya dengan cukup akurat atau hasilnya sesuai dengan target aslinya.
5.2. Saran
Dari hasil penelitian klasifikasi jenis burung ini, ada beberapa saran yang dapat diberikan penulis untuk penelitian selanjutnya dengan topik yang sama yaitu:
a. Menambahkan data jenis burung yang lainnya, sehingga lebih bervariasi.
DAFTAR PUSTAKA
Annisa, R., Hidayat, B., & Wijayanto, I. (2012). Klasifikasi Jenis Burung Berdasarkan Suara Kicau Burung Menggunakan Wavelet Packet Decomposition Dan Jaringan Syaraf Tiruan Self Organizing Map. Bandung: Universitas Telkom.
Diana, L., & Shidik, G. F. (2014). Analisis Data Transaksi Penjualan Untuk Klasifikasi Jenis Barang Dan Relasi Daya Beli Relatif Masyarakat Menggunakan Algoritam K-Means Serta Asosiasi Apriori. Jurnal Teknologi Informasi, 212-219.
Fagerlund, S. (2004). Automatic Recognition of Bird Species by Their Sounds. Otaniemi: Helsinki University of Technology.
Hagan, M., & Demuth, H. (1996). Neural Network Design. Boston: PWS Publishing Company.
Jang, J.-S. R. (2005). ASR (Automatic Speech Recognition) Toolbox. Diambil kembali dari Mirlab: http://mirlab.org/jang/matlab/toolbox/asr/
Jang, J.-S. R. (2015, February 6). Audio Signal Processing and Recognition.
Diambil kembali dari Mirlab:
http://mirlab.org/jang/books/audiosignalprocessing/
Mustofa, A. (2007). Sistem Pengenalan Penutur dengan Metode Mel-Frequency Wrapping. Malang: Universitas Brawijaya.
Passeriform. (2015, December 4). Diambil kembali dari Encyclopaedia Britannica: http://www.britannica.com/animal/passeriform
Setiawan, A., Hidayanto, A., & Isnanto, R. (2011). Aplikasi Pengenalan Ucapan dengan Ekstraksi Mel-Frequency Cepstrum Coefficients (MFCC) Melalui Jaringan Syaraf Tiruan Learning Vector Quantization (LVQ) untuk Mengoperasikan Kursor Komputer. Transmisi, 82-86.
Siang, J. J. (2005). Dalam Jaringan Syaraf Tiruan & Pemorgramannya Menggunakan MATLAB. Yogyakarta: Penerbit Andi.
LAMPIRAN
Source code Main Menu GUI
function varargout = MainMenu(varargin) % MAINMENU MATLAB code for MainMenu.fig
% MAINMENU, by itself, creates a new MAINMENU or raises the existing % singleton*.
%
% H = MAINMENU returns the handle to a new MAINMENU or the handle to % the existing singleton*.
%
% MAINMENU('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MAINMENU.M with the given input arguments. %
% MAINMENU('Property','Value',...) creates a new MAINMENU or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before MainMenu_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application % stop. All inputs are passed to MainMenu_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 MainMenu % Last Modified by GUIDE v2.5 21-May-2016 09:52:34
% Begin initialization code - DO NOT EDIT gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @MainMenu_OpeningFcn, ... 'gui_OutputFcn', @MainMenu_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
function MainMenu_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 MainMenu (see VARARGIN) % Choose default command line output for MainMenu
handles.output = hObject; % Update handles structure guidata(hObject, handles);
% UIWAIT makes MainMenu wait for user response (see UIRESUME) % uiwait(handles.mainMenuFigure); addMyPath; if exist('classification.mat', 'file') evalin('base','load(''classification.mat'')'); end autosave(5,'classification.mat')
% --- Outputs from this function are returned to the command line. function varargout = MainMenu_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 featureExtractionDatabase.
function featureExtractionDatabase_Callback(hObject, eventdata, handles) % hObject handle to featureExtractionDatabase (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) FeatureExtractionAndDatabase;
% --- Executes on button press in trainingTesting.
function trainingTesting_Callback(hObject, eventdata, handles) % hObject handle to trainingTesting (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) TrainingAndTesting;
% --- Executes on button press in classify.
function classify_Callback(hObject, eventdata, handles) % hObject handle to classify (see GCBO)
% handles structure with handles and user data (see GUIDATA) Classify;
% --- Executes when user attempts to close mainMenuFigure.
function mainMenuFigure_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to mainMenuFigure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) autosave stop
% Hint: delete(hObject) closes the figure delete(hObject);
Source code Preprocess GUI
function varargout = Preprocess(varargin) % PREPROCESS MATLAB code for Preprocess.fig
% PREPROCESS, by itself, creates a new PREPROCESS or raises the existing % singleton*.
%
% H = PREPROCESS returns the handle to a new PREPROCESS or the handle to % the existing singleton*.
%
% PREPROCESS('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PREPROCESS.M with the given input arguments. %
% PREPROCESS('Property','Value',...) creates a new PREPROCESS or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Preprocess_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Preprocess_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 Preprocess % Last Modified by GUIDE v2.5 20-May-2016 08:22:51
% Begin initialization code - DO NOT EDIT gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Preprocess_OpeningFcn, ... 'gui_OutputFcn', @Preprocess_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 Preprocess is made visible.
function Preprocess_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 Preprocess (see VARARGIN) % Choose default command line output for Preprocess
handles.output = hObject; % Update handles structure guidata(hObject, handles);
% UIWAIT makes Preprocess wait for user response (see UIRESUME) % uiwait(handles.preprocessFigure);
set(handles.busy, 'String', 'Ready');
set(handles.bird, 'SelectedObject', handles.bird1); if evalin('base', 'exist(''bird1'')')
set(handles.filenameTable, 'Data', evalin('base', 'bird1')); set(handles.preprocessBtn, 'Enable', 'off');
else
set(handles.filenameTable, 'Data', cell(0,0)); end
% --- Outputs from this function are returned to the command line. function varargout = Preprocess_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 loadBtn.
function loadBtn_Callback(hObject, eventdata, handles) % hObject handle to loadBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
[filename, path] = uigetfile({'*.wav;', 'Wave Files'}, ' Select audio file'); if ~isequal(filename, 0) || ~isequal(path, 0)
pathfile = strcat(path, filename);
[pathpart, namepart, ext] = fileparts(pathfile); set(handles.pathToFile, 'String', pathfile); info = audioinfo(pathfile);
info.Name = namepart; gui.data.info = info;
numchannel = info.NumChannels;
set(handles.filename, 'String', namepart); if(numchannel == 1)
set(handles.channel, 'String', strcat(num2str(numchannel), ' (mono)')); else
set(handles.channel, 'String', strcat(num2str(numchannel), ' (stereo)')); end
set(handles.duration, 'String', strcat(num2str(info.Duration), ' secs')); set(handles.samplerate, 'String', strcat(num2str(info.SampleRate), ' Hz')); else
return end
% --- Executes on button press in preprocessBtn.
function preprocessBtn_Callback(hObject, eventdata, handles) % hObject handle to preprocessBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.busy, 'String', 'Busy');
drawnow
h = get(handles.bird, 'SelectedObject'); birdTag = get(h, 'Tag');
info = gui.data.info;
duration = str2double(get(handles.chunkDuration, 'string')); if strcmp(birdTag, 'bird1')
bird1 = chunkAudioV2(info, duration, 'bird/1/'); set(handles.filenameTable, 'Data', bird1); assignin('base', 'bird1', bird1);
elseif strcmp(birdTag, 'bird2')
bird2 = chunkAudioV2(info,duration, 'bird/2/'); set(handles.filenameTable, 'Data', bird2); assignin('base', 'bird2', bird2);
else
bird3 = chunkAudioV2(info,duration, 'bird/3/'); set(handles.filenameTable, 'Data', bird3); assignin('base', 'bird3', bird3);
end
set(handles.busy, 'String', '');
% --- Executes on button press in clearBtn.
% hObject handle to clearBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes when selected object is changed in bird.
function bird_SelectionChangedFcn(hObject, eventdata, handles) % hObject handle to the selected object in bird
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h = get(handles.bird, 'SelectedObject');
birdTag = get(h, 'Tag'); if strcmp(birdTag, 'bird1')
if evalin('base', 'exist(''bird1'')')
set(handles.filenameTable, 'Data', evalin('base', 'bird1')); set(handles.preprocessBtn, 'Enable', 'off');
else
set(handles.filenameTable, 'Data', cell(0,0)); set(handles.preprocessBtn, 'Enable', 'on'); end
elseif strcmp(birdTag, 'bird2')
if evalin('base', 'exist(''bird2'')')
set(handles.filenameTable, 'Data', evalin('base','bird2')); set(handles.preprocessBtn, 'Enable', 'off');
else
set(handles.filenameTable, 'Data', cell(0,0)); set(handles.preprocessBtn, 'Enable', 'on'); end
else
if evalin('base','exist(''bird3'')')
set(handles.filenameTable, 'Data', evalin('base','bird3')); set(handles.preprocessBtn, 'Enable', 'off');
else
set(handles.filenameTable, 'Data', cell(0,0)); set(handles.preprocessBtn, 'Enable', 'on'); end
end
Source code Feature Extraction and Database GUI
function varargout = FeatureExtractionAndDatabase(varargin)
% FEATUREEXTRACTIONANDDATABASE MATLAB code for FeatureExtractionAndDatabase.fig % FEATUREEXTRACTIONANDDATABASE, by itself, creates a new
FEATUREEXTRACTIONANDDATABASE or raises the existing % singleton*.
%
% H = FEATUREEXTRACTIONANDDATABASE returns the handle to a new FEATUREEXTRACTIONANDDATABASE or the handle to
%
% FEATUREEXTRACTIONANDDATABASE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FEATUREEXTRACTIONANDDATABASE.M with the given input arguments.
%
% FEATUREEXTRACTIONANDDATABASE('Property','Value',...) creates a new FEATUREEXTRACTIONANDDATABASE or raises the
% existing singleton*. Starting from the left, property value pairs are % applied to the GUI before FeatureExtractionAndDatabase_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application % stop. All inputs are passed to FeatureExtractionAndDatabase_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 FeatureExtractionAndDatabase % Last Modified by GUIDE v2.5 19-Jun-2016 14:08:42
% Begin initialization code - DO NOT EDIT gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FeatureExtractionAndDatabase_OpeningFcn, ... 'gui_OutputFcn', @FeatureExtractionAndDatabase_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 FeatureExtractionAndDatabase is made visible. function FeatureExtractionAndDatabase_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)
% Choose default command line output for FeatureExtractionAndDatabase handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes FeatureExtractionAndDatabase wait for user response (see UIRESUME) % uiwait(handles.featureFigure);
addMyPath;
set(handles.busy, 'String', 'Ready');
set(handles.bird, 'SelectedObject', handles.bird1);
if exist('bird_dataset','file') && evalin('base', 'exist(''audioList'')') && evalin('base', 'exist(''dirName'')')
set(handles.audioList, 'String', evalin('base', 'audioList')); set(handles.browse, 'String', evalin('base', 'dirName')); [inputs,targets] = bird_dataset;
set(handles.featureTable, 'Data', inputs);
set(handles.extractBtn, 'String', 'Clear Features'); else
set(handles.featureTable, 'Data', cell(0,0)); end
if evalin('base', 'exist(''birdInfo'')') birdInfo = evalin('base', 'birdInfo'); handles.birdInfo = birdInfo;
axes(handles.picture); imshow(birdInfo(1).picture);
set(handles.sciName, 'String', birdInfo(1).sciname); set(handles.family, 'String', birdInfo(1).family); set(handles.genus, 'String', birdInfo(1).genus); else
defpic = imread('bird picture/Unknown.jpg'); birdInfo = struct('picture',{defpic defpic
defpic},'sciname','default','family','default','genus','default'); handles.birdInfo = birdInfo;
assignin('base', 'birdInfo', birdInfo); axes(handles.picture);
imshow(defpic); end
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = FeatureExtractionAndDatabase_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
% --- Executes on button press in extractBtn.
function extractBtn_Callback(hObject, eventdata, handles) % hObject handle to extractBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.busy, 'String', 'Busy');
drawnow
extBtn = get(hObject, 'String'); if strcmp(extBtn, 'Extract Features')
list = get(handles.audioList, 'String'); listSize = size(list);
if listSize(:,1) < 2
msgbox('There are no data, please pick a folder contains audio files for extraction.', 'Error', 'error');
set(handles.busy, 'String', ''); return
end
frameSize = (str2double(get(handles.frameSize, 'String'))/1000)*16000; frameOverlap = (str2double(get(handles.frameOverlap, 'String'))/1000)*16000; assignin('base','frameSize',frameSize); assignin('base','frameOverlap',frameOverlap); dirName = handles.dirName; tic fea = []; wait = waitbar(0, '');
set(wait, 'Name', 'Extracting features...'); for i=1:listSize(:,1)
feature = [];
filename = strcat(dirName, list(i)); [y,fs] = audioread(char(filename)); opt = mfccOptSet(fs); opt.frameSize = frameSize; opt.overlap = frameOverlap; opt.useDelta = 2; mfcc = wave2mfcc(y, fs, opt); feature(:,1) = mean(mfcc, 2); % Mean
feature(:,2) = var(mfcc, 1, 2); % Standard deviation feature(:,3) = min(mfcc, [], 2); % Min
feature(:,4) = max(mfcc, [], 2); % Max fea = [fea feature(:)];
waitbar(i/listSize(:,1), wait, list(i)) end close(wait); birdInputs = fea; smpl = get(handles.targetClass, 'String'); sample = strsplit(smpl,','); t1 = repmat([1 0 0],str2double(sample{1}),1)'; t2 = repmat([0 1 0],str2double(sample{2}),1)'; t3 = repmat([0 0 1],str2double(sample{3}),1)'; birdTargets = [t1 t2 t3];
set(handles.featureTable, 'Data', fea);
set(handles.elapseTime, 'String', strcat('Elapse Time : ', num2str(toc), ' seconds'));
set(handles.extractBtn, 'String', 'Clear Features'); else
evalin('base', 'clear dirName'); evalin('base', 'clear audioList'); delete('bird_dataset.mat');
set(handles.browse, 'String', ''); set(handles.audioList, 'String', {''}); set(handles.featureTable, 'Data', cell(0,0));
set(handles.extractBtn, 'String', 'Extract Features'); end
set(handles.busy, 'String', ''); guidata(hObject, handles);
% --- Executes on button press in picBtn.
function picBtn_Callback(hObject, eventdata, handles) % hObject handle to picBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
[filename, path] = uigetfile({'*.jpg;*.jpeg;', 'JPG Files'}, ' Select picture file');
if ~isequal(filename, 0) || ~isequal(path, 0) birdpic = imread([path filename]); handles.birdpic = birdpic; axes(handles.picture); imshow(birdpic); else return end guidata(hObject, handles);
% --- Executes on button press in svinfoBtn.
function svinfoBtn_Callback(hObject, eventdata, handles) % hObject handle to svinfoBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h = get(handles.bird, 'SelectedObject');
birdTag = get(h, 'Tag'); birdInfo = handles.birdInfo;
sciname = get(handles.sciName, 'String'); family = get(handles.family, 'String'); genus = get(handles.genus, 'String'); if strcmp(birdTag, 'bird1')
birdInfo(1).picture = handles.birdpic; birdInfo(1).sciname = sciname;
birdInfo(1).family = family; birdInfo(1).genus = genus; elseif strcmp(birdTag, 'bird2')
birdInfo(2).sciname = sciname; birdInfo(2).family = family; birdInfo(2).genus = genus; else birdInfo(3).picture = handles.birdpic; birdInfo(3).sciname = sciname; birdInfo(3).family = family; birdInfo(3).genus = genus; end handles.birdInfo = birdInfo;
assignin('base', 'birdInfo', birdInfo); guidata(hObject, handles);
% --- Executes when selected object is changed in bird.
function bird_SelectionChangedFcn(hObject, eventdata, handles) % hObject handle to the selected object in bird
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % h = get(handles.bird, 'SelectedObject');
birdTag = get(hObject, 'Tag'); birdInfo = handles.birdInfo; if strcmp(birdTag, 'bird1') axes(handles.picture); imshow(birdInfo(1).picture);
set(handles.sciName, 'String', birdInfo(1).sciname); set(handles.family, 'String', birdInfo(1).family); set(handles.genus, 'String', birdInfo(1).genus); elseif strcmp(birdTag, 'bird2')
axes(handles.picture); imshow(birdInfo(2).picture);
set(handles.sciName, 'String', birdInfo(2).sciname); set(handles.family, 'String', birdInfo(2).family); set(handles.genus, 'String', birdInfo(2).genus); else
axes(handles.picture); imshow(birdInfo(3).picture);
set(handles.sciName, 'String', birdInfo(3).sciname); set(handles.family, 'String', birdInfo(3).family); set(handles.genus, 'String', birdInfo(3).genus); end
% --- Executes on button press in browseBtn.
function browseBtn_Callback(hObject, eventdata, handles) % hObject handle to browseBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) currentDir = pwd;
dirName = uigetdir(currentDir, 'Pick a directory'); handles.dirName = strcat(dirName, '\');
if ~isequal(dirName, 0)
audiofiles = dir(fullfile(dirName,'*.wav'));
set(handles.audioList, 'String', {audiofiles.name}); else
return end
guidata(hObject, handles);
assignin('base', 'dirName', dirName);
assignin('base', 'audioList', {audiofiles.name});
Source code fungsi chunkAudioV2
function [birdlist] = chunkAudioV2(monoinfo, sec, dir)
% chunkAudioV2: Split audio file into {sec} second long chunks %
% Usage:
% birdlist = chunkAudioV2(monoinfo,sec,dir) %
% Description:
% birdlist = chunkAudioV2(monoinfo,sec,dir) returns list birdlist of generated audio
% chunk
% birdlist: Output list filename, duration, and directory name for generated audio chunk files
%
if nargin < 2; sec = 10; end
Fs = monoinfo.SampleRate; chunkDuration = sec; numSamplesPerChunk = chunkDuration*Fs; birdlist = cell(10,3); audioName = monoinfo.Name; mkdir(dir); dirName = dir; chunkCounter = 1;
for startLoc = 1:numSamplesPerChunk:monoinfo.TotalSamples
endLoc = min(startLoc + numSamplesPerChunk - 1, monoinfo.TotalSamples); y = audioread(monoinfo.Filename, [startLoc endLoc]);
duration = (endLoc-startLoc)/Fs;
outFileName = sprintf(strcat(audioName, '%03d.wav'), chunkCounter); name = strcat(dirName,outFileName); birdlist{chunkCounter,1} = outFileName; birdlist{chunkCounter,2} = round(duration); birdlist{chunkCounter,3} = dirName; audiowrite(name, y, Fs); chunkCounter = chunkCounter + 1; end end
Source code fungsi networkTrain function [accuracy,net,yTst,tTst,trainingrecord] = networkTrain(inputs,targets,k,netConfig) clc if nargin < 1 [inputs,targets] = bird_dataset; k = 10; end [O,N] = size(targets); %===============(all class)random================================= % ind0 = randperm(N);
% ind0 = 1:N; %for debugging
% M = floor(N/k); %length(valind & tstind)
%===============(all class)random================================= %===============(per class)not random============================= trueclassind = vec2ind(targets);
t1 = find(trueclassind == 1); t2 = find(trueclassind == 2); t3 = find(trueclassind == 3); ind0 = 1:N;
M = floor((N/3)/k); %length(valind & tstind) % M = 12;
%===============(per class)not random============================= % rng('default') % rng('shuffle') rng(0) if nargin < 1 net = patternnet(10); else if netConfig.hiddenLayer2 ~= 0
net = patternnet([netConfig.hiddenLayer1 netConfig.hiddenLayer2]); else net = patternnet(netConfig.hiddenLayer1); end net.trainFcn = netConfig.trainFcn; net.trainParam.epochs = netConfig.epochs; end net.divideFcn = 'divideind'; net.trainParam.showWindow = false; net.trainParam.showCommandLine = true; yTst = []; tTst = []; for i = 1:k net = configure(net,inputs,targets);
%%===============train,validation,test============================= %random % valind = 1 + M*(i-1):M*i; % if i == k % tstind = 1:M; % trnind = [M+1:M*(k-1),M*k+1:N]; % else % tstind = valind + M; % trnind = [1:valind(1)-1,tstind(end)+1:N]; % end % trnInd = ind0(trnind); % valInd = ind0(valind); % tstInd = ind0(tstind); %not random valind = 1 + M*(i-1):M*i; if i == k tstind = 1:M; trnind = [M+1:M*(k-1),M*k+1:N/3]; else tstind = valind + M; trnind = [1:valind(1)-1,tstind(end)+1:N/3]; end trnInd = [ind0(t1(trnind)),ind0(t2(trnind)),ind0(t3(trnind))]; valInd = [ind0(t1(valind)),ind0(t2(valind)),ind0(t3(valind))]; tstInd = [ind0(t1(tstind)),ind0(t2(tstind)),ind0(t3(tstind))]; net.divideParam.trainInd = trnInd; net.divideParam.valInd = valInd; net.divideParam.testInd = tstInd; %%===============train,validation,test============================== %%===============train,test========================================= %random % tstind = 1 + M*(i-1):M*i; % if i == k % trnind = 1:tstind(1)-1; % else % trnind = tstind(end)+1:N; % end % trnInd = ind0(trnind); % tstInd = ind0(tstind); %not random % tstind = 1 + M*(i-1):M*i; % if i == k % trnind = 1:tstind(1)-1; % else % trnind = tstind(end)+1:N/3; % end % trnInd = [ind0(t1(trnind)),ind0(t2(trnind)),ind0(t3(trnind))]; % tstInd = [ind0(t1(tstind)),ind0(t2(tstind)),ind0(t3(tstind))];
% net.divideParam.trainInd = trnInd; % net.divideParam.testInd = tstInd;
%%===============train,test========================================= [net,tr,y,e] = train(net,inputs,targets);
% Test Confusion Plot Variables ytst = net(inputs(:,tr.testInd)); yTst = [yTst ytst];
ttst = targets(:,tr.testInd); tTst = [tTst ttst];
trainingrecord{i} = tr; end
Nerr = sum(vec2ind(yTst) ~= vec2ind(tTst)); PctErr = 100*Nerr/size(yTst,2);
accuracy = 100 - PctErr; end
Source code Training and Testing GUI
function varargout = TrainingAndTesting(varargin)
% TRAININGANDTESTING MATLAB code for TrainingAndTesting.fig
% TRAININGANDTESTING, by itself, creates a new TRAININGANDTESTING or raises the existing
% singleton*. %
% H = TRAININGANDTESTING returns the handle to a new TRAININGANDTESTING or the handle to
% the existing singleton*. %
% TRAININGANDTESTING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TRAININGANDTESTING.M with the given input arguments.
%
% TRAININGANDTESTING('Property','Value',...) creates a new TRAININGANDTESTING or raises the
% existing singleton*. Starting from the left, property value pairs are % applied to the GUI before TrainingAndTesting_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to TrainingAndTesting_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
% Last Modified by GUIDE v2.5 22-Jul-2016 15:39:32 % Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TrainingAndTesting_OpeningFcn, ... 'gui_OutputFcn', @TrainingAndTesting_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 TrainingAndTesting is made visible.
function TrainingAndTesting_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 TrainingAndTesting (see VARARGIN) % Choose default command line output for TrainingAndTesting
handles.output = hObject; % Update handles structure guidata(hObject, handles);
% UIWAIT makes TrainingAndTesting wait for user response (see UIRESUME) % uiwait(handles.figure1);
addMyPath;
set(handles.busy, 'String', 'Ready');
if evalin('base', 'exist(''templateData'')') templateData = evalin('base', 'templateData'); else
templateData = struct('mean',{1:13 1:26 1:39},'variance',{40:52 40:65 40:78},'min',{79:91 79:104 79:117},'max',{118:130 118:143 118:156}); assignin('base', 'templateData', templateData);
end
if evalin('base', 'exist(''logDataTrain'')') logDataTrain = evalin('base', 'logDataTrain'); set(handles.logTable, 'Data', logDataTrain); else
set(handles.logTable, 'Data', logDataTrain); assignin('base', 'logDataTrain', logDataTrain); end
handles.templateData = templateData; handles.logDataTrain = logDataTrain; guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = TrainingAndTesting_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 during object creation, after setting all properties. function trainFcn_CreateFcn(hObject, eventdata, handles)
% hObject handle to trainFcn (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 set(hObject, 'String', {'traingdm','traingda','traingdx','traincgf','traincgp','traincgb','trainscg','tra inlm','trainrp'});
% --- Executes on button press in trainTest.
function trainTest_Callback(hObject, eventdata, handles) % hObject handle to trainTest (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.busy, 'String', 'Busy');
drawnow
h = get(handles.mfccCoe, 'SelectedObject'); mfccTag = get(h, 'Tag');
mean = 0; variance = 0; min = 0; max = 0; if strcmp(mfccTag, 'noDelta') x = 1;
elseif strcmp(mfccTag, 'delta') x = 2;
else x = 3; end templateData = handles.templateData; if (get(handles.mean,'Value') == 1) mean = templateData(x).mean; end if (get(handles.variance,'Value') == 1) variance = templateData(x).variance; end if (get(handles.min,'Value') == 1) min = templateData(x).min; end if (get(handles.max,'Value') == 1) max = templateData(x).max; end [x,targets] = bird_dataset; data = x';
selected = [mean variance min max]; assignin('base', 'selected', selected); inputs = data(:,selected(selected~=0)); trainFcnh = get(handles.trainFcn,'String');
trainFcnv = trainFcnh{get(handles.trainFcn,'Value')};
netConfig.hiddenLayer1 = str2double(get(handles.hiddenLayer1, 'String')); netConfig.hiddenLayer2 = str2double(get(handles.hiddenLayer2, 'String')); netConfig.epochs = str2double(get(handles.epochs, 'String'));
netConfig.trainFcn = trainFcnv;
k = str2double(get(handles.kfold, 'String')); tic
% [accuracy, conmat, net] = netTrain(dataset',netConfig);
[accuracy,net,yTst,tTst,tr] = networkTrain(inputs',targets,k,netConfig); tstop = toc;
set(handles.accuracy, 'String', strcat(num2str(accuracy),'%')); set(handles.elapseTime, 'String', strcat(num2str(tstop), ' seconds')); handles.yTst = yTst; handles.tTst = tTst; logDataTrain = handles.logDataTrain; r = size(logDataTrain,1); logDataTrain{r+1,1} = mfccTag; logDataTrain{r+1,2} = get(handles.mean,'Value'); logDataTrain{r+1,3} = get(handles.variance,'Value'); logDataTrain{r+1,4} = get(handles.min,'Value'); logDataTrain{r+1,5} = get(handles.max,'Value');
logDataTrain{r+1,6} = str2double(get(handles.hiddenLayer1, 'String')); logDataTrain{r+1,7} = str2double(get(handles.hiddenLayer2, 'String')); logDataTrain{r+1,8} = trainFcnv;
logDataTrain{r+1,9} = k;
logDataTrain{r+1,10} = num2str(accuracy); logDataTrain{r+1,11} = num2str(tstop); handles.logDataTrain = logDataTrain;
set(handles.logTable, 'Data', logDataTrain); assignin('base', 'net', net);
assignin('base', 'logDataTrain', logDataTrain); assignin('base', 'tr', tr);
set(handles.busy, 'String', ''); guidata(hObject, handles);
% --- Executes on button press in plotconf.
function plotconf_Callback(hObject, eventdata, handles) % hObject handle to plotconf (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) figure,
plotconfusion(handles.tTst,handles.yTst)
Source code Classify GUI
function varargout = Classify(varargin) % CLASSIFYBTN MATLAB code for classifybtn.fig
% CLASSIFYBTN, by itself, creates a new CLASSIFYBTN or raises the existing % singleton*.
%
% H = CLASSIFYBTN returns the handle to a new CLASSIFYBTN or the handle to % the existing singleton*.
%
% CLASSIFYBTN('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in CLASSIFYBTN.M with the given input arguments. %
% CLASSIFYBTN('Property','Value',...) creates a new CLASSIFYBTN or raises the