if (predsample > 32767) predsample = 32767;
elseif (predsample < -32768) predsample = -32768; end
index = index + IndexTable(code+1);
if (index < 1) index = 1; end
if (index > 89) index = 89; end
prevsample = predsample; previndex = index;
raw_y(n) = predsample / 32767; n = n + 1; end
输入一个模拟信号的编码解码过程: t=0:pi/50:2*pi; y=cos(t);
adpcm_y=adpcm_encoder(y); Y=adpcm_decoder(adpcm_y); Z=Y-y;
subplot(2,2,1) plot(t,y)
title('输入模拟信号y'); subplot(2,2,2)
stem(adpcm_y) title('ADPCM编码'); subplot(2,2,3) plot(t,Y)
title('ADPCM解码'); subplot(2,2,4) plot(Z) title('误差');
该程序运行后得到结果入下图:
输入的模拟信号y112100.58064-0.52-1012345670020406080100120ADPCM编码ADPCM解码10.40.20.50-0.20-0.4-0.5-0.6-0.8-101234567-102040误差6080100120
四、结果分析
从上面的运行结果来看,ADPCM编码的效率较高,解码后误差小。而且编码位数都为4位二进制,提供跟高的压缩比,减小了带宽利用,提高了频率利用率,因此在频带紧缺的现代通信中具有广泛的应用前景.