📄 pcm_encode.m
字号:
function [out]=pcm_encode(UniS)
SLENGTH = length(UniS)
PCMout=zeros(1,SLENGTH);
bytesOut=zeros(3,SLENGTH);
for i = 1:SLENGTH,
Byte=zeros(1,3);
% Determine the Sign ('+' => 0; '-' => 1)!
if UniS(i) >= 0,
Byte(1) = 0;
else
Byte(1) = 1;
end
% Determine the Segment Code
for j = 1:8,
if abs(UniS(i)) >= (1/2)^j,
Byte(2) = 8-j;
break;
end
end
% Determine the Inner Segment Code
if Byte(2) == 0, % This is for the points in segment 0 % in case!
preByte = (1/2)^7;
preByte1 = 0;
else
preByte = (1/2)^(8-Byte(2));
preByte1 = preByte;
end
for j = 1:16,
if (abs(UniS(i))-preByte1) >= preByte*(16-j)/16
Byte(3) = 16-j;
break;
end
end
clear preByte;
clear preByte1;
% Convert Byte's value to bit and
% put Byte's value into PCMout array
PCMout(i) = Byte(1)*2^7 + Byte(2)*2^4 + Byte(3);
% debug
bytesOut(1,i)=Byte(1);
bytesOut(2,i)=Byte(2);
bytesOut(3,i)=Byte(3);
end
% Generate the Digintal Signal
%[Digital Preparer]%
bitsOut = [];
for i=1:SLENGTH,
aBit = bitget(PCMout(i),8:-1:1);
bitsOut = [bitsOut aBit];
end
out = bitsOut;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -