Home > NoiseTools > nt_bsrms.m

nt_bsrms

PURPOSE ^

[rms,sd,all]=nt_bsrms(x,N,w) - calculate rms, estimate sd using bootstrap

SYNOPSIS ^

function [rms,sd,all]=nt_bsrms(x,N,w)

DESCRIPTION ^

[rms,sd,all]=nt_bsrms(x,N,w) - calculate rms, estimate sd using bootstrap

  rms: rms over second dimension of x
  sd: standard deviation of rms calculated by bootstrap
  all: matrix of all trials
  
  x: matrix of observations (time X repetitions)
  N: number of bootstrap trials [default: 100]
  w: weight (time X repetitions)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [rms,sd,all]=nt_bsrms(x,N,w)
0002 %[rms,sd,all]=nt_bsrms(x,N,w) - calculate rms, estimate sd using bootstrap
0003 %
0004 %  rms: rms over second dimension of x
0005 %  sd: standard deviation of rms calculated by bootstrap
0006 %  all: matrix of all trials
0007 %
0008 %  x: matrix of observations (time X repetitions)
0009 %  N: number of bootstrap trials [default: 100]
0010 %  w: weight (time X repetitions)
0011 
0012 if nargin <2; N=100; end
0013 if nargin<3; w=[]; end
0014 
0015 if ndims(x)>2; 
0016     x=squeeze(x);
0017     if ndims(x)>2; 
0018         error('data must be at most 2D'); 
0019     end
0020 end
0021 if numel(N)>1; error('!'); end; 
0022 
0023 if isempty(w)
0024     [m,n]=size(x);
0025     all=zeros(m,N);
0026     for k=1:N
0027         idx=ceil(n*rand(1,n));
0028         all(:,k)=sqrt(mean(x(:,idx).^2,2));
0029     end
0030     rms=sqrt(mean(x.^2,2));
0031     sd=sqrt(mean((all-repmat(rms,1,N)).^2,2));
0032 else
0033     if size(w,2)==1; w=repmat(w,1,size(x,2)); end
0034     if size(w)~=size(x); error('!'); end
0035     [m,n]=size(x);
0036     all=zeros(m,N);
0037     for k=1:N
0038         idx=ceil(n*rand(1,n));
0039         all(:,k)=sqrt(nt_wmean(x(:,idx).^2,w(:,idx),2));
0040     end
0041     rms=sqrt(nt_wmean(x.^2,w,2));
0042     sd=sqrt(nt_wmean((all-repmat(rms,1,N)).^2,w,2));
0043 end
0044 
0045

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005