% Build the matrix for a Frame Multiplier
% function FM = FramMultMat(s,D,Ds)
%
% A matrix is buildt, which represents the frame multiplier with the 
% symbol s, the analysis frame D and the synthese frame Ds.
%  
% inputs : s .......... the symbol (K x 1) 
%          D .......... the elements of the analysis frame (columnwise) 
%                       (n x K)
%          Ds ......... the elements of the synthesis frame (columnwise) 
%                       (m x K) (default: Ds = D)
%
% output: FM ......... the matrix of the frame multiplier using the frames
%                      in D and Ds
%
% usage:  FM = FramMultMat(s,D,Ds)
%
% test:   s = [2 1];
%         D = [0 1/sqrt(2) -1/sqrt(2); 1 -1/sqrt(2) -1/sqrt(2)]
%         FM = FramMultMat(s,D);
%
% date: 28/02/2007
%
% notes : D and Ds are just the synthesis operators of the respective frames. 
%        To be able to define frame multipliers they have to have the same  
%        number of elements. 
%
% Author:  XXL .. Peter Balazs, contact: Peter.Balazs@oeaw.ac.at
%
% Literature : [Xxl] P. Balazs; Irregular And Regular Gabor frame multipliers 
%                    with application to psychoacoustical masking 
%                    (Ph.D. thesis, in preparation 2005) 
%
% See also: GMappir,low2uppIr, ApprFramMult,testapprfarmmult.m, 
%           testapprGabmultKap1.m
%
% Copyright : (c) Acoustics Research Institute, Austrian Academy of
%              Science
%              http://www.kfs.oeaw.ac.at

function FM = FramMultMat(s,D,Ds)

if nargin < 2
    error('At leatst two inputs are needed; s and D');
end;

[K M] = size(s);
[Nd Kd] = size(D);

if K~=1 && M ~=1
    error('The input s has to be a vector.');
else
    MM = diag(s);
    if K==1
        K = M;
    end
end

if K ~= Kd
    error('The number of columns in D and elements in s have to be the same.');
end;

if nargin < 3
    Ds = D;
else
    [Ns Ks] = size(Ds);
    if Kd ~= Ks
        error('The frames must have the same number of elements.');
    end;
end;

FM = Ds*(MM*D');
