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:

- nt_unfold y=nt_fold(x) - unfold 3D to 2D
- nt_vecmult y=nt_vecmult(x,v) - multiply all rows or columns of matrix by vector

This function is called by:

- nt_dss_repeat_cluster y=nt_dss_repeat_cluster(x,nkeep,cluster_size) - dss within clusters
- nt_inpaint function y=nt_inpaint(x,w) - weighted interpolation based on correlation structure
- nt_outliers [w,y]=nt_outliers(x,w,thresh,niter) - detect outliers based on weighted correlation structure
- nt_sns_cluster y=nt_sns_cluster(x,nneigbors,cluster_size) - sensor noise suppression within clusters
- nt_star [y,w,ww]=nt_star(x,thresh,closest,depth) - sensor noise suppression
- nt_star2 [y,w,ww]=nt_star2(x,thresh,closest,w) - sensor noise suppression
- nt_zapline [y,yy]=nt_zapline(x,fline,nremove,p,plotflag) - remove power line artifact

## 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