% calculates the number of zero crossings in a signal ip function [indices, num_zeros] = zero_crossings(ip) ip = ip + power(2, -100); end_element = ip(length(ip)); start_element = ip(1); a = [ip, end_element]; % new ip array with no new zero crossings with an additional element b = [start_element, ip]; % shifted version of ip (shifted once to the right) with no extra zero crossings sign_a = sign(a); sign_b = sign(b); c = sign_a + sign_b; % count the number of zeros in c. This is equal to the number of zero crossings (Well not quite.. since an existing string of zeros will be counted as zero cross points. This is okay for voiced unvoiced decision though) % quick way of counting zeros; abs_c = abs(sign(c)); % every element is either a one or a zero num_zeros = length(abs_c) - sum(abs_c); indices = find(c == 0) - 1; % END of function to calculate the zero crossings