LAT Hologramm-Software 2.0
Loading...
Searching...
No Matches
dec2gray.m
Go to the documentation of this file.
1function [gray] = dec2gray(decimal)
2%DEC2GRAY decimal to Gray-Code conversion
3%Autor: Damian Haske
4
5% max=255 (8 bit)
7i = 1;
8q = floor(decimal/2);
9r = rem(decimal, 2);
10binaer(i) = num2str(r(i));
11
12 while 2 <= q
13 decimal = q;
14 i = i + 1;
15 q = floor(decimal/2);
16 r = rem(decimal, 2);
17 binaer(i) = num2str(r);
18 end
19
20binaer(i + 1) = num2str(q);
21binaer = fliplr(binaer);
22
23gray(1) = binaer(1);
24
25 for i = 2 : length(binaer)
26 x = xor(str2double(binaer(i-1)), str2double(binaer(i)));
27 gray(i) = num2str(x);
28 end
29
30gray=fliplr(gray);
31lengthstr=strlength(gray);
32
33
34for i = 1:1:8
35 if i>lengthstr
36 gray(i) = 0;
37 else
38 gray(i+lengthstr) = gray(i);
39 end
40end
41
42gray=[gray(8), gray(7), gray(6), gray(5), gray(4), gray(3), gray(2), gray(1)];
43
44gray=(zeros(1,8)+gray)-48;
45
46for i = 1:1:8
47if gray(i)==-48
48 gray(i)=0;
49end
50end
51
52
53% https://www.matrixlab-examples.com/gray-code.html
54% https://www.matrixlab-examples.com/decimal-to-binary.html
function dec2gray(in decimal)
#define bit(n)
Definition: nuts_bolts.h:61
#define max(a, b)
Definition: nuts_bolts.h:56