function [coefs, aprox] = smult(st, T, func, Tf, txt_waitbar)
% Synopsis:
%  [coefs, aprox] = smult(st, T, func, Tf, txt_waitbar)
%
% Description:
%  This function compute scalar product of input signal and input function 
%  
% Input:
%  st [column vector] - input signal s(t) 
%  T - duration time of input signal
%  func [column vector] - second function (phi alebo psi)
%  Tf - duration time of second function
%  txt_waitbar - text which will be showed in waitbar, Default is 'Please wait...'
%
% Output:
%  coefs [column vector] - values of scalar product computed with step 1 second
%  aprox [column vector] - aproximation of input signal by second function
%
% See also: 
%  TODO
%
% About: 
%  Author: Jozef Knotek  
% 
% Changed : 2.12.2006

%% Checking right inputs
tmp = size(st);
if tmp(1) < tmp(2)
    st = st';
end
tmp = size(st);
if tmp(2) > 1
    error('First parameter must be column vector.')
    return
end

tmp = size(T);
if tmp(1) > 1 | tmp(2) > 1
    error('Second parameter must be value.')
    return
end

tmp = size(func);
if tmp(1) < tmp(2)
    func = func';
end
tmp = size(func);
if tmp(2) > 1
    error('Third parameter must be column vector.')
    return
end

tmp = size(Tf);
if tmp(1) > 1 | tmp(2) > 1
    error('Forth parameter must be value.')
    return
end

if T < Tf
    error('Second parameter must be greater than forth paramater.')
end

[N tmp] = size(st);
[Nf tmp] = size(func);
if N/T ~= Nf/Tf
    error('Functions must have the same number of values.')
end

%% Creating aproximation
f = zeros(Nf*T/Tf,1);
f(1:Nf) = func;
% % % f = f(1:round(Nf*T/(Tf*N)):end);
% % % f = f(1:end-1);
% % % f = f';

if ~exist('txt_waitbar')
    txt_waitbar = 'Please wait...';
end

h = waitbar(0,txt_waitbar);
aprox = zeros(N,1);
for i = 1:T
%     predch = toc;
    offset = (i-1)*fix(N/T);
    Tr = zeros(1,N);
    Tr(1,1+offset : end) = f(1 : end - offset);
    coefs(i,1) = Tr*st;
    aprox = aprox + coefs(i)*Tr';
    waitbar(i/T)
%     disp(['iteracia' num2str(i) ', trvanie: ' num2str(toc-predch)])
end
close(h)
return