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.');

Antworten (1)

Walter Roberson
Walter Roberson am 12 Feb. 2020

0 Stimmen

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.

Kategorien

Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 12 Feb. 2020

Beantwortet:

am 12 Feb. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by