% graycode.m % convert from (value,length) to a bitstring. % Usage: % c = graycode(9, 8) % print_without_spaces(c) % returns the 8 bits % c = [ 0 0 0 0 1 1 0 1 ] % 00001101 % This has a value of 9 when interpreted as gray code. % by John C. Kieffer % http://www.ee.umn.edu/users/kieffer/programs.html % documented in % ftp://oz.ee.umn.edu/users/kieffer/seminar/notes1.ps % more documentation by David Cary 1999-06-26 % % See also BINARYCODE, BINARY_TO_INDEX, PRINT_WITHOUT_SPACES. function y = graycode(i,L) x=binarycode(i,L); y(1)=x(1); for j=2:L; if x(j-1)==1 y(j)=1-x(j); else y(j)=x(j); end end