Home > NoiseTools > nt_wpwr.m

nt_wpwr

PURPOSE ^

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

SYNOPSIS ^

function [y,tweight]=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,tweight]=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 x=nt_unfold(x);
0014 w=nt_unfold(w);
0015 
0016 if isempty(w)
0017     y=sum(x(:).^2);
0018     tweight=numel(x);
0019 else
0020     x=nt_vecmult(x,w);
0021     y=sum(x(:).^2);
0022     tweight=sum(w(:));
0023 end
0024 
0025 if nargout==0; 
0026     disp(num2str(y));
0027     clear y tweight
0028 end

Generated on Mon 14-May-2018 09:45:18 by m2html © 2005