annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirrms.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 = mirrms(x,varargin)
Daniel@0 2 % e = mirrms(x) calculates the root mean square energy.
Daniel@0 3 % Optional arguments:
Daniel@0 4 % mirrms(...,'Frame') computes the temporal evolution of the energy.
Daniel@0 5 % mirrms(...,'Root',0) does not apply the root operation to the mean
Daniel@0 6 % square energy.
Daniel@0 7
Daniel@0 8 normal.key = 'Normal';
Daniel@0 9 normal.type = 'Boolean';
Daniel@0 10 normal.default = 1;
Daniel@0 11 option.normal = normal;
Daniel@0 12
Daniel@0 13 root.key = 'Root';
Daniel@0 14 root.type = 'Boolean';
Daniel@0 15 root.default = 1;
Daniel@0 16 option.root = root;
Daniel@0 17
Daniel@0 18 specif.option = option;
Daniel@0 19
Daniel@0 20 specif.defaultframelength = 0.05;
Daniel@0 21 specif.defaultframehop = 0.5;
Daniel@0 22
Daniel@0 23 specif.eachchunk = @eachchunk;
Daniel@0 24 specif.combinechunk = @combinechunk;
Daniel@0 25 specif.afterchunk = @afterchunk;
Daniel@0 26
Daniel@0 27 varargout = mirfunction(@mirrms,x,varargin,nargout,specif,@init,@main);
Daniel@0 28
Daniel@0 29
Daniel@0 30 function [x type] = init(x,option)
Daniel@0 31 type = 'mirscalar';
Daniel@0 32
Daniel@0 33
Daniel@0 34 function e = main(x,option,postoption)
Daniel@0 35 if iscell(x)
Daniel@0 36 x = x{1};
Daniel@0 37 end
Daniel@0 38 d = get(x,'Data');
Daniel@0 39 v = mircompute(@algo,d,option);
Daniel@0 40 e = mirscalar(x,'Data',v,'Title','RMS energy');
Daniel@0 41
Daniel@0 42
Daniel@0 43 function e = algo(d,option)
Daniel@0 44 nl = size(d,1);
Daniel@0 45 nc = size(d,2);
Daniel@0 46 nch = size(d,3);
Daniel@0 47 e = zeros(1,nc,nch);
Daniel@0 48 for i = 1:nch
Daniel@0 49 for j = 1:nc
Daniel@0 50 if option.root
Daniel@0 51 e(1,j,i) = norm(d(:,j,i));
Daniel@0 52 else
Daniel@0 53 e(1,j,i) = d(:,j,i)'*d(:,j,i);
Daniel@0 54 end
Daniel@0 55 end
Daniel@0 56 end
Daniel@0 57 if option.normal
Daniel@0 58 e = e/sqrt(nl);
Daniel@0 59 end
Daniel@0 60
Daniel@0 61
Daniel@0 62 function [y orig] = eachchunk(orig,option,missing,postchunk)
Daniel@0 63 option.normal = 0;
Daniel@0 64 y = mirrms(orig,option);
Daniel@0 65
Daniel@0 66
Daniel@0 67 function y = combinechunk(old,new)
Daniel@0 68 do = get(old,'Data');
Daniel@0 69 do = do{1}{1};
Daniel@0 70 dn = get(new,'Data');
Daniel@0 71 dn = dn{1}{1};
Daniel@0 72 y = set(old,'ChunkData',sqrt(do^2+dn^2));
Daniel@0 73
Daniel@0 74
Daniel@0 75 function y = afterchunk(orig,length,postoption)
Daniel@0 76 d = get(orig,'Data');
Daniel@0 77 v = mircompute(@afternorm,d,length);
Daniel@0 78 y = set(orig,'Data',v);
Daniel@0 79
Daniel@0 80
Daniel@0 81 function e = afternorm(d,length)
Daniel@0 82 e = d/sqrt(length);