when i look this page 我真的不知道如何实现这个计时器
我想按下pushbutton2时创建对象计时器,当pussbutton2中的进程完成时计时器将停止
注意:计时器将显示在text1
中
这是我的代码:
function pushbutton2_Callback(hObject, eventdata, handles) global x
global fs global silenceRemovedSignal THRESHOLD =
str2double(get(handles.edit1,'String'));
samplePerFrame=floor(fs/100); bgSampleCount=floor(fs/5); %according
to formula, 1600 sample needed for 8 khz
%---------- %calculation of mean and std bgSample=[]; for
i=1:1:bgSampleCount
bgSample=[bgSample x(i)]; end meanVal=mean(bgSample); sDev=std(bgSample); %---------- %identify voiced or not for each
value for i=1:1:length(x) if(abs(x(i)-meanVal)/sDev > THRESHOLD)
voiced(i)=1; else
voiced(i)=0; end end
% identify voiced or not for each frame %discard insufficient samples
of last frame
usefulSamples=length(x)-mod(length(x),samplePerFrame);
frameCount=usefulSamples/samplePerFrame; voicedFrameCount=0; for
i=1:1:frameCount cVoiced=0; cUnVoiced=0; for
j=i*samplePerFrame-samplePerFrame+1:1:(i*samplePerFrame)
if(voiced(j)==1)
cVoiced=(cVoiced+1);
else
cUnVoiced=cUnVoiced+1;
end end %mark frame for voiced/unvoiced if(cVoiced>cUnVoiced)
voicedFrameCount=voicedFrameCount+1;
voicedUnvoiced(i)=1; else
voicedUnvoiced(i)=0; end end
silenceRemovedSignal=[];
%----- for i=1:1:frameCount
if(voicedUnvoiced(i)==1)
for j=i*samplePerFrame-samplePerFrame+1:1:(i*samplePerFrame)
silenceRemovedSignal= [silenceRemovedSignal x(j)];
end
end end
global t4 t4=(0:length(silenceRemovedSignal)-1)/fs;
set(handles.axes2,'HandleVisibility','ON'); axes(handles.axes2); axis
on;
plot(t4,silenceRemovedSignal/(max(silenceRemovedSignal)),'Color',[1.0
0.0 0.0]); grid on; clc;