Here is the code which i m trying to implement and plotting digital high and digtial low signal if value from signal exceeds a certain value but matlab is not plotting second graph ( z with respect to t ) . Any help would be appreciated.
recorder = audiorecorder(22000, 8, 2);
disp('Start speaking.')
recorder.record(20);
startTime = datetime('now');
z=[];
while recorder.isrecording()
pause(0.1);
y = (getaudiodata(recorder));
x=abs(y);
[up1,lo1] = envelope(x,4000,'rms');
t = datetime('now') - startTime;
t = t*24*3600;
%x=smooth(up1,'sgolay');
%pks = findpeaks(up1,'MinPeakDistance',10000);
%up1
if (up1>0.15)
z=[z 1];
else
z=[z 0];
end
subplot(2,1,1)
plot(up1);
drawnow();
subplot(2,1,2)
plot(t,z);
drawnow();
end
disp('End of Recording.');

답변 (1개)

Walter Roberson
Walter Roberson 2020년 2월 12일

0 개 추천

envelope returns a vector. Not all elements of the vector are greater than 0.15 so the if fails, because if is only true if all the items in the array being tested are true. So you always do the else case and append 0 to z. Then when you plot z it is all zero and you do not happen to notice that because the default plot range would put the zeros exactly at the bottom axes where it is easy to overlook.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

질문:

2020년 2월 12일

답변:

2020년 2월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by