[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
PCM编码仿真比较简单,我这里给出了实验代码和结果图
一、实验原理
二、实验代码
clear; clc; T=0.0005; t=-0.01:T:0.01; fs=2000; sdt=1/fs; t1=-0.01:sdt:0.01;
xt=cos(2*pi*30*t)+sin(2*pi*120*t); st=cos(2*pi*30*t1)+sin(2*pi*120*t1); max =
max(abs(st)); % 原始信号 figure; subplot(2,1,1);plot(t,xt);title('原始信号');grid on;
subplot(2,1,2);stem(t1,st,'.');title('抽样信号');grid on; pcm_encode =
PCMcoding(st); figure; stairs(pcm_encode);%绘制信号的阶梯图 axis([0 20 -0.1 1.1]);
title('PCM 编码'); grid on; function code=PCMcoding(S) z=sign(S); %判断S的正负
MaxS=max(abs(S)); %求S的最大值 S=abs(S/MaxS); %归一化 Q=2048*S; %量化
code=zeros(length(S),8); %PCM编码存储矩阵 %% % 段落码判断程序 for i=1:length(S) if
(Q(i)>128)&&(Q(i)<=2048) code(i,2)=1; %在第五段与第八段之间,段位码第一位都为"1" end if
(Q(i)>32)&&(Q(i)<=128)||(Q(i)>512)&&(Q(i)<=2048) code(i,3)=1;
%在第三四七八段内,段位码第二位为"1" end if
(Q(i)>16)&&(Q(i)<=32)||(Q(i)>64)&&(Q(i)<=128)||(Q(i)>256)&&(Q(i)<=512)||(Q(i)>1024)&&(Q(i)<=2048)
code(i,4)=1; %在二四六八段内,段位码第三位为"1" end end %% % 段内码判断程序 N=zeros(length(S)); for
i=1:length(S) N(i)=bin2dec(num2str(code(i,2:4)))+1;
%找到code位于第几段,bin2dec将二进制整数的文本表示转换为双精度值, end a=[0,16,32,64,128,256,512,1024];
%13折线各段起始对应的量化单位数 b=[1,1,2,4,8,16,32,64]; %除以16,得到每段的最小量化间隔 for i=1:length(S)
q=ceil((Q(i)-a(N(i)))/b(N(i))); %求出在段内的位置,ceil将 X 的每个元素四舍五入到大于或等于该元素的最接近整数 if
q==0 code(i,(5:8))=[0,0,0,0]; %如果输入为零则输出"0" else k=dec2bin(q-1,4);
%将字符数组或字符串转换为数值数组,编码段内码为二进制,dec2bin将十进制整数转换为其二进制表示字符向量 code(i,5)=str2num(k(1));
code(i,6)=str2num(k(2)); code(i,7)=str2num(k(3)); code(i,8)=str2num(k(4)); end
%符号位的判断 if z(i)>0 code(i,1)=1; elseif z(i)<0 code(i,1)=0; end end code =
reshape(code', 1, []); end
三、实验结果