Matlab实现量化过程(均匀量化)(共3页).doc
精选优质文档-倾情为你奉上Matlab实现量化过程(均匀量化)对信号进行2到8bit量化,并对两种量化方式的量化噪声作对比 clc;clear n=1:2000; y=sin(2*pi*n/100)+0.5*cos(2*pi*n/200)+2*sin(2*pi*n/300); for bits=2:8 figure(bits-1); v=0:2bits; m=-2.6+(2.6+2.6)/2bits*v; %量化 v1=1:2bits; p_round=m(v1)+(m(v1+1)-m(v1)/2; %中间值 %画原函数图 subplot(3,1,1); plot(n,y); grid on;title('y(n)'); axis(0,2000,-3.5,3.5); %画round()函数量化图 y_round=y; for i=1:2000 for j=1:2bits if(y(i)>=m(j)&&y(i)<m(j+1) y_round(i)=p_round(j); end; end; end;subplot(3,1,2); plot(n,y_round); title('round(n)'); grid on; axis(0,2000,-3.5,3.5); %画floor()函数量化图 y_floor=y; for i=1:2000 for j=1:2bits if(y(i)>=m(j)&&y(i)<m(j+1) y_floor(i)=m(j);end;end; end; subplot(3,1,3); plot(n,y_floor); grid on; title('floor(n)'); axis(0,2000,-3.5,3.5); %计算SNR Y_power=sum(y.2)/2000; round_power=sum(y-y_round).2)/2000; SNR_round(1)=0; SNR_round(bits)=Y_power/round_power; floor_power=sum(y-y_floor).2)/2000; SNR_floor(1)=0; SNR_floor(bits)=Y_power/floor_power; end; %结束2-8比特循环 SNR_round_db=10*log10(SNR_round) SNR_floor_db=10*log10(SNR_floor) %画SNR图 figure(8); axis_x=1:8; plot(axis_x,SNR_round_db); title('量化信噪比'); hold on; plot(axis_x,SNR_floor_db,'r'); grid on; axis(2,8,0,50); xlabel('bit'); ylabel('SNR/dB'); legend('round','floor');运行结果:SNR_round_db = -Inf 12.5760 18.4032 24.3451 30.7085 36.7237 42.6317 48.4947SNR_floor_db = -Inf 6.5254 12.5704 18.5765 24.6524 30.6839 36.6813 42.6456 上一条线为round函数产生的量化信噪比,下一条线为floor函数产生的量化信噪比。专心-专注-专业