% ======================================================================
%> @brief Brief description of the Framework function
%>
%> This function prepare input signals for further processing mainly by 
%>  dividing signals into frames.
%>
%> @param x Contains input signal x.
%> @param y Contains input signal y.
%> @param FS Contains sampling frequency
%> @param FrameLength Contains length of frame in miliseconds
%> @retval l Return number of samples per frame.
%> @retval rx Return signal x reshaped into matrix where one row is one
%>  frame.
%> @retval ry Same as rx but this contains signal y.
%> @retval delay Returns delay between x and y.
% =====================================================================

function [l,rx,ry,delay] = Framework( x,y,FS, FrameLength )
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here
fsx=FS;x=x';
fsy=FS;y=y';
l=floor(FS*FrameLength); 	%pocet vzoriek v jednom ramci 
delay=finddelay(x,y);	 	%zistenie oneskorenia
y=circshift(y,[1 -delay]);	%oprava oneskorenia
%x=x.*(1/abs(max(x)));		%normalizacia x
%y=y.*(1/abs(max(y)));	
if (length(x)>length(y))	%vyrovnanie dlzky signalov
    y(1,length(x))=0;
else x(1,length(y))=0;
end
a=rem(length(x),l);		%zistenie potrebnej dlzky
a=(1-(a/l))*l;
a=length(x)+a;
x(1,a)=0;				%doplnenie nulami
y(1,a)=0;
rx=reshape (x,l,[]);rx=rx';	%rozdelenie na ramce
ry=reshape (y,l,[]);ry=ry';

end

