function [xf, nround] = softthreshold(x, epsilon) % Soft threshold for a one or two dimensional signal % [xf, nround] = softthreshold(x, epsilon) % % x is filtered according to the equation % xf(k) = sign( x(k) ) * ( |x(k)| - epsilon ) % Input parameters: % x Signal % epsilon Treshold value % Output parameters: % xf The tresholded signal % nround Number of elements in xf that are zero. nround = 0; [N,M] = size(x); % Thresholding for n=1:N for m=1:M if abs(x(n,m)) < epsilon xf(n,m) = 0; nround = nround + 1; else xf(n,m) = sign( x(n,m) ) * ( abs(x(n,m)) - epsilon ); end end end