Home > NoiseTools > nt_wpwr.m

nt_wpwr

PURPOSE ^

[y,tweight]=nt_wpwr(x,w) - weighted power

SYNOPSIS ^

function [y,tw]=nt_wpwr(x,w)

DESCRIPTION ^

[y,tweight]=nt_wpwr(x,w) - weighted power

  y: weighted ssq of x
  tweight: total weight

  x: data
  w: weight

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y,tw]=nt_wpwr(x,w)
0002 %[y,tweight]=nt_wpwr(x,w) - weighted power
0003 %
0004 %  y: weighted ssq of x
0005 %  tweight: total weight
0006 %
0007 %  x: data
0008 %  w: weight
0009 %
0010 
0011 if nargin<2; w=[]; end
0012 
0013 if iscell(x);
0014     if ~isempty(w); error('not implemented'); end
0015     y=0; tw=0;
0016     for iTrial=1:numel(x)
0017         y=y+nt_wpwr(x{iTrial});
0018         tw=tw+size(x{iTrial},1);
0019     end
0020     return;
0021 end
0022 
0023 x=nt_unfold(x);
0024 w=nt_unfold(w);
0025 
0026 if isempty(w)
0027     y=sum(x(:).^2);
0028     tw=numel(x);
0029 else
0030     x=nt_vecmult(x,w);
0031     y=sum(x(:).^2);
0032     tw=sum(w(:));
0033 end
0034 
0035 if nargout==0; 
0036     disp(num2str(y));
0037     clear y tweight
0038 end

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