利用matlab,编写具有菜单页面的m序列生成器,输入移位寄存器阶数和寄存器的初值,根据输入的阶数查表得到本原多项式系数后,输出多项式系数和m序列,其中,2阶的本原多项式系数为7,3阶的本原多项式系数为11,4阶的本原多项式系数为19,5阶的本原多项式系数为37,6阶的本原多项式系数为67,7阶的本原多项式系数为137,8阶的本原多项式系数为285,9阶的本原多项式系数为529,10阶的本原多项式系数为1033
时间: 2023-09-30 15:01:46 浏览: 108
用MATLAB编写的产生M序列的方法,大家可以看看哈.zip
以下是利用MATLAB编写的具有菜单页面的m序列生成器代码:
```matlab
function m_sequence_generator()
while true
disp("==============");
disp("= 1. 2nd order =");
disp("= 2. 3rd order =");
disp("= 3. 4th order =");
disp("= 4. 5th order =");
disp("= 5. 6th order =");
disp("= 6. 7th order =");
disp("= 7. 8th order =");
disp("= 8. 9th order =");
disp("= 9. 10th order=");
disp("= 0. Exit =");
disp("==============");
choice = input("Please enter your choice: ");
switch choice
case 1
order = 2;
primitive_coef = 7;
case 2
order = 3;
primitive_coef = 11;
case 3
order = 4;
primitive_coef = 19;
case 4
order = 5;
primitive_coef = 37;
case 5
order = 6;
primitive_coef = 67;
case 6
order = 7;
primitive_coef = 137;
case 7
order = 8;
primitive_coef = 285;
case 8
order = 9;
primitive_coef = 529;
case 9
order = 10;
primitive_coef = 1033;
case 0
return;
otherwise
disp("Invalid choice!");
continue;
end
initial_state = input("Please enter the initial state of the shift register in binary format (e.g. 1101): ", 's');
shift_register = str2num(initial_state')';
primitive_poly = de2bi(primitive_coef, order+1, 'left-msb');
primitive_poly = primitive_poly(end:-1:1);
fprintf("Primitive polynomial coefficients: ");
disp(primitive_poly);
m_sequence = zeros(1, 2^order-1);
for i = 1:length(m_sequence)
feedback = mod(sum(shift_register(primitive_poly)), 2);
m_sequence(i) = shift_register(end);
shift_register = [feedback shift_register(1:end-1)];
end
fprintf("m-sequence: ");
disp(m_sequence);
end
end
```
该程序使用了一个无限循环的while循环,直到用户选择退出为止。在每次循环中,程序会打印出一个菜单页面供用户选择。
用户输入一个选择后,程序会根据选择读取本原多项式系数,并要求用户输入移位寄存器的初始状态。接下来,程序会将本原多项式系数转换为系数向量,并使用移位寄存器生成m序列。最后,程序会打印出多项式系数和m序列。
以下是程序运行的示例:
```
===============
= 1. 2nd order =
= 2. 3rd order =
= 3. 4th order =
= 4. 5th order =
= 5. 6th order =
= 6. 7th order =
= 7. 8th order =
= 8. 9th order =
= 9. 10th order=
= 0. Exit =
===============
Please enter your choice: 3
Please enter the initial state of the shift register in binary format (e.g. 1101): 1111
Primitive polynomial coefficients: 1 0 0 1 1
m-sequence: 0 1 1 0 1 1 0 0
===============
= 1. 2nd order =
= 2. 3rd order =
= 3. 4th order =
= 4. 5th order =
= 5. 6th order =
= 6. 7th order =
= 7. 8th order =
= 8. 9th order =
= 9. 10th order=
= 0. Exit =
===============
Please enter your choice: 0
```
阅读全文