Gray code pattern looks like binary pattern. Is this correct?

186 Views Asked by At

I have this following gray code pattern but it looks like binary pattern to me. Please let me know if this is correct or something has to be changed?

n = ceil(log2(py));  T = length(n) ;
gray_pattrn = zeros(2^n,1) ;  gray_pattrn(2) = 1;  T = 2;
for  k = 2:n
   T2 = T+T ;
   gray_pattrn(T+1:T2) = T + flipud(gray_pattrn(1:T)) ;
   T = T2;  
end
mat = transpose(flip(transpose(de2bi(gray_pattrn))));

gray_level = 4; 
patternSeq = transpose(repmat(mat(:, gray_level), 1, 1024));
figure, imagesc(patternSeq); colormap gray;
figure, plot(patternSeq(512,:));

And I got the following images.

Gray code pattern Gray code at pixel 512

1

There are 1 best solutions below

0
RPM On

Despite the name, Gray code is binary and so what you are getting could very well be correct (I haven't actually checked your code). It's called Gray code because it was invented by Frank Gray, not because it outputs grayscale values (it doesn't).