Code covered by the BSD License  

Highlights from
Toolbox Wavelets

image thumbnail
from Toolbox Wavelets by Gabriel Peyre
Wavelet transform and coding functions, including other more exotic transforms (laplacian, steerable

keep_biggest(x,n)
function [y,t] = keep_biggest(x,n)

% keep_biggest - keep only the n biggest coef, 
%   set the rest to zero.
%
% y = keep_biggest(x,n);
%
%   Copyright (c) 2004 Gabriel Peyr

if iscell(x)
    % concat cells array
    xx = [];
    for i=1:length(x)
        xx = [xx;x{i}(:)];
    end
    [yy,t] = keep_biggest(xx,n);
    % recreate cells
    for i=1:length(x)
        y{i} = yy( 1:prod( size(x{i}) ) );
        y{i} = reshape(y{i}, size(x{i}));
        yy( 1:prod( size(x{i}) ) ) = [];
    end
    return;
end

n = round(n);
y = x;
[tmp,I] = sort(abs(y(:)));
t = tmp(I(end-n));
y( I(1:end-n) ) = 0;

Contact us at files@mathworks.com