%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                        %
%                                 LTE_Int                                %
%                                                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%ZABEZPECUJE INTERLEAVNUTIE A DEINTERLEAVNUTIE DAT
%Vstupne premenne:
%data - ktore budu de/interleavnute [double,int]
%x - oznacuje interleaver/deinterleaver [bool][1-int,0-deint]
%Vystupna premenna:
%out - interleavnute/deinterleavnute data [double,int]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out = LTE_Int(data,x)

inf = 9e9;
[a, b] = size(data);
vys_int = repmat(inf,[a, b]);
vys_dei = repmat(inf,[a, b]);
table = dlmread('LTE_table.txt');                                           %hodnoty pre jednotlive velkosti blokov
[r, s] = find(table(:,1)==b);                                      

if (~isempty(a)&&~isempty(b))
    %%INTERLEAVER
    if(x == 1)
        for i=1:b
            zzz = (table(r,2)*(i-1)+table(r,3)*(i-1)^2);                    %vypocet podla standardu LTE
            index = mod(zzz,b) + 1;
            vys_int(a, index) = data(a, i); 
        end
        out = vys_int;
    %DEINTERLEAVER
    elseif(x == 0)
        for j=1:b
            zzz = (table(r,2)*(j-1)+table(r,3)*(j-1)^2);                    %vypocet podla standardu LTE
            index = mod(zzz,b)+1;
            vys_dei(a, j) = data(a, index);
        end
        out = vys_dei;
    end
else
    error('CHYBA');
end
end
