dec2bin_gmsk.m

来自「完成GMSK信号调制」· M 代码 · 共 43 行

M
43
字号
%==========================================================================
%版权所有(C)2008,迟帅
%
%函数名称:dec2bin_viterbi
%作者名:  迟帅
%版本号:  1.0
%完成日期:2008/10/13
%
%函数调用形式:
%          output = dec2bin_viterbi(src, format_len)
%入口参数说明:
%          名称                  含义
%          src                   十进制数
%          format_len            输出的二进制序列的长度
%                                (0表示输入十进制数对应二进制数的有效长度)
%函数完成功能:
%          实现十进制数到二进制序列的转换
%==========================================================================
function output = dec2bin_gmsk(src, format_len)

%------------------------------初始化-------------------------------------%
temp = src;%提取输入的十进制数
index = 1;%设定index的初始值
temp_output = [0];%配合src为零的情况

%--------------------利用除法求余方式得到除以2的余数----------------------%
while (temp >= 1)
    temp_output(index) = mod(temp,2);
    temp = floor(temp / 2);
    index = index + 1;
end;

%--------------------余数序列反序得到对应的二进制比特---------------------%
temp_output = fliplr(temp_output);

%-----------------------转化成指定长度的二进制序列------------------------%
if format_len == 0
    output = temp_output;
else
    output = zeros(1, format_len);
    valid_len = size(temp_output, 2);
    output((format_len - valid_len + 1):format_len) = temp_output;
end;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?