DSPRelated.com
Code

Duobinary Encoder and Decoder

Senthilkumar March 28, 2012 Coded in Scilab

This function is used to generate duobinary encoder and decoder output with example input and output are pasted below the function. You can test those inputs and verify your result.

function [c,b_r]=Duobinary_EncDec(b)

// Precoded Duobinary coder and decoder
//b = input binary sequence:precoder input
//c = duobinary coder output
//b_r = duobinary decoder output
a(1) = xor(1,b(1));
if(a(1)==1)
  a_volts(1) = 1;
end
for k =2:length(b)
  a(k) = xor(a(k-1),b(k));
  if(a(k)==1)
    a_volts(k)=1;
  else
    a_volts(k)=-1;
  end
end
a = a';
a_volts = a_volts';
disp(a,'Precoder output in binary form:')
disp(a_volts,'Precoder output in volts:')
//Duobinary coder output in volts
c(1) = 1+ a_volts(1);
for k =2:length(a)
  c(k) =  a_volts(k-1)+a_volts(k);
end
c = c';
disp(c,'Duobinary coder output in volts:')
//Duobinary decoder output  by applying decision rule
for k =1:length(c)
  if(abs(c(k))>1)
    b_r(k) =  0;
  else
    b_r(k) = 1;
  end
end
b_r = b_r';
disp(b_r,'Recovered original sequence at detector oupupt:')
endfunction
//Result
//Precoder output in binary form:   
// 
//  1.    1.    0.    0.    1.    0.    0.  
// 
// Precoder output in volts:   
// 
//  1.    1.  - 1.  - 1.    1.  - 1.  - 1.  
// 
// Duobinary coder output in volts:   
//
//  2.    2.    0.  - 2.    0.    0.  - 2.  
// 
// Recovered original sequence at detector oupupt:   
// 
//  0.    0.    1.    0.    1.    1.    0.