脉冲编码调制(PCM )实验 一、实验目的:
学会利用 MATLAB 软件对脉冲编码的仿真。通过实验提高学生实际动手能力和编程能力,为日后从事通信工作奠定良好的基础。
二、 实验内容:
(1)根据抽样值+1270,利用 MATLAB 软件编写其 PCM 程序,进一步加强对PCM 编码原理的理解。
(2)根据抽样值-93,利用 MATLAB 软件编写其 PCM 程序。
三、程序和实验结果:
(1 1 )
+1270
程序
clear all
close all
x=+1270;
% 极性码 C1 的判定
if x>0
out(1)=1;
else
out(1)=0;
end
%段落码 C2、C3、C4 的判定,st 为段落数,step 为
if abs(x)>=0 & abs(x)<16
out(2)=0;out(3)=0;out(4)=0;step=1;st=0;
elseif 16<abs(x) & abs(x)<32
out(2)=0;out(3)=0;out(4)=1;step=1;st=16;
elseif 32<abs(x) & abs(x)<64
out(2)=0;out(3)=1;out(4)=0;step=2;st=32;
elseif 64<abs(x) & abs(x)<128
out(2)=0;out(3)=1;out(4)=1;step=4;st=64;
elseif 128<abs(x) & abs(x)<256
out(2)=1;out(3)=0;out(4)=0;step=8;st=128;
elseif 256<abs(x) & abs(x)<512
out(2)=1;out(3)=0;out(4)=1;step=16;st=256;
elseif 512<abs(x) & abs(x)<1024
out(2)=1;out(3)=1;out(4)=0;step=32;st=512;
else
out(2)=1;out(3)=1;out(4)=1;step=64;st=1024;
end
% 段内码的判定
if(abs(x)>=2048)
out(2:8)=[1 1 1 1 1 1 1]
else
tmp=floor((abs(x)-st)/step);
%floor 取整函数,不大于该数的最大整数
t=dec2bin(tmp,4)-48;
%dec2bin 把 tmp 转化成 4 位二进制数,由于 dec2bin 转换得到的是 string 类型,
%因此用 double 强制转换后得到的是 ASCII 值,数字 0 的 ascii 值为 48,再减去 48 就可以了
out(5:8)=t(1:4);
end
out=reshape(out,1,8)
%将数组 out 改写成一个 1x8 的数组
(2 2 )
+1270
实验结果
out =
1
1
1
1
0
0
1
1
(3 3 )- - 93 程序
clear all
close all
x=-93;
% 极性码 C1 的判定
if x>0
out(1)=1;
else
out(1)=0;
end
%段落码 C2、C3、C4 的判定,st 为段落数,step 为
if abs(x)>=0 & abs(x)<16
out(2)=0;out(3)=0;out(4)=0;step=1;st=0;
elseif 16<abs(x) & abs(x)<32
out(2)=0;out(3)=0;out(4)=1;step=1;st=16;
elseif 32<abs(x) & abs(x)<64
out(2)=0;out(3)=1;out(4)=0;step=2;st=32;
elseif 64<abs(x) & abs(x)<128
out(2)=0;out(3)=1;out(4)=1;step=4;st=64;
elseif 128<abs(x) & abs(x)<256
out(2)=1;out(3)=0;out(4)=0;step=8;st=128;
elseif 256<abs(x) & abs(x)<512
out(2)=1;out(3)=0;out(4)=1;step=16;st=256;
elseif 512<abs(x) & abs(x)<1024
out(2)=1;out(3)=1;out(4)=0;step=32;st=512;
else
out(2)=1;out(3)=1;out(4)=1;step=64;st=1024;
end
% 段内码的判定
if(abs(x)>=2048)
out(2:8)=[1 1 1 1 1 1 1]
else
tmp=floor((abs(x)-st)/step);
%floor 取整函数,不大于该数的最大整数
t=dec2bin(tmp,4)-48;
%dec2bin 把 tmp 转化成 4 位二进制数,由于 dec2bin 转换得到的是 string 类型,
%因此用 double 强制转换后得到的是 ASCII 值,数字 0 的 ascii 值为 48,再减去 48 就可以了
out(5:8)=t(1:4);
end
out=reshape(out,1,8)
%将数组 out 改写成一个 1x8 的数组
(4 4 )- - 93 实验结果
out =
0
0
1
1
0
1
1
1 四、 实验结果及分析:
(1 1 )0 +1270 实验结果分析
(2 2 )- -7 97 实验结果分析
推荐访问: 原理 通信 报告版权所有:精诚范文网 2010-2024 未经授权禁止复制或建立镜像[精诚范文网]所有资源完全免费共享
Powered by 精诚范文网 © All Rights Reserved.。 蜀ICP备20022334号