gusucode.com > 基于matlab的adpcm语音编码源码程序 > 基于matlab的adpcm语音编码源码程序/2bitadpcm/decoder.m
% APDCM decoder y = zeros(1,len); ss2 = zeros(1,len); ss2(1) = startval; for n = 2:len % decode the encoded sample % calculate the quantized difference from code(n) neg = code(n) >= sign_bit; if (neg) temp = code(n) - sign_bit; else temp = code(n); end temp2 = (temp+.5)*ss2(n-1); if (neg) temp2 = -temp2; end y(n) = y(n-1) + temp2; if (y(n) > 127) y(n) = 127; elseif (y(n) < -127) y(n) = -127; end % compute the new step size temp = temp + 1; currentIndex = currentIndex + index(temp); if (currentIndex < 1) currentIndex = 1; elseif (currentIndex > numSteps) currentIndex = numSteps; end ss2(n) = table2(currentIndex); end y = y/128; SNR = 10*log10( sum(x.^2)/sum((x-y').^2) )