% Creates the irregular Gabor frame n the lattice xpo
% gabbaspirr.M,   created: 20.04.2005  XXL 
%                 last change: 21.09.2007
% 
% This program creates the irregular Gabor system using the window win at 
% the points which are non-zero in xpo. This algorithm uses row vectors
% and matrix multiplication from the right to be compatible to gabbasp.m.
%
% Matrix-multiplication is supposed to be FROM THE RIGHT!!! For left side
% multiplication use GBI.'!
%
% Inputs :  win ... window, length n; row vector
%           xpo ... frequency time matrix, with K non-zero entries, 
%                   rows: frequency
%
% Output :  GBI ... n x n matrix, the synthesis matrix of the system
%
% usage :   GBI = gabbaspirr(win,xpo); 
%  
% see also: gabbasp.m
% 
% Author: XXL ..  a8927259@unet.univie.ac.at 
%              or  xxl@kfs.oeaw.ac.at
%
% Notes: xpo was chosen to have the frequency values in the rows fitting
% the standard picture of a spectogram. So xpo(i,j) is the i-th frequency
% bin and j-the time frame. To fit to NuHAG-conventions, rotmod is used!!
% To get a matrix for left-multiplication use GBI.'
% We use first translation, then modulation: g_k = M_x_k  T_y_k  g%
%
% Lit.: [XXL] Peter Balazs, "Irregular and regular Gabor multiplier with
%             application to psychoacoustic masking"
% 
% 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
function     GBI = gabbaspirr(win,xpo);

if nargin < 2;  error('two inputs needed.');  end;  
n = length(win);
[nn n] = size(win);
if nn ~= 1
    if n ~= 1
        error('the window has to be a vector!');
    end
    win = win.';
    n = nn;
end;
if size(xpo) ~= [n,n];
    error('The Lattice does not fit the size of the window.');
end;
[xpx xpy] = find(xpo > 0);
k = size(xpx,1);
if k == 0 
  error('The matrix xpo is containing only zeros');
end

GBI = zeros(k,n);
for ii = 1:k
%     xpx(ii)
%     xpy(ii)
    gg = rotmod(win,xpy(ii)-1,xpx(ii)-1);
%    plot(gg)
    GBI(ii,:)=gg;
%    pause
end

% F=ifft(eye(n))*n;
% tso = -1;
% for ii = 1:k
%       tsn = xpy(ii) % time-shift-new
%       if tsn ~= tso
%           g = rot(win,tsn-1)
%           tso = tsn
%       end;
%       for jj = 1:k
%          GBI(jj,:)=F(xpx(jj),:).*g;
%      end
% end
