% Create the block matrix our of the full Gabor-type matrix
% Wal2BloXXL.M   Gabor Frame Like Matrix 
% by XXL, 22.06.2004
% 
% This program creates the data block from a matrix  
% expecting it to be a Walnut matrix, Gabor-like , meaning 
% it is expected to have a-periodic side-diagonals and only 
% every M=L/b the sidediagonal is not zero. Depending on the parameter 
% method a b x a or a x b matrix is created.
%
% inputs : A ...... n x n Matrix with the non trivial data
%          a ...... first parameter (block-circulant, 
%                   periodic side diagonals; in Gabor case time)
%          b ...... second parameter (diagonal blocks, 
%                   non-zero side diagonals; in Gabor case frequency)
%          method . 0 - b x a block matrix (Default)
%                   1 - a x b block matrix
%
%  output: the block matrix with the "essential" data. 
%
%  usage:  B = Wal2Blo(A,n)
%
%  notes : method == 0 corresponds to the algorithm first used and 
%          implemented by Qiu and Feichtinger, where the block matrix is
%          the condensed left b x n submatrix of the frame operator
%          method == 1 uses the a x b matrix, which is derived from the
%          upper submatrix a x n submatrix
%
% Author:   XXL .. Peter Balazs, contact: a8927259@unet.univie.ac.at
%
% Literature : [Qiu] S. Qiu, H.G. Feichtinger, Gabor-Type Matrices And 
%                    Discrete Huge Gabor Transforms 
%              [Xxl] P. Balazs, Gabor frame multipliers with application to
%                    psychoacoustical masking 
%                    (Ph.D. thesis, in preparation) 
%
%  see also: blockxxl.m, blo2walxxl.m, blocknon.m 
%
% Copyright :  (c) NUHAG, Faculty of Math., University of Vienna, AUSTRIA
%              http://nuhag.mat.uunivie.ac.at/
%              (c) Acoustics Research Institute, Austrian Academy of
%              Science
%              http://www.kfs.oeaw.ac.at
%
%              Permission is granted to modify and re-distribute this
%              code in any manner as long as this notice is preserved.
%              All standard disclaimers apply.

% news (12/01/2005) both kind of block matrices possible.


function U = Wal2Bloxxl(A,a,b,method);

if nargin < 3;
    disp('At least three inputs (A,a,b) are needed');
end;
if nargin < 4 | method ~= 1
    method = 0;
end

[n m] = size(A);
if n ~= m;
    disp('The matrix should be quadratic');
    return;
end;

T = n/a;
F = n/b;

mult = lcm(a,b);

if rem(n, mult) ~=0; 
    disp(sprintf(...
    'The number of rows (a= %i) and columns (b= %i) of A have %s%i)',...
    '  to be divisors of the size of the Matrix (n=',a,b,n));
    return;
end;

if method == 0
    U = diag2row(A,F)
    U = U(:,1:a)
else
    U = diag2col(A,F)
    U = U(1:a,:)
end

