A method for data storage includes accepting data for storage in a memory
(28) that includes multiple analog memory cells (32). The data is
converted to input values. The input values are filtered using a
non-linear filtering operation to produce respective shaped values, and
the shaped values are converted to output values using a linear spreading
transformation with coefficients chosen so that each of the shaped values
contributes to at least two of the output values. The non-linear
filtering operation is selected so as to reduce a size of an output range
in which the output values lie. The output values are stored in the
respective analog memory cells.