function [ dat ] = decode( codeddat, m, n, k )
%[ outsig ] = code( insig, m, n, k )
%   This file assumes M=2 and that the # of channels is even.
%   Channels are paired to make M=4 bits, the signal is encoded
%   and then the coded date is again split into N channels



[rows, cols] = size(codeddat);
codeddat = gf(codeddat, m);
dat = gf(zeros(rows, ceil(k*cols/n)), m);
%outdat = rsenc(outdat, n, k)

for r = 1:rows
    for c = 1:ceil(cols/n)
        ceil(cols/n)
        cols
        n
        codemsg = codeddat(r, (c-1)*n+1:c*n);
        msg = rsdec(codemsg, n, k);
        dat(r, (c-1)*k+1:k*c) = msg(1, :);
    end
end    

dat = gf2dec(dat, m, primpoly(m));

%outdat = codedat;
    
%outdat = codedat;    
%for i = 1:rows/2
%    outdat(2*i-1, :) = mod(codedat(i), 4);
%    outdat(2*i, :) = (codedat(i)-outdat(2*i-1, :))/4;
%end
    
