% script for testing the frame transformation using stochastic parameters
% script: testframtrans
%
% This simple script tests the switching between frames using the Gram matrix. 
%
% date: 27/06/2006 
%
% Author:  XXL .. Peter Balazs, contact: a8927259@unet.univie.ac.at
%
% Literature : [Xxl] P. Balazs; Frames, Finite Dimensionality and
%               Algorithms; in preparation (2006)
%
% See also: RandFrame.m
%

dim = ceil(rand()*10)+1;
% random dimension, mimimal 2
M1 = dim + ceil(rand()*20);
% random number of frame elements
M2 = dim + ceil(rand()*20);
% random number of frame elements

disp(sprintf('Dimension = %g, Number of frame elements, first frame = %g, second frame = %g',dim,M1,M2));
disp('First frame:');
D1 = RandFrame(dim,M1);
    % first frame in [Xxl]
disp('Second frame:');
D2 = RandFrame(dim,M2);
    % second frame
    
G12 = CrossGram(pinv(D1)',D2);
    % cross-Gram matrix

%test with random signal
N_test = 100;
mmm = 0;
for ii = 1:N_test
    f = rand(dim,1); % random signal
    coeff1 = D1'*f; % coefficents with first frame
    coeff2 = D2'*f; % coefficients with second frame
    frametrans = G12 * coeff1; % frame transformation
    error = norm(coeff2-frametrans); % norm of error
    if error > mmm
        mmm = error;
    end
end
disp(sprintf('The maximal error of the frame transformation in %g runs was %g',N_test,mmm));