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

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