matlab输入随机时CRC的输入
Input of CRC when the input is random in matlab
我在 MATLAB 中有这个 CRC 代码,msg
是数据,poly
是生成函数。
msg=[1 0 1 1 0 0 1 0 1 ];
poly=[1 0 1 1];
[M, N]=size(poly);
mseg=[msg zeros(1,N-1)];
[q, r]=deconv(mseg,poly);
r=abs(r);
for i=1:length(r)
a=r(i);
if ( mod(a,2)== 0 )
r(i)=0;
else
r(i)=1;
end end
crc=r(length(msg)+1:end) frame = bitor(mseg,r)
效果很好,但我想随机 msg
大小为 7。
我用过这个但是它有错误。
msg = randi([0, 1], 7,1);
错误是:
Error using horzcat Dimensions of matrices being concatenated are not
consistent.
请帮我解决这个问题。
你试过了吗:msg = randi([0, 1], 1, 7);
?
注意 7, 1
到 1, 7
的切换。请看看这是否解决了您的问题。
我在 MATLAB 中有这个 CRC 代码,msg
是数据,poly
是生成函数。
msg=[1 0 1 1 0 0 1 0 1 ];
poly=[1 0 1 1];
[M, N]=size(poly);
mseg=[msg zeros(1,N-1)];
[q, r]=deconv(mseg,poly);
r=abs(r);
for i=1:length(r)
a=r(i);
if ( mod(a,2)== 0 )
r(i)=0;
else
r(i)=1;
end end
crc=r(length(msg)+1:end) frame = bitor(mseg,r)
效果很好,但我想随机 msg
大小为 7。
我用过这个但是它有错误。
msg = randi([0, 1], 7,1);
错误是:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
请帮我解决这个问题。
你试过了吗:msg = randi([0, 1], 1, 7);
?
注意 7, 1
到 1, 7
的切换。请看看这是否解决了您的问题。