《matlab--PCM编码.docx》由会员分享,可在线阅读,更多相关《matlab--PCM编码.docx(4页珍藏版)》请在课桌文档上搜索。
1、PCM编码:clearall:closeall;先建立原信号dt=O.OO2;%取时间间隔为0.01t=0:dt:10;%时域间隔dt为间隔从。到IQ画图fc=l%xt里最大频率xt=sin(2*pi*fc*t)+cos(2*pi*fc*t);%Xt方程%采样:时间连续信号变为时间离散模拟信号fs=10;%抽样fs=2fc,每秒钟内的抽样点数目将等于或大于2fcs=Ocode(i,l)=l;%便正值elsecode(i.l)=0;%代表负值end%段内码a2a3a4ifabs(i)=0abs(i)16COde(i,2)=0;COde(i,3)=0;COdC(i,4)=0;SteP=Iart=0
2、;elseif16=abs(A(i)&abs(A(i)32code(i,2)=0;COde(i,3=0;COde(i,4)=l;SteP=1;Start=16;elseif32=abs(A(i)&abs(A(i)64COde(i,2)=0;Code(i,3)=l;COde(i.4)=0;SteP=2;start=32;elseif64=ahs(A(i)&abs(A(i)12Code(i,2)=0;Code(i,3)=l;Code(i,4)=l:SteP=4:Start=64:elseif128=abs(A(i)&al,s(A(i)256Code(i,2)=l:Code(i,3)=0:COde(
3、i,4)=0:SteP=8:Start=I28;elseif256=abs(.(i)abs(.(i)=0;code(i,4)=1;step=16;start=256;elseif512=abs(.-(i)&abs(?(i)=0;SteP=32;start=512;elseif1024=abs(A(i)&abs(A(i)start)step);%段内码储码floor取整4she5rut=dec2bin(B,4)-48;%dec2bin定义将B变为血2进制码,-48变更格式code(i,5:8)=t(l:4);%输出段内码endcoc(code1,8*n);%rcshapi代表从新星形codeSU
4、bPlot(313):stcm(coIe,.)axis(16001);title。编码侑号*gridona,r=0code(i,1)=1;elsecode(i,1)=0;endifabs(A(i)=0&abs(A(i)16code(i,2)=0;code(i,3)=0;code(i,4)=O;step=l;Start=0;elseif16=abs(A(i)&abs(A(i)32code(i,2)=O;code(i,3)=0;code(i,4)=l;step=l;start=16;elsei32=abs(A(i)&abs(A(i)64code(i,2)=0;code(i,3)=l;code(i,
5、4)=0;step=2;start=32;elseif64=abs(A(i)&abs(A(i)128code(i,2)=0;code(i,3)=l;code(i,4)=l;step=4;start=64;elseif128=abs(A(i)&abs(A(i)256code(i,2)=l;code(i,3)=0;code(i,4)=0;step=8;start=128;elseif256=abs(A(i)&abs(A(i)512code(i,2)=1;code(i,3)=0;code(i,4)=l;step=16;start=256;elseif512=abs(A(i)&abs(A(i)1024code(i,2)=1;code(i,3)=1;code(i,4)=0;step=32;Start=512;elseif1024=abs(A(i)&abs(A(i)2048code(i,2)=1;code(i,3)=1;code(i,4)=l;step=64;start=1024;endB=floor(abs(A(i)-start)/step);t=dec2bin(B,4)-48;code(i,5:8)=t(l:4);endcode=reshape(code,1,8*n);codesubplot(212);stem(code,.,);axis(110001);title(4);gridon