function x = wthresh(x,in2,t)
%MATLAB Code Generation Library Function

%   Copyright 1995-2023 The MathWorks, Inc.
%#codegen

sorh = char(in2);
coder.internal.prefer_const(sorh);
sorh = validatestring(in2,{'s','h'},'wthresh','sorh');
SOFT = (sorh == 's');
validateattributes(x,{'double','single'},{'finite'},'wthresh','x')
validateattributes(t,{'double','single'},{'nonnegative','real'},'wthresh','t');
validT = any(isscalar(t) | (size(t) == size(x)));
coder.internal.errorIf(~validT,'Wavelet:FunctionInput:invalidT');
if SOFT
    if isscalar(t)
        for k = 1:numel(x)
            x(k) = wthreshSoft(x(k),t(1));
        end
    else
        for k = 1:numel(x)
            x(k) = wthreshSoft(x(k),t(k));
        end
    end
else
    if isscalar(t)
        for k = 1:numel(x)
            x(k) = wthreshHard(x(k),t(1));
        end
    else
        for k = 1:numel(x)
            x(k) = wthreshHard(x(k),t(k));
        end
    end
end

%--------------------------------------------------------------------------
function x = wthreshSoft(x,t)
coder.inline('always');
tmp = abs(x) - t;
tmp = (tmp + abs(tmp))/2;
x = sign(x)*tmp;
%--------------------------------------------------------------------------
function x = wthreshHard(x,t)
coder.inline('always');
x = x*(abs(x) > t);
%--------------------------------------------------------------------------
