wolffd@0: function varargout = mirzerocross(orig,varargin) wolffd@0: % mirzeroscross(x) computes the sign-changes rate along the signal x, wolffd@0: % i.e., how many time the waveform crosses the X-axis. When applied on wolffd@0: % an audio waveform, gives a notion of noise. wolffd@0: % Optional argument: wolffd@0: % mirzerocross(...,'Per',p) precises the temporal reference for the wolffd@0: % rate computation. wolffd@0: % Possible values: wolffd@0: % p = 'Second': number of sign-changes per second (Default). wolffd@0: % p = 'Sample': number of sign-changes divided by the total wolffd@0: % number of samples. wolffd@0: % The 'Second' option returns a result equal to the one returned wolffd@0: % by the 'Sample' option multiplied by the sampling rate. wolffd@0: % mirzerocross(...,'Dir',d) precises the definition of sign change. wolffd@0: % Possible values: wolffd@0: % d = 'One': number of sign-changes from negative to positive wolffd@0: % only (or, equivalently, from positive to negative only). wolffd@0: % (Default) wolffd@0: % d = 'Both': number of sign-changes in both ways. wolffd@0: % The 'Both' option returns a result equal to twice the one wolffd@0: % returned by the 'One' option. wolffd@0: wolffd@0: wolffd@0: per.key = 'Per'; wolffd@0: per.type = 'String'; wolffd@0: per.choice = {'Second','Sample'}; wolffd@0: per.default = 'Second'; wolffd@0: option.per = per; wolffd@0: wolffd@0: dir.key = 'Dir'; wolffd@0: dir.type = 'String'; wolffd@0: dir.choice = {'One','Both'}; wolffd@0: dir.default = 'One'; wolffd@0: option.dir = dir; wolffd@0: wolffd@0: specif.option = option; wolffd@0: wolffd@0: varargout = mirfunction(@mirzerocross,orig,varargin,nargout,specif,@init,@main); wolffd@0: wolffd@0: wolffd@0: function [x type] = init(x,option) wolffd@0: if not(isamir(x,'mirdata')) wolffd@0: x = miraudio(x); wolffd@0: end wolffd@0: type = 'mirscalar'; wolffd@0: wolffd@0: wolffd@0: function z = main(a,option,postoption) wolffd@0: if iscell(a) wolffd@0: a = a{1}; wolffd@0: end wolffd@0: d = get(a,'Data'); wolffd@0: f = get(a,'Sampling'); wolffd@0: v = cell(1,length(d)); wolffd@0: for h = 1:length(d) wolffd@0: v{h} = cell(1,length(d{h})); wolffd@0: for i = 1:length(d{h}) wolffd@0: di = d{h}{i}; wolffd@0: nc = size(di,2); wolffd@0: nf = size(di,3); wolffd@0: nl = size(di,1); wolffd@0: zc = sum( di(2:end,:,:).*di(1:(end-1),:,:) < 0 ) /nl; wolffd@0: if strcmp(option.per,'Second') wolffd@0: zc = zc*f{h}; wolffd@0: end wolffd@0: if strcmp(option.dir,'One') wolffd@0: zc = zc/2; wolffd@0: end wolffd@0: v{h}{i} = zc; wolffd@0: end wolffd@0: end wolffd@0: z = mirscalar(a,'Data',v,'Title','Zero-crossing rate');