1function [w1]=NCAF(K,w,order,n,mcAdapt)
 2
 3 if ~isempty(K)  
 4        % Finding norm without Matlab's function lets us avoid for
 5        Omega = sum(w.^2);  % Find norm of all columns
 6        OmegaMat = ones(order,1) * Omega;  % Expand to a norm matrix
 7        inds = OmegaMat > K;  % save comparison so it doesnt repeat
 8        if ~isempty(mcAdapt) % apply AMC SNR threshold if specified
 9            amcIndMat = ones(order,1) * mcAdapt(n,:);
10            inds = OmegaMat > K & amcIndMat;
11        end
12  w(inds) = w(inds) .* sqrt(K./OmegaMat(inds));
13 end
14w1=w;
15end