%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                        %
%                              WiMAX_Blok                                %
%                                                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%vstupne premenne:
%data - data z prenosoveho kanala [double]
%blok - velkost bloku [int]
%rate - rate kodera [double]
%vystupna premenna:
%out - data rozdelene do blokov [double]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out = WiMAX_Blok(data,blok,punc)

y = [];                                                                    
table = [12,24,48,72,96,144,192,288,384,576,768,1152];                      %povolene hodnoty blokov
[r, s] = find(table(1,:)==blok);

if (~isempty(r)&&~isempty(s))
    %%RATE 1/5
    if (punc == 1/5)                                                        
        b = blok*5;                                                         %velkost dat bloku pre dekoder (*3 pretoze sy,pa1,pa2)
        it = floor(length(data)/b);                                         %zistenie poctu blokov
        for i = 1:it     
            y(i,:) = data(1,(i*b-b)+1:i*b);                                 %S W1 W2 Y1 Y2
        end
    %%RATE 1/3
    elseif (punc == 1/3)                                                                        
        b = blok*3;                                                        
        it = floor(length(data)/b);
        for i = 1:it
            y(i,:) = data(1,(i*b-b)+1:i*b);                                 %S W1 W2
        end
    %%RATE 1/2
    elseif (punc == 1/2)
        b = blok*2;
        it = floor(length(data)/b);
        for i = 1:it
            y(i,:) = data(1,(i*b-b)+1:i*b);                                 %S W1 W2 - len polovice s par.
        end
    else
        fprintf('Nespravny rate.');
    end
else
    disp('Nesprávna veľkost bloku.');
end
out = y;                                                                    %vystup funkcie
end