Cnv_encd.m
Upload User: loeagle
Upload Date: 2013-03-02
Package Size: 1236k
Code Size: 1k
Development Platform:

Matlab

  1. function output=cnv_encd(g,k0,input)
  2. %   cnv_encd(g,k0,input)
  3. %   determines the output sequence of a binary convolutional encoder
  4. %   g is the generator matrix of the convolutional code
  5. %         with n0 rows and l*k0 columns. Its rows are g1,g2,...,gn.
  6. %   k0 is the number of bits entering the encoder at each clock cycle.
  7. %   input is the binary input seq.
  8. %  Check to see if extra zero-padding is necessary.
  9. if rem(length(input),k0) > 0
  10.   input=[input,zeros(size(1:k0-rem(length(input),k0)))];
  11. end
  12. n=length(input)/k0;
  13. %  Check the size of matrix g.
  14. if rem(size(g,2),k0) > 0
  15.   error('Error, g is not of the right size.')
  16. end
  17. %  Determine l and n0.
  18. l=size(g,2)/k0;
  19. n0=size(g,1);
  20. %  add extra zeros
  21. u=[zeros(size(1:(l-1)*k0)),input,zeros(size(1:(l-1)*k0))];
  22. %  Generate uu, a matrix whose columns are the contents of 
  23. %  conv. encoder at various clock cycles.
  24. u1=u(l*k0:-1:1);
  25. for i=1:n+l-2
  26.   u1=[u1,u((i+l)*k0:-1:i*k0+1)];
  27. end
  28. uu=reshape(u1,l*k0,n+l-1);
  29. %  Determine the output
  30. output=reshape(rem(g*uu,2),1,n0*(l+n-1));
  31.