a nonconventional approach to generating efficient ...

21 downloads 575 Views 647KB Size Report
May 4, 2012 - Wikipedia— shaft encoder 2011. Through the ... and compared with the coding of our proposed ... plexity. • PHP Depend (2011). [Online]. Avail-.
A NONCONVENTIONAL APPROACH TO GENERATING EFFICIENT BINARY GRAY CODE SEQUENCES A. AHMAD AND F. BAIT-SHIGINAH

THE GRAY CODES ARE NAMED after Frank Gray, who patented (U.S. Patent 2 632 058) the use of them in shaft encoders in 1953. Because of the reflection property of the code, sometimes the term Gray code is used to refer to reflected binary codes. The Gray codes are cycling in nature and maintain the unit hamming distance between one code word to the next code word. To visualize the attributes of reflection property, cyclic nature and unit hamming distance of Gray codes, Fig. 1 can be referred to where the binary Gray code patterns G(n) for size n 5 1 to 4 b are depicted. The unique property of Gray code is that every subsequent digit differs from the previous digit by a single bit. Due to this particular property, the codes are used in linear and rotary shaft position encoders. Since the code avoids ambiguous switching situations, the Gray codes are particularly used to safely and conveniently handle control problems. In digital logic design, the Karnaugh maps are used to obtain the minimal expression of a Boolean function, which is based on Gray codes principles to label the axes of the maps. The Gray code serves as a solution guide for many puzzle problems including the Tower of Hanoi. They are also very useful in the field of genetic algorithms during the process of mutations of the algorithm. Modern digital communication systems use Gray codes to detect and correct errors in data transmission. In digital logic design, the Gray codes are used in designs of large chips that operate with many different clocking frequencies. To learn more about the applications of binary Gray codes the interested readers may refer to resources provided in literature including Gray, Heath, Ahmad and Mohammed, and Wikipedia— shaft encoder 2011. Through the literature generated from much discovery, we learn that Gray code is associated with many elegant circuits Digital Object Identifier 10.1109/MPOT.2011.2178193 Date of publication: 4 May 2012

16

© PHOTODISC

and algorithms. However, the procedure of generating Gray code was still done using conventional techniques. Research works in the literature only script the faster codes, but not many deviated from the existing conventional algorithms for generating the Gray codes. To learn more about the various algorithms for generating the binary Gray codes, interested readers may refer to Knuth and Ahmad and Mohammed. We used the conventional approach but suggested the mechanism for reducing the storage complexity for efficient online applications of Gray codes. Through this communication we present a newly evolved concept of generating the Gray codes of n-bit size. The developed algorithm is different from other algorithmic approaches and stemmed from the fact of the study of distributions of 1s and 0s in the columns. The resulting algorithm is in concise form and trivial to implement. The designed algorithm claims a better and more efficient

0278-6648/12/$31.00 © 2012 IEEE

IEEE POTENTIALS

Read more about it >> n = 4; >> GZ = [ ]; >> for i = n – 1: –1: 1 GZ = [GZ 2^(i – 1)]; End >> GZ GZ = 4 2 1

>> n = 4; >> n = 4; >> GS = [ ]; >> TG = [ ]; >> for i = n – 1: –1: 1 >> for i = 1: n – 1 GS = [GS 2^i ]; TG = [TG (2^i ) – 1]; End End >> GS >> TG GS = TG = 8 4 2 1 3 7

Fig. 3 Computing GZ, GS, and TG via MATLAB.

Table 2. Average execution time. Average Execution Times in Seconds

n

Recursive Method (P1)

A Method of Knuth’s (P2)

Proposed Method (P3)

1

0.00238700

0.035800

0.003100

2

0.00345920

0.044320

0.003200

3

0.00534600

0.048800

0.003300

4

0.00695040

0.038229

0.003840

6

0.01166805

0.043348

0.006030

8

0.03463485

0.050920

0.018413

10

0.06492156

0.187521

0.035978

12

0.49794687

0.583512

0.276493

programs. For all three of the programs (P1, P2, and P3), we first executed the algorithms for large number of times and then determined the average CPU execution time for each. A frequency of runs such as 1,000 times is opted in our execution cycle. These averages of execution times for the conventional (recursive), Knuth’s, and the developed algorithms are given in Table 2. To validate results of Table 2, cyclomatic complexity for software metric measurement developed by Thomas J. McCabe Sr., is used to indicate the complexity of the three programs. We used the same source codes for P1 and P2 (as published in the literature McCabe; Watson and McCabe; Wikipedia—cyclomatic complexity, 2011; and Pichler) without any modifications or changes and compared with the coding of our proposed algorithm P3. Table 3 shows the cyclomatic McCabe complexity for the programs P1, P2, and P3.

Further, the determined values of GZ, GS, and TG shown in Table 1 can be verified by computing the values via MATLAB codes. For n 5 4, these computations are shown in Fig. 3.

Implementation of algorithm and results The above designed algorithm is implemented using the MATLAB codes. We also encoded the conventional (recursive) method along with one of the methods from the algorithms of Knuth of Gray code conversions into MATLAB script to compare the execution time efficiency amongst these three approaches. MATLAB 7.0 on a P 4 CPU 1.5 GHz, 512 MB of RAM is used as the benchmarks for testing the codes for the three computing methodologies. The processing time required to implement the three programs [P1: the conventional (recursive), P2: one of the Knuth’s algorithm’s program, and P3: the proposed one] are recorded while running the

Table 3. Cyclomatic McCabe software complexity. McCabe Software Complexity Levels Recursive Method (P1) 3

MAY/JUNE 2012

A Method of Knuth’s (P2) 4

Proposed Method (P3) 2

• F. Gray, “Pulse code communication,” U.S. Patent 2 632 058, Mar. 17, 1953. • F. G. Heath, “Origins of the binary code,” Sci. Amer., vol. 227, no. 2, pp. 76–83, Aug. 1972. • I. Flores, “Reflected number systems,” IRE Trans. Electron. Comput., vol. 5, no. 2, pp. 79–82, June 1956. • W i k ip e d i a — rot a r y e nco der (2011). [Online]. Available: http:// en.wikipedia.org/wiki/Rotary_encoder • D. Knuth, The Art of Computer Programming, vol. 3, Fascicle 2, Generating All Tuples and Permutations. Reading, MA: Addison-Wesley, ch. 7, sec. 7.2.1.1, 2005. • A. Ahmad and M. B. S. Mohammed, “A more economical algorithmic procedure for computing gray codes,” J. Eng. Res., vol. 7, no. 2, pp. 12–19, 2009. • T. J. McCabe, “A complexity measure,” IEEE Trans. Software Eng., vol. SE2, no. 4, pp. 308–320, 1976. • A. H. Watson and T. J. McCabe, “Structured testing: A testing methodology using the cyclomatic complexity metric,” D. R. Wallace, Ed. National Institute of Standards and Technology (NIST), Gaithersburg, MD, 1996. • Wikipedia—Cyclomatic Complexity (2011). [Online]. Available: http:// en.wikipedia.org/wiki/Cyclomatic_complexity • PHP Depend (2011). [Online]. Available: http://pdepend.org/documentation/ software-metrics.html

About the authors A. Ahmad ([email protected]) earned his Ph.D in computer engineering from the Indian Institute of Technology, Roorkee. Currently, he is working at Sultan Qaboos University in Oman. Dr. Ahmad has authored more than 110 scientific papers, some book chapters, numerous technical reports, and scientific manuals. His field of specialization is VLSI testing, algorithm design and testing, fault-tolerant computing, data security, coding and its commercial applications, and development of low cost engineering educational tools. F. Bait-Shiginah ([email protected]) is an assistant professor in the Electrical and Computer Engineering Department at Sultan Qaboos University, Oman. He received his Ph.D. in computer engineering from the University of Arizona, where he specialized in modeling and simulation. 19