# Matlab- Generating a De Brujin Sequence

Page 1 of 1

## 0 Replies - 665 Views - Last Post: 13 August 2011 - 04:11 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=243387&amp;s=c202b7c62c1dba7396ab1e6a6e3b8e0c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 monty486

Reputation: 0
• Posts: 1
• Joined: 13-August 11

# Matlab- Generating a De Brujin Sequence

Posted 13 August 2011 - 04:11 AM

Hi there im having a problem in creating a De Brujin sequence in MATLAB. What the sequence is, it takes an input which is the order and returns an output of a sequence in a 1D array involving 0's and 1's. Two functions are required for the brujin sequence. One function is used to determine what the next number should be in the sequence, by checking if a specific pattern already appears in that sequence, and returns an output of true or false indicating weather it appears or not. The other function is the main brujin sequence and this will require the function described before to determine the number that should go into the sequence....Also i want to no a way to make the sequence cyclical, because there is a special case for the last element in the sequence, because the last element should be considered to be next to the first element. Ive been trying to get the brujin working just keep getting into errors, the pattern function seems to work, but the burjin does not.

Brujin Algorithm

set x(1),x(2)...x(n)=0
set i = n + 1

while i<= 2^n (n = order number of the sequence)

set z = the opposite of x(i-1) (ie if x(i-1) is a zero than z=1 and vice versa)

test if adding z to the end of the sequence produces a pattern length n at the end of the sequence that already appears somehwere in the sequence

if the pattern already appears then set z = x(i-1)

add z to the end of the sequence (i.e set x(i) = z

increment i

------------
http://pastebin.com/NJYFjFXF (Brujin)
http://pastebin.com/9Js1atxj (Pattern)

cheers

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }