📄 rsdecof.m
字号:
function rsdecof(file_in, file_out, err_cor);
%RSDECOF Reed-solomon decode for an ASCII file.
% RSDECOF(FILE_IN, FILE_OUT) decodes an ASCII file FILE_IN using
% code-word length 127, message length 117 Reed-Solomon code. The
% error-correction capability of this code is 5 (for every 127
% character). The decoded message is written to FILE_OUT. Both
% FILE_IN and FILE_OUT are string variables. FILE_IN should be
% the output processed by RSENCOF.
%
% RSDECOF(FILE_IN, FILE_OUT, ERR_COR) decodes an ASCII file FILE_IN
% using code-word length 127, error-correction capability as ERR_COR
% Reed-Solomon code. The message length is 127 - 2*ERR_COR.
%
% See also RSENCOF.
% Wes Wang 10/11/95.
% Copyright (c) 1995-96 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1996/04/01 18:02:52 $
if nargin < 3
err_cor = 5;
end;
% file read in.
h = fopen(file_in, 'r');
if h < 0
error(['File ', file_in, ' does not exist.']);
end;
x = fread(h, 'char');
fclose(h);
%decode
[x, err] = vec2mat(x, 127);
if err > 0
disp('Warning: The number of the characters are different from the output of the encode.');
disp(' This may cause error in the decode.');
end;
N = 127;
K = 127 - 2 * err_cor;
msg = decode(x, N, K, 'rs/decimal')';
[m_msg, n_msg] = size(msg);
tmp = find(msg(m_msg, :)==setstr(4));
msg = msg(:)';
if ~isempty(tmp)
msg = msg(1 : (m_msg - 1) * n_msg + tmp(1) - 1);
end;
h = fopen(file_out, 'w');
fwrite(h, msg, 'char');
% end of rsdecof.m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -