function ms=mseq(baseVal,powerVal,shift,whichSeq)
% Maximum length sequence assuming 2,3,5 distinct values
%
% [ms]=MSEQ(baseVal,powerVal[,shift,whichSeq])
%
% OUTPUT:
% ms = generated maximum length sequence, of length
basisVal^powerVal-1
%
% INPUT:
% baseVal -nuber of sequence levels (2,3, or 5 allowed)
% powerVal -power, so that sequence length is
baseVal^powerVal-1
% shift -cyclical shift of the sequence
% whichSeq -sequence istantiation to use
% (numer of sequences varies with powreVal - see the
code)
%
% Example: ms=mseq(2,3,1,2) generates a binary sequence of length
2^3-1
% shifted cyclically by 1 step and using the second set
of weights
% (c) Giedrius T. Buracas, SNL-B, Salk Institute
% Register values are taken from: WDT Davies, System Identification
% for self-adaptive control. Wiley-Interscience, 1970
% When using mseq code for design of FMRI experiments, please, cite:
% G.T.Buracas & G.M.Boynton (2002) Efficient Design of Event-Related
fMRI
% Experiments Using M-sequences. NeuroImage, 16, 801-813.
if nargin<4, whichSeq=1; end
if nargin<3, shift=1; end;
bitNum=baseVal^powerVal-1;
register=ones(powerVal,1);
if baseVal==2,
switch powerVal,
case 2, tap(1).No=[1,2];
case 3, tap(1).No=[1,3];
tap(2).No=[2,3];
case 4, tap(1).No=[1,4];
tap(2).No=[3,4];
case 5, tap(1).No=[2,5];
tap(2).No=[3,5];
tap(3).No=[1,2,3,5];
tap(4).No=[2,3,4,5];
tap(5).No=[1,2,4,5];
tap(6).No=[1,3,4,5];
case 6, tap(1).No=[1,6];
tap(2).No=[5,6];
tap(3).No=[1,2,5,6];
tap(4).No=[1,4,5,6];
tap(5).No=[1,3,4,6];
tap(6).No=[2,3,5,6];