function rs_example
% (15, 9) reed-solomon
%input
m = 4; % Number of bits per symbol
n = 2^m-1; k = 9; % Word lengths for code

% define 0, 1, alpha and alpha powers in GF

% alpha table
% 0, 1, 2, ..., n-1

zero = gf(0, m);
one = gf(1, m);
alpha = gf(2, m);

alpha_tbl = [];
for i = 1:n-1
    alpha_tbl = [alpha_tbl alpha^i];
end

poly=rsgenpoly(15, 9, 19, 1);

msg = gf([4 15 10 3 8 6 1 2 5],m);
%msg = gf([5 2 1 6 8 3 10 15 4],m); % Two rows of m-bit symbols
code = rsenc(msg,n,k, poly)
err = gf([0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], m);
rcv = code + err
%rcv = gf([6 15 10 3 8 6 2 2 5 2 6 8 13 4 5], m);
%decoding:

% why alpha = 2H
% convenient for programming
% remember in most of the textbooks, 1 is 2^{n-1}

%step1: get syndromes:
s=[]; 
for i = 1: n-k
    xi = alpha_tbl(i);
    si = rcv(n);
    for j= 1:n-1
        si = si + rcv(j)*xi^(n-j);
    end
    s=[s si];
end
s
   % rcv(i)
% end


%dec = rsdec(rcv, n, k) 