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