📄 thresh.m
字号:
function [xo,N]=thresh(ttype,xi,lambda);%THRESH Threshold (hard/soft)% Usage: x=thresh(ttype,x,lambda);% [x,N]=thresh(ttype,x,lambda);%% THRESH('hard',x,lambda) or THRESH(1,x,lambda) will perform% hard thresholding on x, i.e. all element with absolute value% less than lambda will be set to zero.%% THRESH('soft',x,lambda) or THRESH(2,x,lambda) will perform% soft thresholding on x, i.e. lambda will be subtracted from% the absolute value of every element of x.%% [x,N]=THRESH(ttype,x,lambda) additionally returns a number N specifying% how many numbers where kept.%% The function WTHRESH in the Matlab Wavelet toolbox implements the same% functionality.%if nargin~=3; error('Wrong number of input arguments.');end;if (prod(size(lambda))~=1 || ~isnumeric(lambda)) error('lambda must be a scalar.');end;if ischar(ttype) ttype=lower(ttype);end;switch ttype case {'hard',1} xo=xi.*(abs(xi)>=lambda); case {'soft',2} xa=abs(x)-lambda; % In the following line, the +0 is significant: It turns % -0 into +0, oh! the joy of numerics. xo=((xa>0)*xa+0).*sign(xi); otherwise error('Unknown thresholding type.');end;if nargout==2 work=(abs(xi)>=lambda); N=sum(work(:));end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -