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