Daniel@0: function varargout = mirrms(x,varargin) Daniel@0: % e = mirrms(x) calculates the root mean square energy. Daniel@0: % Optional arguments: Daniel@0: % mirrms(...,'Frame') computes the temporal evolution of the energy. Daniel@0: % mirrms(...,'Root',0) does not apply the root operation to the mean Daniel@0: % square energy. Daniel@0: Daniel@0: normal.key = 'Normal'; Daniel@0: normal.type = 'Boolean'; Daniel@0: normal.default = 1; Daniel@0: option.normal = normal; Daniel@0: Daniel@0: root.key = 'Root'; Daniel@0: root.type = 'Boolean'; Daniel@0: root.default = 1; Daniel@0: option.root = root; Daniel@0: Daniel@0: specif.option = option; Daniel@0: Daniel@0: specif.defaultframelength = 0.05; Daniel@0: specif.defaultframehop = 0.5; Daniel@0: Daniel@0: specif.eachchunk = @eachchunk; Daniel@0: specif.combinechunk = @combinechunk; Daniel@0: specif.afterchunk = @afterchunk; Daniel@0: Daniel@0: varargout = mirfunction(@mirrms,x,varargin,nargout,specif,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: type = 'mirscalar'; Daniel@0: Daniel@0: Daniel@0: function e = main(x,option,postoption) Daniel@0: if iscell(x) Daniel@0: x = x{1}; Daniel@0: end Daniel@0: d = get(x,'Data'); Daniel@0: v = mircompute(@algo,d,option); Daniel@0: e = mirscalar(x,'Data',v,'Title','RMS energy'); Daniel@0: Daniel@0: Daniel@0: function e = algo(d,option) Daniel@0: nl = size(d,1); Daniel@0: nc = size(d,2); Daniel@0: nch = size(d,3); Daniel@0: e = zeros(1,nc,nch); Daniel@0: for i = 1:nch Daniel@0: for j = 1:nc Daniel@0: if option.root Daniel@0: e(1,j,i) = norm(d(:,j,i)); Daniel@0: else Daniel@0: e(1,j,i) = d(:,j,i)'*d(:,j,i); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: if option.normal Daniel@0: e = e/sqrt(nl); Daniel@0: end Daniel@0: Daniel@0: Daniel@0: function [y orig] = eachchunk(orig,option,missing,postchunk) Daniel@0: option.normal = 0; Daniel@0: y = mirrms(orig,option); Daniel@0: Daniel@0: Daniel@0: function y = combinechunk(old,new) Daniel@0: do = get(old,'Data'); Daniel@0: do = do{1}{1}; Daniel@0: dn = get(new,'Data'); Daniel@0: dn = dn{1}{1}; Daniel@0: y = set(old,'ChunkData',sqrt(do^2+dn^2)); Daniel@0: Daniel@0: Daniel@0: function y = afterchunk(orig,length,postoption) Daniel@0: d = get(orig,'Data'); Daniel@0: v = mircompute(@afternorm,d,length); Daniel@0: y = set(orig,'Data',v); Daniel@0: Daniel@0: Daniel@0: function e = afternorm(d,length) Daniel@0: e = d/sqrt(length);