matlab生成m序列的函数

原来那个效率太低,主要是因为实际应用并不需要生成太长的m序列,加入了需求长度,能有效减少运行时间。25级的移位寄存器,运行了一个小时都没有出来一周期,我仅仅需要三千bit而已。改进版:

function [seq]=mseq(connections,registers,len);
%***************************************************
% 此函数用来生成最大长度线性移位寄存器序列
% connections为特征多项式向量,registers为初始值向量
% len为所需序列长度,若为0则输出一个周期
%***************************************************
m=length(connections);
L=2^m-1; %周期长度

if len==0
	len=L;
end

fan=0;

for i=1:len
	seq(i)=registers(m);

	for j=1:m
		fan=fan +connections(j)*registers(j);
		fan=(mod(fan,2));
	end

	for t=m:-1:2 %寄存器移位
		registers(t)=registers(t-1);
	end

	registers(1)=fan;
	fan=0;
end

附:部分本原多项式

#
# Minimal weight primitive polynomials over GF(2)
# In addition the coefficients/bits (apart from the
# constant and the leading term) are as close to
# the low end as possible.
#.
# Generated by Joerg Arndt, 2003-January-30
#

2,1,0
3,1,0
4,1,0
5,2,0
6,1,0
7,1,0
8,4,3,2,0
9,4,0
10,3,0
11,2,0
12,6,4,1,0
13,4,3,1,0
14,5,3,1,0
15,1,0
16,5,3,2,0
17,3,0
18,7,0
19,5,2,1,0
20,3,0
21,2,0
22,1,0
23,5,0
24,4,3,1,0
25,3,0
26,6,2,1,0
27,5,2,1,0
28,3,0
29,2,0
30,6,4,1,0
31,3,0
32,7,6,2,0
33,13,0
34,8,4,3,0
35,2,0
36,11,0
37,6,4,1,0
38,6,5,1,0
39,4,0
40,5,4,3,0
41,3,0
42,7,4,3,0
43,6,4,3,0
44,6,5,2,0
45,4,3,1,0
46,8,7,6,0
47,5,0
48,9,7,4,0
49,9,0
50,4,3,2,0
51,6,3,1,0
52,3,0
53,6,2,1,0
54,8,6,3,0
55,24,0
56,7,4,2,0
57,7,0
58,19,0
59,7,4,2,0
60,1,0
61,5,2,1,0
62,6,5,3,0
63,1,0
64,4,3,1,0
65,18,0
66,9,8,6,0
67,5,2,1,0
68,9,0
69,6,5,2,0
70,5,3,1,0
71,6,0
72,10,9,3,0
73,25,0
74,7,4,3,0
75,6,3,1,0
76,5,4,2,0
77,6,5,2,0
78,7,2,1,0
79,9,0
80,9,4,2,0
81,4,0
82,9,6,4,0
83,7,4,2,0
84,13,0
85,8,2,1,0
86,6,5,2,0
87,13,0
88,11,9,8,0
89,38,0
90,5,3,2,0
91,8,5,1,0
92,6,5,2,0
93,2,0
94,21,0
95,11,0
96,10,9,6,0
97,6,0
98,11,0
99,7,5,4,0
100,37,0
101,7,6,1,0
102,6,5,3,0
103,9,0
104,11,10,1,0
105,16,0
106,15,0
107,9,7,4,0
108,31,0
109,5,4,2,0
110,6,4,1,0
111,10,0
112,11,6,4,0
113,9,0
114,11,2,1,0
115,8,7,5,0
116,6,5,2,0
117,5,2,1,0
118,33,0
119,8,0
120,9,6,2,0
121,18,0
122,6,2,1,0
123,2,0
124,37,0
125,7,6,5,0
126,7,4,2,0
127,1,0
128,7,2,1,0
129,5,0
130,3,0
131,8,3,2,0
132,29,0
133,9,8,2,0
134,57,0
135,11,0
136,8,3,2,0
137,21,0
138,8,7,1,0
139,8,5,3,0
140,29,0
141,13,6,1,0
142,21,0
143,5,3,2,0
144,7,4,2,0
145,52,0
146,5,3,2,0
147,11,4,2,0
148,27,0
149,10,9,7,0
150,53,0
151,3,0
152,6,3,2,0
153,1,0
154,9,5,1,0
155,7,5,4,0
156,9,5,3,0
157,6,5,2,0
158,8,6,5,0
159,31,0
160,5,3,2,0
161,18,0
162,8,7,4,0
163,7,6,3,0
164,12,6,5,0
165,9,8,3,0
166,10,3,2,0
167,6,0
168,16,9,6,0
169,34,0
170,23,0
171,6,5,2,0
172,7,0
173,8,5,2,0
174,13,0
175,6,0
176,12,11,9,0
177,8,0
178,87,0
179,4,2,1,0
180,12,10,7,0
181,7,6,1,0
182,8,6,1,0
183,56,0
184,9,8,7,0
185,24,0
186,9,8,6,0
187,7,6,5,0
188,6,5,2,0
189,6,5,2,0
190,13,6,2,0
191,9,0
192,15,11,5,0
193,15,0
194,87,0
195,8,3,2,0
196,11,9,2,0
197,9,4,2,0
198,65,0
199,34,0
200,5,3,2,0
201,14,0
202,55,0
203,8,7,1,0
204,10,4,3,0
205,9,5,2,0
206,10,9,5,0
207,43,0
208,9,3,1,0
209,6,0
210,12,4,3,0
211,11,10,8,0
212,105,0
213,6,5,2,0
214,5,3,1,0
215,23,0
216,7,3,1,0
217,45,0
218,11,0
219,8,4,1,0
220,12,10,9,0
221,8,6,2,0
222,8,5,2,0
223,33,0
224,12,7,2,0
225,32,0
226,10,7,3,0
227,10,9,4,0
228,12,11,2,0
229,10,4,1,0
230,8,7,6,0
231,26,0
232,11,9,4,0
233,74,0
234,31,0
235,9,6,1,0
236,5,0
237,7,4,1,0
238,5,2,1,0
239,36,0
240,8,5,3,0
241,70,0
242,11,6,1,0
243,8,5,1,0
244,9,4,1,0
245,6,4,1,0
246,11,2,1,0
247,82,0
248,15,14,10,0
249,86,0
250,103,0
251,7,4,2,0
252,67,0
253,7,3,2,0
254,7,2,1,0
255,52,0
256,10,5,2,0
257,12,0
258,83,0
259,10,6,2,0
260,10,8,7,0
261,7,6,4,0
262,9,8,4,0
263,93,0
264,10,9,1,0
265,42,0
266,47,0
267,8,6,3,0
268,25,0
269,7,6,1,0
270,53,0
271,58,0
272,9,6,2,0
273,23,0
274,67,0
275,11,10,9,0
276,6,3,1,0
277,12,6,3,0
278,5,0
279,5,0
280,9,5,2,0
281,93,0
282,35,0
283,12,7,5,0
284,119,0
285,10,7,5,0
286,69,0
287,71,0
288,11,10,1,0
289,21,0
290,5,3,2,0
291,12,11,5,0
292,97,0
293,11,6,1,0
294,61,0
295,48,0
296,11,9,4,0
297,5,0
298,11,8,4,0
299,11,6,4,0
300,7,0
301,9,5,2,0
302,41,0
303,13,12,6,0
304,11,2,1,0
305,102,0
306,7,3,1,0
307,8,4,2,0
308,15,9,2,0
309,10,6,4,0
310,8,5,1,0
311,7,5,3,0
312,11,10,5,0
313,79,0
314,15,0
315,10,9,1,0
316,135,0
317,7,4,2,0
318,8,6,5,0
319,36,0
320,4,3,1,0
321,31,0
322,67,0
323,10,3,1,0
324,6,4,3,0
325,10,5,2,0
326,10,3,1,0
327,34,0
328,9,7,5,0
329,50,0
330,8,7,2,0
331,10,6,2,0
332,123,0
333,2,0
334,7,4,1,0
335,10,7,2,0
336,7,4,1,0
337,55,0
338,6,3,2,0
339,16,10,7,0
340,11,4,3,0
341,14,11,5,0
342,125,0
343,75,0
344,11,10,6,0
345,22,0
346,11,7,2,0
347,11,10,3,0
348,8,7,4,0
349,6,5,2,0
350,53,0
351,34,0
352,13,11,6,0
353,69,0
354,14,13,5,0
355,6,5,1,0
356,10,9,7,0
357,11,10,2,0
358,14,8,7,0
359,68,0
360,26,25,1,0
361,7,4,1,0
362,63,0
363,8,5,3,0
364,67,0
365,9,6,5,0
366,29,0
367,21,0
368,17,9,7,0
369,91,0
370,139,0
371,8,3,2,0
372,15,7,3,0
373,8,7,2,0
374,8,6,5,0
375,16,0
376,8,7,5,0
377,41,0
378,43,0
379,10,8,5,0
380,47,0
381,5,2,1,0
382,81,0
383,90,0
384,16,15,6,0
385,6,0
386,83,0
387,9,8,2,0
388,14,3,1,0
389,10,9,5,0
390,89,0
391,28,0
392,13,10,6,0
393,7,0
394,135,0
395,11,6,5,0
396,25,0
397,12,7,6,0
398,14,6,5,0
399,86,0
400,5,3,2,0

以上。
很久没来的老狼

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注