function t = thresholdValue(WT,numEl) % we wish to keep only the numEl largest wavelet coefficients. % to do so, we unfold the wavelet transform WT to concatenate % the details, sort the result by descending order, and get the value % of the element at the computed position. This value is the output % threshold scale = size(WT.Details,1); det = []; for i = 1:scale det = [det WT.Details{i}.s]; end det = abs(det); det = sort(det,'descend'); if size(det,2) < numEl t = det(end); else t = det(numEl) end