largestn.m

来自「linear time-frequency toolbox」· M 代码 · 共 49 行

M
49
字号
function [xo]=largestn(xi,N)%LARGESTN   Keep N largest coefficients.%   Usage:  xo=largestn(x,N);%%   LARGESTN(x,N) returns an array of the same size as x keeping%   the N largest coefficients.%%   If the coefficients represents a signal expanded in an orthonormal%   basis, then this will be the best N-term approximation.%%   SEE ALSO:  LARGESTR%%   REFERENCES:%     S. Mallat. A wavelet tour of signal processing. Academic Press, San Diego,%     CA, 1998.if nargin~=2  error('Wrong number of input arguments.');end;if (prod(size(N))~=1 || ~isnumeric(N))  error('N must be a scalar.');end;% Determine the size of the array.ss=prod(size(xi));% Handle the trivial cases.if N>=ss  xo=xi;  return;end;if N<=0  xo=zeros(size(xi));  return;end;% Sort the absolute values of the coefficients.sxi=sort(abs(xi(:)));% Find the coeffiecient sitting at position N through the array,% and use this as a threshing value. threshval=sxi(ss-N+1);% Do the threshing.xo=xi.*(abs(xi)>=threshval);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?