資源描述:
《matlab實(shí)現(xiàn)量化過程(均勻量化)》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、Matlab實(shí)現(xiàn)量化過程(均勻量化)對信號進(jìn)行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;%中間值%畫原函數(shù)圖subplot(3,1,1);plot(n,y);gridon;title('y(n)');axis([0,2
2、000,-3.5,3.5]);%畫round()函數(shù)量化圖y_round=y;fori=1:2000forj=1:2^bitsif(y(i)>=m(j)&&y(i)=m(j)&&y(i)3、d;end;end;subplot(3,1,3);plot(n,y_floor);gridon;title('floor(n)');axis([0,2000,-3.5,3.5]);%計(jì)算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;en
4、d;%結(jié)束2-8比特循環(huán)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');運(yùn)行結(jié)果:SNR_round_db=-Inf12.576018.40322
5、4.345130.708536.723742.631748.4947SNR_floor_db=-Inf6.525412.570418.576524.652430.683936.681342.6456上一條線為round函數(shù)產(chǎn)生的量化信噪比,下一條線為floor函數(shù)產(chǎn)生的量化信噪比。