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