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