function [xf, nround] = hardthreshold(x, epsilon) % Hard threshold for a one or two dimensional signal % [xf, nround] = hardthreshold(x, epsilon) % % x is filtered according to the equation % xf(k) = 0 if |x(k)| < epsilon % xf(k) = x(k) otherwise % 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) = x(n,m); end end end