% Simulasi Kinerja Kode Blok Linier
% Programmer    : M. Agus Zainuddin
% Tanggal       : 02 Apr 09

clear all, close all, clc;
tic
% --- Proses Source Coding ---
disp('Proses Source Coding');
I = imread('Lena256.bmp');
[A B] = size(I);
Citra = double(I);
C_bin = de2bi(Citra,8,'left-msb');
bit_stream = reshape(C_bin',1,A*B*8);

% --- Proses Channel Coding ---
disp('Proses Channel Coding');
code = buffer(bit_stream',4)';
P = randint(4);
G = [P eye(4)];
H = [eye(4) P'];
tabel = syndtable(H);
codeword = encode(code,8,4,'linear',G);

% --- Proses Transmissi ---
tx = pskmod(codeword,2);
EbNo = 2;
kanal = awgn(tx,EbNo);
rx = pskdemod(kanal,2);

% --- Proses Channel Decoding ---
code_est = decode(rx,8,4,'linear',G,tabel);

% --- Proses Source Decoding ---
C_bin_est = reshape(code_est',8,A*B)';
Citra_est = reshape(bi2de(C_bin_est,'left-msb'),A,B);
I_est = uint8(Citra_est);


% --- Tampilan Visual ---
imshow(I),title('Citra Asli');
figure;
imshow(I_est),title('Citra Rekontruksi');

toc