I'm trying to create an interface with the gui MATLAB 2015a, but I'm getting an error from the command window that " Undefined function or variable "frame". Error in ForTA>test_mfcc_Callback (line 304) rata_frame=mean(frames);
when i press push button "test mfcc", i can't get value for pre-emphasis to coefficen cepstrum. due to error in line 304
This my source code :
function varargout = ForTA(varargin)
% FORTA MATLAB code for ForTA.fig
% FORTA, by itself, creates a new FORTA or raises the existing
% singleton*.
%
% H = FORTA returns the handle to a new FORTA or the handle to
% the existing singleton*.
%
% FORTA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FORTA.M with the given input arguments.
%
% FORTA('Property','Value',...) creates a new FORTA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ForTA_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ForTA_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
% edit1 the above text to modify the response to help ForTA
% Last Modified by GUIDE v2.5 05-Nov-2021 21:15:13
% Begin initialization code - DO NOT EDIT1
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ForTA_OpeningFcn, ...
'gui_OutputFcn', @ForTA_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 EDIT1
% --- Executes just before ForTA is made visible.
function ForTA_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 ForTA (see VARARGIN)
% Choose default command line output for ForTA
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ForTA wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ForTA_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;
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: edit1 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 browse.
function browse_Callback(hObject, eventdata, handles)
% hObject handle to browse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname]=uigetfile ('*.wav*');
if ~isequal (filename, 0)
[y,Fs] = audioread(fullfile (pathname,filename));
a=0.97;
y2= filter ((1-a), 1, y);
time=(1:length(y))/Fs;
time1=(length(y))/Fs;
axes (handles.axe_original);
plot(time, y);
grid on
set (gca, 'unit', 'pixel');
axes(handles.axe_emphasis)
plot(time,y2);
grid on
set (gca, 'unit', 'pixel');
set (handles.edit1, 'string',filename)
set (handles.edit2,'string',Fs);
set (handles.edit3,'string',time1);
[y,Fs] = audioread(fullfile(pathname,filename));
else
return
end
handles.y2 = y2;
handles.y = y;
handles.Fs = Fs;
handles.time1 = time1;
guidata(hObject,handles)
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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 edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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 edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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 Test.
function Test_Callback(hObject, eventdata, handles)
% hObject handle to Test (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% a = data input training data dari excel
a=xlsread ('C:\Users\waf_r\Download\refsuara\input.xlsx','Sheet1');
cepstrum=handles.cepstrum
time1=handles.time1;
c=[cepstrum;time1];
t(1:3)=1;t(4:6)=2;t(7:9)=3;t(10:12)=4;t(13:15)=5;t(16:18)=6;t(19:21)=7;t(22:24)=8;
net = newff (a', t, [10 5], {'logsig', 'logsig'},'trainlm');
%melihat bobot, bobot akan diberikan secara acak oleh matlab
bobotawal_Input = net.IW(1,1);
bobotawal_bias_input = net.b(1,1);
%parameter training
net.trainParam.show = 25;
net.trainParam.epochs = 5000; %jumlah maksimum epoch
net.trainParam.goal = 0.00000000001; %nilai minimum error
net.trainParam.min_grad=le-10;
net.trainParam.max_fail=1000000000000000000000000000000000000000000000000000000
net.trainParam.Ir=0.01; %nilai learning rate
%training jaringan
net = train (net,a',t);
save net.mat
%uji jaringan;
y=sim(net,c');
y=round(y);
switch y
case 1
set (handles.edithasil, 'String','Sa','Visible','on')
case 2
set (handles.edithasil, 'String','Sho','Visible','on')
case 3
set (handles.edithasil, 'String','Dza','Visible','on')
case 4
set (handles.edithasil, 'String','Za','Visible','on')
case 5
set (handles.edithasil, 'String','Qo','Visible','on')
case 6
set (handles.edithasil, 'String','Ka','Visible','on')
case 7
set (handles.edithasil, 'String','A','Visible','on')
case 8
set (handles.edithasil, 'String','^A','Visible','on')
end
%akurasi hasil training
X= round (sim(net,a'));
%hasil=(t,X);
n=length(t);
b=0;
%b=jumlah input yang memiliki nilai sama dengan target
for i=1:n
if X(i)==t(i)
b=b+1;
end
end
b;
ak=(b/n)*100;
disp (['accuracy JARINGAN SYARAF TIRUAN =',num2str(ak,'%2f'),'%'])
% --- Executes on button press in Play_ori.
function Play_ori_Callback(hObject, eventdata, handles)
% hObject handle to Play_ori (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
y=handles.y;
Fs=handles.Fs;
sound(y,Fs);
% --- Executes on button press in Play_emphasis.
function Play_emphasis_Callback(hObject, eventdata, handles)
% hObject handle to Play_emphasis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%framing1
y=handles.y;
a=0.97;
y2=filter((1-a),1,y);
Fs=handles.Fs;
sound(y2,Fs);
% --- Executes on button press in test_mfcc.
function test_mfcc_Callback(hObject, eventdata, handles)
% hObject handle to test_mfcc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
y=handles.y;
Fs=handles.Fs;
a=0.97;
y2=filter((1-a),1,y);
n=512 %Number of FAST FOURIER TRANSFORM points
Tf=(length(y))/Fs; %Frame duration in seconds
N=Fs*Tf; %Number of samples per frame
fn=24; %Number of mel filters
l=length(y); %total number of sample speech
Ts=0.01; %Framse step in seconds
FrameStep=Fs*Ts; %Frame step in samples
noFrame=floor(1/FrameStep); %Maximum no of frames in speech sample
for i=1:noFrame
frame=y2((i-1)*FrameStep+1:(i-1)*FrameStep+N); %Holds individual frames
end
rata_frame=mean(frame);
set(handles.framing1,'string',rata_frame);
figure;
plot(frame(1,:));
handles.frame = frame;
handles.rata_frame = rata_frame;
%proses windowing
Fs=handles.Fs;
t=(1:512)'/Fs;
n=512;
f=n/t;
original=sin(2*pi*f*t)+0.2*randn(length(t),1);
windowed = original.*hamming(length(t));
rata_window = mean (windowed);
set (handles.windowing,'string',rata_window);
handles.rata_window = rata_window;
%FAST FOURIER TRANSFORM
Fs=handles.Fs;
a=0.97;
%y2=filter([1-a],1,y);
n=4096; %Power of 2 number of samples/length of FAST FOURIER TRANSFORM
%Get/Generate data
t=0:1/Fs:(n-1)/Fs; %n/fs sec sample
x=(1.3)*sin(2*pi*1500*t) ... % 1.5k Hz component
+ (1.7)*sin(2*pi*4000*(t-2)) ... %4.0k Hz component
+ (2.5)*randn(size(t));
%# Frequency Bins
bins = (0:1:n-1)*(Fs/n);
y = fft(x,n);
rata_fft = mean (y);
set(handles.fft, 'string', rata_fft);
handles.rata_fft = rata_fft;
%DISCRETE COSINE TRANSFORM
y=handles.y;
in_dct = f_fft_(y);
% Input for a DISCRETE COSINE TRANSFORM Transform
k=0 : ( length (in_dct)-1);
%limits for Variable K tends to N-1.
ex=exp (-j*k*pi/length(in_dct));
%Multiplaying Co-efficient.
in_dct=in_dct.*ex; %Point to point Multiplication.
in_dct=2*real(in_dct); % Extraction of Real-Part and Multiplaying with 2.
n=length(in_dct);
%Length of the input_dicrete cosine transform.
p=1:n; %To Get Even Symethric Output Waveform (DISCRETE COSINE TRANSFORM).
n=length (in_dct)/2;
%Length of the input_discrete cosine transform halved.
p=1:n; %samples halved
x(p)=in_dct(p);%Storing valves in another Variable.
x;
rata_dct=mean (x);
set(handles.dct,'string',rata_dct); %Cepstrallifter
Fs=handles.Fs;
y2=handles.y2;
y2 = y2 (:,1); %get the first channel
xmax = max (abs(y2)); %find the maximum value
y2=y2/xmax; %scale the sinal
%time vector generation
N= length (y2);
t= (0:N-1)/Fs;
% cepstral analysis
[C,q] = cepstrum (y2,Fs);
handles.C = C;
%plot of the signal
figure;
subplot (2,1,1)
plot (t,y2,'r')
xlim([0 max (t)])
ylim([-1.1*max(abs(y2)) 1.1*max(abs(y2))])
grid on
set (gca, 'FontName', 'Times New Roman', 'FontSize',12)
xlabel ('Time,s')
ylabel ('Normalized amplitude')
title ('The signal in the time domain')
%plot of the cepstrum
%1 ms minimum speech quefrency (1000 Hz) and 20 ms maximum speech qufrency(50 Hz)
subplot (2,1,2)
plot (q*1000, C, 'r');
grid on
xlim ([1 20])
set (gca, 'FontName', 'Times New Roman', 'FontSize', 12)
xlabel('Quefrency, ms')
ylabel('Amplitude')
title('Amplitude cepstrum of the signal(quefrencies from ms to 20 ms)')
%rata-rata nilai cepstrum
C=handles.C;
rata=mean(C);
handles.rata =rata;
set(handles.cepstrum, 'string',rata);
%handles.rata = rata;
function framing1_Callback(hObject, eventdata, handles)
% hObject handle to framing1 (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 framing1 as text
% str2double(get(hObject,'String')) returns contents of framing1 as a double
% --- Executes during object creation, after setting all properties.
function framing1_CreateFcn(hObject, eventdata, handles)
% hObject handle to framing1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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 windowing_Callback(hObject, eventdata, handles)
% hObject handle to windowing (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 windowing as text
% str2double(get(hObject,'String')) returns contents of windowing as a double
% --- Executes during object creation, after setting all properties.
function windowing_CreateFcn(hObject, eventdata, handles)
% hObject handle to windowing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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 edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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 edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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 edit9_Callback(hObject, eventdata, handles)
% hObject handle to edit9 (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 edit9 as text
% str2double(get(hObject,'String')) returns contents of edit9 as a double
% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit1 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