annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirlowenergy.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 = mirlowenergy(x,varargin)
wolffd@0 2 % p = mirlowenergy(f) computes the percentage of frames showing a RMS
wolffd@0 3 % energy that is lower than a given threshold.
wolffd@0 4 % For instance, for a musical excerpt with some very loud frames and
wolffd@0 5 % lots of silent frames, we would get a high low-energy rate.
wolffd@0 6 % Optional argument:
wolffd@0 7 % mirlowenergy(...,'Threshold',t) expressed as a ratio to the average
wolffd@0 8 % energy over the frames.
wolffd@0 9 % Default value: t = 1
wolffd@0 10 % mirlowenergy(...,'Frame',l,h) specifies the use of frames of
wolffd@0 11 % length l seconds and a hop rate h.
wolffd@0 12 % Default values: l = .05 s, h = .5
wolffd@0 13 % mirlowenergy(...,'Root',0) uses mean square instead of root mean
wolffd@0 14 % square
wolffd@0 15 % mirlowenergy(...,'ASR') computes the Average Silence Ratio, which
wolffd@0 16 % corresponds in fact to mirlowenergy(...,'Root',0,'Threshold',t)
wolffd@0 17 % where t is fixed here by default to t = .5
wolffd@0 18 % [p,e] = mirlowenergy(...) also returns the RMS energy curve.
wolffd@0 19
wolffd@0 20 asr.key = 'ASR';
wolffd@0 21 asr.type = 'Boolean';
wolffd@0 22 asr.default = 0;
wolffd@0 23 option.asr = asr;
wolffd@0 24
wolffd@0 25 root.key = 'Root';
wolffd@0 26 root.type = 'Boolean';
wolffd@0 27 root.default = 1;
wolffd@0 28 option.root = root;
wolffd@0 29
wolffd@0 30 thr.key = 'Threshold';
wolffd@0 31 thr.type = 'Integer';
wolffd@0 32 thr.default = NaN;
wolffd@0 33 option.thr = thr;
wolffd@0 34
wolffd@0 35 frame.key = 'Frame';
wolffd@0 36 frame.type = 'Integer';
wolffd@0 37 frame.number = 2;
wolffd@0 38 frame.default = [.05 .5];
wolffd@0 39 option.frame = frame;
wolffd@0 40
wolffd@0 41 specif.option = option;
wolffd@0 42
wolffd@0 43 specif.combinechunk = {'Average',@nothing};
wolffd@0 44 specif.extensive = 1;
wolffd@0 45
wolffd@0 46 varargout = mirfunction(@mirlowenergy,x,varargin,nargout,specif,@init,@main);
wolffd@0 47
wolffd@0 48
wolffd@0 49 function [x type] = init(x,option)
wolffd@0 50 if option.asr
wolffd@0 51 option.root = 0;
wolffd@0 52 end
wolffd@0 53 if isamir(x,'miraudio')
wolffd@0 54 if isframed(x)
wolffd@0 55 x = mirrms(x,'Root',option.root);
wolffd@0 56 else
wolffd@0 57 x = mirrms(x,'Frame',option.frame.length.val,option.frame.length.unit,...
wolffd@0 58 option.frame.hop.val,option.frame.hop.unit,...
wolffd@0 59 'Root',option.root);
wolffd@0 60 end
wolffd@0 61 end
wolffd@0 62 type = 'mirscalar';
wolffd@0 63
wolffd@0 64
wolffd@0 65 function e = main(r,option,postoption)
wolffd@0 66 if iscell(r)
wolffd@0 67 r = r{1};
wolffd@0 68 end
wolffd@0 69 if isnan(option.thr)
wolffd@0 70 if option.asr
wolffd@0 71 option.thr = .5;
wolffd@0 72 else
wolffd@0 73 option.thr = 1;
wolffd@0 74 end
wolffd@0 75 end
wolffd@0 76 v = mircompute(@algo,get(r,'Data'),option.thr);
wolffd@0 77 fp = mircompute(@noframe,get(r,'FramePos'));
wolffd@0 78 e = mirscalar(r,'Data',v,'Title','Low energy','Unit','/1','FramePos',fp);
wolffd@0 79 e = {e,r};
wolffd@0 80
wolffd@0 81
wolffd@0 82 function v = algo(d,thr)
wolffd@0 83 v = sum(d < repmat(thr*mean(d,2),[1 size(d,2) 1]));
wolffd@0 84 v = v / size(d,2);
wolffd@0 85
wolffd@0 86
wolffd@0 87 function fp = noframe(fp)
wolffd@0 88 fp = [fp(1);fp(end)];
wolffd@0 89
wolffd@0 90
wolffd@0 91 function y = nothing(old,new)
wolffd@0 92 y = old;