matlab code

Upload: deepak

Post on 08-Oct-2015

219 views

Category:

Documents


0 download

DESCRIPTION

speech recognition

TRANSCRIPT

MATLAB CODE

function f = yesno(filename) % This is the main function to distinguish 'YES' from 'NO'

% Block SizeN = 600; % Block IncrementM = 200;% Threshold to discardsumthresh = 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 Mn = 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); endend

function f = strip(blocks, sumthresh, zerocrossthresh) % This function removes leading and trailing blocks that do not contain sufficient energy or frequency to warrent consideration.% Total energy is measured by summing the entire vector.% Frequency is measured by counting the number of times 0 is crossed.% The parameters sumthresh and zerocrossthrech are the thresholds, averaged across each sample, above which consideration is warrented.% A good sumthresh would be 0.035% A good zerocrossthresh would be 0.060 len = length(blocks);n = sum(size(blocks)) - len;min = n+1;max = 0;sumthreshtotal = len * sumthresh;zerocrossthreshtotal = len * zerocrossthresh;for i = 1:n currsum = sum(abs(blocks(i,1:len))); currzerocross = zerocross(blocks(i,1:len)); if or((currsum > sumthreshtotal),(currzerocross > zerocrossthreshtotal)) if i < min min = i; end if i > max; max = i; end endend if max > min 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; endend f = currsum;