function seq = gen_fib_seq(n_gen)
% gen_fib_seq - generate Fibonacci sequence
%   Usage: seq = gen_fib_seq(n_gen)
% Input:
%   n_gen - number of the iterations
% Output:
%   seq - row of 1's and (-1)'s arranged in Fibonacci sequence
%
% Algorithm: the iteration rule is S(n+2)=[S(n)S(n+1)], S(-1)=B=-1;S(0)=A=1.
% Older function gen_fib_seq_old.m used different definition of the generation number.
% Here, definition is consistent with that in Fib_Number.m (a standard
% one), i.e. as
%       index: 0 1 2 3 4 5 6 7 ...
%       F_ind: 0 1 1 2 3 5 8 13 ...

A=1;
B=-1;

if n_gen==1,
    C=B;
elseif n_gen==2,
    C=A;
else
    for ii=1:n_gen-2,
        C=[B A];
        B=A;
        A=C;
    end
end


seq=C;

