% Encoder for the (7,5) convolutional code
% bits to be encoded are in the row vector msg
% The routine pads two zeros to msg, to ensure that the termination state
% is 00
% Thus, for N input bits (i.e., length(msg)=N), we get 2N+4 output bits 

function v = encoder_75(msg)
taps=[ 1 1 1;1 0 1];
msg_pad=[msg zeros(1,2)]; % pad with zeros to ensure final state is 00
init1=zeros(1,2); % initial state
v=zeros(1,length(msg_pad)*2);
for o=1:length(msg_pad),
  v((o-1)*2+1:o*2)=[mod((taps(1,:)*[msg_pad(o) init1]'),2) mod((taps(2,:)*[msg_pad(o) init1]'),2) ];
  init1(2:end)=init1(1:end-1);
  init1(1)=msg_pad(o);
end
end