0

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

dazemood
  • 23
  • 5
  • Your example does not execute. How is `py` defined when you run it? – beaker Jan 17 '21 at 16:07
  • I am defining py as 1024. Size of the image as 1024x1024 – dazemood Jan 18 '21 at 18:31
  • Okay, and what are you trying to visualize? You're getting a valid Gray code listing, but you're only plotting the 4th bit of each pattern. – beaker Jan 18 '21 at 18:42
  • My idea is to use these gray codes to do phase unwrapping that is combined with sinusoidal pattern.If this is correct, then I hope i can do the unwrapping properly – dazemood Jan 20 '21 at 09:27
  • Then, as the answer below states, this is a binary code so you're going to get a binary plot. Perhaps if you looked at each row of the Gray code pattern as a gray level? Something like `imagesc(gray_pattrn.')`? – beaker Jan 20 '21 at 16:17
  • Thats what I have shown in the figure above the plot. – dazemood Jan 21 '21 at 19:30
  • I was suggesting `gray_pattrn` rather than `patternSeq`. – beaker Jan 21 '21 at 19:32

1 Answers1

2

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).

RPM
  • 1,704
  • 12
  • 15