Daniel@0: function varargout = mirflatness(orig,varargin) Daniel@0: % f = mirflatness(x) calculates the flatness of x, which can be either: Daniel@0: % - a spectrum (spectral flatness), Daniel@0: % - an envelope (temporal flatness), or Daniel@0: % - any histogram. Daniel@0: Daniel@0: Daniel@0: varargout = mirfunction(@mirflatness,orig,varargin,nargout,struct,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: if not(isamir(x,'mirenvelope') || isamir(x,'mirhisto')) Daniel@0: x = mirspectrum(x); Daniel@0: end Daniel@0: type = 'mirscalar'; Daniel@0: Daniel@0: Daniel@0: function f = main(x,option,postoption) Daniel@0: if iscell(x) Daniel@0: x = x{1}; Daniel@0: end Daniel@0: m = get(x,'Data'); Daniel@0: y = cell(1,length(m)); Daniel@0: for h = 1:length(m) Daniel@0: if not(iscell(m{h})) % for histograms Daniel@0: m{h} = {m{h}'}; Daniel@0: end Daniel@0: y{h} = cell(1,length(m{h})); Daniel@0: for i = 1:length(m{h}) Daniel@0: mm = m{h}{i}; Daniel@0: nl = size(mm,1); Daniel@0: ari = mean(mm); Daniel@0: geo = (prod(mm.^(1/nl))); Daniel@0: divideByZero = warning('query','MATLAB:divideByZero'); Daniel@0: logZero = warning('query','MATLAB:log:logOfZero'); Daniel@0: warning('off','MATLAB:divideByZero'); Daniel@0: warning('off','MATLAB:log:logOfZero'); Daniel@0: y{h}{i} = ...10*log10( Daniel@0: geo./ari;%); Daniel@0: warning(divideByZero.state,'MATLAB:divideByZero'); Daniel@0: warning(logZero.state,'MATLAB:log:logOfZero'); Daniel@0: nany = find(isinf(y{h}{i})); Daniel@0: y{h}{i}(nany) = zeros(size(nany)); Daniel@0: end Daniel@0: end Daniel@0: if isa(x,'mirenvelope') Daniel@0: t = 'Temporal flatness'; Daniel@0: elseif isa(x,'mirspectrum') Daniel@0: t = 'Spectral flatness'; Daniel@0: else Daniel@0: t = ['Flatness of ',get(x,'Title')]; Daniel@0: end Daniel@0: f = mirscalar(x,'Data',y,'Title',t,'Unit','');