Professional Documents
Culture Documents
function f = yesno(filename)
% This is the main function to distinguish 'YES' from 'NO'
% Block Size
N = 600;
% Block Increment
M = 200;
% Threshold to discard
sumthresh = 0.035;
zerocrossthresh = 0.060;
rawdata = wavread(filename);
blockeddata = block(rawdata,N,M);
strippeddata = strip(blockeddata,sumthresh,zerocrossthresh);
zerocrossdata = zerocrossmap(strippeddata);
plot(zerocrossdata);
maxzerocross = max(zerocrossdata);
if (maxzerocross < 5)
f='INSUFFICIENT DATA';
elseif (maxzerocross > 100)
f='YES';
else
f='NO';
end
function f = block(v, N, M)
% This function separates the vector into blocks. Each
block has size N and consecutive blocks differ in
% their starting positions by M
n = length(v);
maxblockstart = n - N + 1;
lastblockstart = maxblockstart - mod(maxblockstart-1 ,
M);
numblocks = (lastblockstart-1)/M + 1;
f = zeros(numblocks,N);
for i = 1:numblocks
for j = 1:N
f(i,j) = v((i-1)*M+j);
end
end
f = blocks(min:max,1:len);
else
f = zeros(0,0);
end
function f = zerocrossmap(blocks);
% This counts the zero cross count for each block
% and returns a vector of those values.
len = length(blocks);
n = sum(size(blocks)) - len;
f = zeros(n,1);
for i = 1:n
f(i) = zerocross(blocks(i,1:len));
end
function f = zerocross(vector)
% This function simply reports the number of times
% that the input vector crosses the zero boundary
len = length(vector);
currsum = 0;
prevsign = 0;
for i = 1:len
currsign = sign(vector(i));
if (currsign * prevsign) == -1
currsum = currsum + 1;
end
if currsign ~= 0
prevsign = currsign;
end
end
f = currsum;