您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > Matlab实现量化过程(均匀量化)
Matlab实现量化过程(均匀量化)对信号进行2到8bit量化,并对两种量化方式的量化噪声作对比clc;clearn=1:2000;y=sin(2*pi*n/100)+0.5*cos(2*pi*n/200)+2*sin(2*pi*n/300);forbits=2:8figure(bits-1);v=0:2^bits;m=-2.6+(2.6+2.6)/2^bits*v;%量化v1=1:2^bits;p_round=m(v1)+(m(v1+1)-m(v1))/2;%中间值%画原函数图subplot(3,1,1);plot(n,y);gridon;title('y(n)');axis([0,2000,-3.5,3.5]);%画round()函数量化图y_round=y;fori=1:2000forj=1:2^bitsif(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)');gridon;axis([0,2000,-3.5,3.5]);%画floor()函数量化图y_floor=y;fori=1:2000forj=1:2^bitsif(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);gridon;title('floor(n)');axis([0,2000,-3.5,3.5]);%计算SNRY_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('量化信噪比');holdon;plot(axis_x,SNR_floor_db,'r');gridon;axis([2,8,0,50]);xlabel('bit');ylabel('SNR/dB');legend('round','floor');运行结果:SNR_round_db=-Inf12.576018.403224.345130.708536.723742.631748.4947SNR_floor_db=-Inf6.525412.570418.576524.652430.683936.681342.6456上一条线为round函数产生的量化信噪比,下一条线为floor函数产生的量化信噪比。
本文标题:Matlab实现量化过程(均匀量化)
链接地址:https://www.777doc.com/doc-6153522 .html