function y = DMencode(x, a, delt)
%函数DMencode为德尔塔编码程序,x为要编码的矩阵,a为预测系数,delt为一个正常数。
%当a默认时,a=1;delt默认时,delt=6.5。
error(nargchk(1, 3, nargin))
if nargin < 3
delt = 6.5
if nargin < 2
a = 1;
end
end
x = double(x);
[m, n] = size(x);
p = zeros(m, n); %存放预测值
e = zeros(m, n); %量化前误差
qe = zeros(m, n); %量化后误差
ff = zeros(m, n);
ff(:, 1) = x(:, 1);
qe(:, 1) = x(:, 1);
for i = 1: m
for j = 2: n
p(i, j) = a.* ff(i, j-1);
e(i, j) = x(i, j) - p(i, j);
if e(i, j) > 0
qe(i, j) = delt;
else
qe(i, j) = -delt;
end
ff(i, j) = p(i, j) + qe(i, j);
end
end
y = qe;
function x = DMdecode(y, a)
%函数DMdecode为解码程序,y为要解码的预测误差矩阵,a为预测系数,当a默认时,a = 1。
error(nargchk(1, 2, nargin));
if nargin < 2
a = 1;
end
[m, n] = size(y);
x = zeros(m, n + 1);
for j = 1: n
jj = j + 1;
x(:, jj) = y(:, j) + a.* x(:, (jj-1));
end
x = x(:, 1+1:end);