annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirflatness.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function varargout = mirflatness(orig,varargin)
wolffd@0 2 % f = mirflatness(x) calculates the flatness of x, which can be either:
wolffd@0 3 % - a spectrum (spectral flatness),
wolffd@0 4 % - an envelope (temporal flatness), or
wolffd@0 5 % - any histogram.
wolffd@0 6
wolffd@0 7
wolffd@0 8 varargout = mirfunction(@mirflatness,orig,varargin,nargout,struct,@init,@main);
wolffd@0 9
wolffd@0 10
wolffd@0 11 function [x type] = init(x,option)
wolffd@0 12 if not(isamir(x,'mirenvelope') || isamir(x,'mirhisto'))
wolffd@0 13 x = mirspectrum(x);
wolffd@0 14 end
wolffd@0 15 type = 'mirscalar';
wolffd@0 16
wolffd@0 17
wolffd@0 18 function f = main(x,option,postoption)
wolffd@0 19 if iscell(x)
wolffd@0 20 x = x{1};
wolffd@0 21 end
wolffd@0 22 m = get(x,'Data');
wolffd@0 23 y = cell(1,length(m));
wolffd@0 24 for h = 1:length(m)
wolffd@0 25 if not(iscell(m{h})) % for histograms
wolffd@0 26 m{h} = {m{h}'};
wolffd@0 27 end
wolffd@0 28 y{h} = cell(1,length(m{h}));
wolffd@0 29 for i = 1:length(m{h})
wolffd@0 30 mm = m{h}{i};
wolffd@0 31 nl = size(mm,1);
wolffd@0 32 ari = mean(mm);
wolffd@0 33 geo = (prod(mm.^(1/nl)));
wolffd@0 34 divideByZero = warning('query','MATLAB:divideByZero');
wolffd@0 35 logZero = warning('query','MATLAB:log:logOfZero');
wolffd@0 36 warning('off','MATLAB:divideByZero');
wolffd@0 37 warning('off','MATLAB:log:logOfZero');
wolffd@0 38 y{h}{i} = ...10*log10(
wolffd@0 39 geo./ari;%);
wolffd@0 40 warning(divideByZero.state,'MATLAB:divideByZero');
wolffd@0 41 warning(logZero.state,'MATLAB:log:logOfZero');
wolffd@0 42 nany = find(isinf(y{h}{i}));
wolffd@0 43 y{h}{i}(nany) = zeros(size(nany));
wolffd@0 44 end
wolffd@0 45 end
wolffd@0 46 if isa(x,'mirenvelope')
wolffd@0 47 t = 'Temporal flatness';
wolffd@0 48 elseif isa(x,'mirspectrum')
wolffd@0 49 t = 'Spectral flatness';
wolffd@0 50 else
wolffd@0 51 t = ['Flatness of ',get(x,'Title')];
wolffd@0 52 end
wolffd@0 53 f = mirscalar(x,'Data',y,'Title',t,'Unit','');