function T = blkToeplitz(y,r,kk)
% T = blkToeplitz(y,r,k)
%  Return a block Toeplitz matrix filled with the data y containing k block-rows
%     
%  INPUT       DESCRIPTION                                     DIMENSION
%  =====       ===========                                     ==========
%   y          a sequence of vectors, e.g., time sequences     m x N
%   r          number of columns in each block of y 
%   k          number of block rows of T
%
%  OUTPUT      DESCRIPTION                                     DIMENSION
%  ======      ===========                                     ==========
%   T          block Toeplitz matrix of the output             m*k x r*(N+1-k)

  [m,N] = size(y);
  if (N < m), y = y'; [m,N] = size(y); end % time sequences are the _rows_ of y
  N = N/r;

% Check dimensions
  if (kk < 0),       error('blkToeplitz: k should be positive');  end
  jj = N+1-kk;       % number of block columns in T 
  if (m*kk > r*jj),  error('blkToeplitz: # rows > # cols, decrease k');  end

% fill the block-Toeplitz matrix
  T = zeros(m*kk,r*jj);
  for ii=1:kk
    T(m*(ii-1)+1:m*ii,:) = y(:,r*(kk-ii)+1:r*(kk-ii+jj));
  end

% ----------------------------------------------------------------- blkToeplitz
