execute automatically Stop button command after X seconds that Start Button is pressed - GUI
이전 댓글 표시
Hi everybody. I have a problem with a real time demo. I am trying to execute automatically the commands into the Stop Button after X seconds that the Start Button is pressed. Here the two callback functions of the start button and stop button.
function startButton_Callback(hObject, eventdata, handles)
% hObject handle to startButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
myGUIdata=guidata(handles.realTimeSgramGUI);
% cla(handles.freq_response_plot)
handles.ttt = timer('TimerFcn',{@stopButton_Callback, handles},'StartDelay',62);
disp('Start')
audioFile='file1.wav';
[audioFileFCN, Fs_audio] = audioread(audioFile);
start(handles.ttt)
sound(audioFileFCN,Fs_audio);
myGUIdata = guidata(handles.realTimeSgramGUI);
set(myGUIdata.saveButton,'enable','off');
set(myGUIdata.startButton,'enable','off');
set(myGUIdata.playButton,'enable','off');
set(myGUIdata.stopButton,'enable','on');
set(myGUIdata.displayPopupMenu,'enable','off');
switch get(myGUIdata.timer50ms,'running')
case 'on'
stop(myGUIdata.timer50ms);
end
myGUIdata.audioRecorderCount = myGUIdata.maxAudioRecorderCount;
myGUIdata.lastPosition = 1;
record(myGUIdata.recordObj1);
switch get(myGUIdata.timer50ms,'running')
case 'off'
start(myGUIdata.timer50ms);
case 'on'
otherwise
disp('timer is bloken!');
end
guidata(handles.realTimeSgramGUI,myGUIdata);
end
function stopButton_Callback(hObject, eventdata, handles)
global durToClass
global train_net
% hObject handle to stopButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%%%%%%% CLASSIFICATION%%%%%%
%%% GET all data from when Start is pressed;
myGUIdata = guidata(handles.realTimeSgramGUI);
delete(handles.ttt)
myGUIdata.audioData = getaudiodata(myGUIdata.recordObj1);
recorded = myGUIdata.audioData(:,1)+ 1i*myGUIdata.audioData(:,2);
% duration = floor(size(recorded,1)/22000)
% Start_C = size(recorded,1)- 22000*durToClass +1
% Stop_C = size(recorded,1)
Bl = str2double(get(handles.Bl_editText,'String'));
f_r = str2double(get(handles.risonanceFrequency_editText,'String'));
q_ts = str2double(get(handles.q_ts_editText,'String'));
q_es = str2double(get(handles.q_es_editText,'String'));
coil_rad = str2double(get(handles.coilRadius_editText,'String'));
f_v1 = str2double(get(handles.fv1_editText,'String'));
f_v2 = str2double(get(handles.fv2_editText,'String'));
volt= str2double(get(handles.volt_editText,'String'));
f_s=str2double(get(handles.frequencySampling_editText,'String'));
lengthAcq=str2double(get(handles.lengthAcquisition_editText,'String'));
wavelength=str2double(get(handles.wavelength_editText,'String'));
fft_bins=str2double(get(handles.fftbins_editText,'String'));
t=linspace(0,lengthAcq,lengthAcq*f_s);
f_v=f_v1*((f_v2/f_v1)^(1/lengthAcq)).^t;
toClass = recorded(end-22000*durToClass +1:end);
toClass= toClass- mean(toClass);
toClass=toClass./max(abs(toClass));
toClass=lowpass(toClass,5000,f_s);
% whos toClass
downSamplingmic=1;
[orig_ss,Fs_audio]=audioread('file.wav');
orig_ss=orig_ss(1*Fs_audio + 1:downSamplingmic:(1 + lengthAcq)*Fs_audio,1);
envelope_sig=resample(orig_ss,f_s,Fs_audio).';
gamma_c=1./(1-(f_v.^2./f_r^2)+(1i*f_v./f_r/q_ts));
% gamma_c2=1./(1-(fv.^2./fs^2)+(1i*fv./fs/2));
displ_amplitude=volt.*gamma_c./(2*pi*f_r*Bl*q_es);
range=abs(displ_amplitude).*envelope_sig;
sigma=2*pi*coil_rad/wavelength^2;
y=sigma.*(cos(4*pi*range./wavelength)+1i*sin(4*pi*range./wavelength)); %((1./(1-xxx)).^2).*
% y=sigma.*(1./(1-xxx)).^2.*(4*pi*xxx./lambda + 1i*sin(4*pi*xxx./lambda));
y = y-mean(y);
y = y./max(abs(y));
resampled_freq=linspace(1,(2*lengthAcq)*f_s-1,4096);
[impulse_response, lag]=xcorr(angle(toClass(:)),angle(y(:)));
% [impulse_resp_phase, ~]=xcorr(toClass(:)./abs(toClass(:)),y(:)./abs(y(:)));
%
[~, pos]=max(abs(impulse_response));
time_start=lag(pos)/f_s
[im_re_full, ~]=xcorr(angle(toClass(round(time_start*f_s)+1:round((time_start+lengthAcq)*f_s))),angle(y(:)));
DUT=FR_generation(im_re_full)
axes(handles.freq_response_plot)
semilogx(linspace(0,f_s/2,length(DUT(1,:))),DUT(1,:),'b','LineWidth',1);
hold on
semilogx(linspace(0,f_s/2,length(DUT(1,:))),DUT(2,:),'r','LineWidth',1);
semilogx(linspace(0,f_s/2,length(DUT(1,:))),DUT(3,:),'k','LineWidth',1);
semilogx(linspace(0,f_s/2,length(DUT(1,:))),DUT(4,:),'g','LineWidth',1);
semilogx(linspace(0,f_s/2,length(DUT(1,:))),DUT(5,:),'m','LineWidth',1);
%%% LOAD CLASSIFIER %%%%
%%%% CLASSIFY%%%%
DUT_cell=mat2cell(DUT,5);
whos DUT_cell
YPred = classify(train_net,DUT_cell,'MiniBatchSize',1,'SequenceLength','longest');
% whos YPred
%classNumber = randi(5,1); %%% OUTPUT CLASSIFICATION
switch YPred
case categorical(1)
CurrentClass = 'Good';
ColorTD = 'green';
case categorical(2)
CurrentClass = 'Bad';
ColorTD = 'red';
case categorical(3)
CurrentClass = 'Bad2';
ColorTD = 'red';
otherwise
CurrentClass = 'Undefined';
ColorTD = 'red';
end
%%% VISUALIZE CLASSIFICATION OUTPUT
set(myGUIdata.Class,'string', CurrentClass);
set(myGUIdata.Class,'BackgroundColor', ColorTD);
%%%%
myGUIdata = guidata(handles.realTimeSgramGUI);
set(myGUIdata.saveButton,'enable','on');
set(myGUIdata.startButton,'enable','on');
set(myGUIdata.playButton,'enable','on');
set(myGUIdata.stopButton,'enable','off');
set(myGUIdata.displayPopupMenu,'enable','on');
switch get(myGUIdata.timer50ms,'running')
case 'on'
stop(myGUIdata.timer50ms)
case 'off'
otherwise
disp('timer is bloken!');
end
myGUIdata.audioData = getaudiodata(myGUIdata.recordObj1);
stop(myGUIdata.recordObj1);
guidata(handles.realTimeSgramGUI,myGUIdata);
end
Even if the code gets into the Stop Button function, I have some errors as:
Error while evaluating TimerFcn for timer 'timer-2'
Reference to non-existent field 'ttt'
How Can I fix this? Any idea?
Thanks
Ale
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB Mobile Fundamentals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!