Automation Algorithm
Solution
clear all
clc
[y,fs]=audioread(‘tones_set1.wav’);
L=input(‘Logical:’);
t=0:1/fs:(length(y)-1)/fs;
i=2;
k=1;
while i<=length(y)
if y(i-1)==0&&y(i)~=0
A(k,1)=t(i);
end
if y(i-1)~=0&&y(i)==0
B(k,1)=t(i);
Time_tones(k,1)=B(k,1)-A(k,1);
k=k+1;
end
i=i+1;
end
if L==1
H={‘Time of the tones’,’start(seg)’,’finish(seg)’};
HH=[Time_tones A B];
Table=[H;num2cell(HH)]
plot(t,y)
soundsc(y,fs)
end
if L==0
H={‘Time of the tones’,’start(seg)’,’finish(seg)’};
HH=[Time_tones A B];
Table=[H;num2cell(HH)]
plot(t,y)
title(‘Tone vs time’)
legend(num2str(Time_tones’))
soundsc(y,fs)
end