====== Creating M-sequences ====== ===== What is an M-Sequence and Why is it Desirable ===== M-sequences are a special class of [[:public:de_bruijn|de Bruijn sequences.]] An m-sequence is a N element pseudonoise sequence of numbers belonging to **Z**/p**Z** with the following properties: - The length, N, is pk-1 for any k, integer. - With respect to any shift less than N, the autocorrelation of the sequence is equal to exactly zero except if p>2, then the second half of the sequence is the exact negative of the 1st half of the sequence. - The sequence is kth order counterbalanced. * Counterbalancing means that each label in the sequence appears k elements before or k elements after each other label in the sequence an identical number of times. Another phrasing of this is that every k-tuple of elements is present other than the k-tuple of all zeros. The draw of the autocorrelation property is the fact that if each label is a stimulus in an fMRI, the sequence will seem random to the observer. Also, the BOLD signal can be paired with the actual stimulus present rather than be effected by the correlation between the stimuli. The counterbalancing properties serve two purposes. First, if the researchers wish to examine the effect of contrast between two stimuli, the sequence must be 1st order counterbalanced so that the subject sees each contrast the same number of times. Second, counterbalancing controls for carry over effects. * Note: In m-sequences used for fMRI, the label 0 represents the blank stimulus. === Resulting Useful Properties of True M-Sequnces (1) === - For any q which is relatively prime to N, if you choose every qth element in the sequence until the length of the new sequence is N, the resulting sequence is also an m-sequence. When choosing, clearly one must imagine that the m-sequence has a period of N and therefore has a correlation of 1 with respect to the shift of N. - Another m-sequence can also be created by adding a shifted version of the original sequence to the orignal sequence, mod p. This is equivalent to simply shifting the sequence. ===== How to Create a Basic M-Sequence ===== == Black Box Method == There is a m-file which was created by Giedrius Buracas (2). This is available online at: \\ http://www.cnl.salk.edu/giedrius/professional/m-seqs/msequences.htm \\ or available here at \\ [[:public:m_sequences_code:mseq.m]] In order to create an m-sequence where p= 2, 3, or 5 and k is a reasonable size, the input for this function is mseq(p,k). This will output a m-sequence of the correct length and counterbalancing. == Real Method == M-sequences can be generated by primitive polynomials of the k splitting field of GF(p), more simply known as polynomials with coefficients in **Z**/p**Z**. I will call this field SP. A primitive polynomial is a polynomial such that its order is the order of SP, thus it can cyclically generate SP. Now imagine that the coefficients of this polynomial are stripped out to be the beginning k elements of a sequence. These coefficients are then added, mod p, by the original primitive polynomial, which we can now call a Shift Register Generator. This will create an ordering of all possible k-tuples of elements because the primitive polynomial's powers are all the elements SP. The coefficients to these polynomials are all the possible k-tuples. Below is a simple graphic (3) displaying this process:
Example: **Z**/9**Z** with first and second order counterbalancing - Starting with base m-sequence, p=3 and k=6, the sequence was multiplied by 3 and shifted by +2 to yield a sequence of [0 3 6]. - The sequence was then added to the original sequence so that a sequence of [0 1 2 3 4 5 6 7 8] was generated. This shift maintained first and second order counterbalancing. The sum of the absolute value of its autocorrelation is 3.78.Much thanks is given to Giedrius Buracas for guidance using this method. == Informative N-Tuples == * This method creates a messier m-sequence and is generally not recommended for use unless the additive method fails. In this method, a mapping from a real m-sequence to the desired m-sequence is made in this way:
0 0 3 0 1 6 0 6 3 2 4 6 3 3 4 7 7 3 0 2 6 0 4 3 1 5 6 8 1 5 8 8 1 7 8 6 0 7 3 2 2 6 5 4 4 0 5 4 1 0 4 7 1 3 1 8 6 6 7 5 5 2 0 2 5 0 3 2 1 6 5 6 4 1 4 4 8 5 3 6 0 8 3 2 6 6 4 5 4 5 0 5 2 1 2 5 7 3 1 2 6 7 4 5 2 5 2 3 2 3 6 3 8 4 8 6 3 7 4 8 2 3 8 3 8 6 8 7 5 7 2 1 1 5 7 8 1 0 8 7 2 7 1 4 1 8 4 6 6 3 5 4 7 0 3 1 1 6 7 6 5 0 4 2 1 4 5 8 5 1 6 2 6 3 4 4 7 5 3 2 0 6 5 2 4 2 3 4 3 7 5 8 2 1 8 5 6 6 1 5 3 8 0 8 8 2 7 8 4 0 6 4 2 4 4 3 5 5 7 0 1 1 0 7 7 2 0 1 5 0 8 2 2 8 5 4 6 0 3 3 1 7 6 6 0 5 3 1 0 6 7 2 5 1 3 2 8 6 4 7 4 3 2 5 6 3 1 4 6 8 3 5 6 7 1 5 1 8 2 6 8 4 5 6 5 1 4 2 8 4 4 6 5 3 4 0 7 4 2 2 4 5 3 5 0 7 2 2 1 5 5 8 0 1 8 0 6 8 2 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