The Bar-Width Histogram - A Robust Trick: How Histograms Make Barcode Decoding More Reliable |
Subtitle: A Deep Dive into Histogram-Based Module Width Estimation, Outlier Rejection, and Adaptive Decoding - with Real-World Examples from Symbol, Zebra, Honeywell, Datalogic, Cognex, and Microscan |

|
Opening Summary |
The decoder's most critical task is to estimate the module width - the width of the narrowest bar or space. This estimate is the ruler that measures all other elements. If the estimate is wrong, the entire decoding process fails. The simplest method, the shortest pulse method, works well most of the time, but it is vulnerable to noise, scratches, and print defects. A single noise spike can produce a very short pulse, leading to an underestimation of the module width and a cascade of decoding errors. |
The solution is a robust trick: the bar-width histogram. Instead of relying on a single pulse, the decoder builds a histogram of all the measured pulse widths. The histogram reveals the true distribution of bar widths, with distinct peaks at the module width, twice the module width, and three times the module width. The decoder then finds the first peak - the module width - with far greater reliability than the shortest pulse method. The histogram is a robust statistical tool that rejects outliers and provides a reliable estimate even in the presence of noise and distortion. |
This article is dedicated to the bar-width histogram - its construction, its analysis, and its role in robust barcode decoding. We will explore the different types of histograms (frequency histograms and cumulative histograms), the techniques for peak detection, and the methods for handling variable scanning speeds. We will look at how major companies have implemented histogram-based decoding in their products. We will see how Honeywell uses histograms in their Adaptus firmware. We will explore Datalogic's use of histograms in their Auto-Adaptive Decoding. We will examine Cognex's advanced histogram-based algorithms for machine vision. We will also look at reference designs from Microchip, NXP, and STMicroelectronics. |
By the end of this journey, you will understand that the bar-width histogram is not just a trick but a fundamental technique that underpins the reliability of modern barcode decoders. |

|
Full Article |
Section 1: The Problem with the Shortest Pulse Method |
The shortest pulse method is simple and efficient. It finds the smallest pulse width in the captured sequence and uses it as the module width. This works well when the barcode is clean and the scanning speed is constant. However, the method is vulnerable to a single outlier. |
If a noise spike creates a pulse that is, say, half the width of a real narrow bar, the module width will be underestimated. All subsequent measurements will be off by a factor of two. This can cause a complete decoding failure. Similarly, a scratch or a print defect that creates a very narrow bar can corrupt the estimate. |
Section 2: The Histogram - A Statistical Solution |
A histogram is a statistical tool that shows the distribution of a set of data. The data is grouped into bins, and the height of each bin shows the number of data points in that bin. The histogram provides a visual representation of the data's distribution. |
For bar-width decoding, the data is the set of measured pulse widths. The histogram is constructed by binning the pulse widths. The histogram will show peaks at the module width, twice the module width, and three times the module width. The first peak corresponds to the module width. |
The histogram is robust to outliers. A single noise spike will create a single pulse width that is too small. This outlier will not create a significant peak in the histogram. The first peak will still be at the true module width. |

|
Section 3: Constructing the Histogram - Binning the Data |
The first step in constructing a histogram is to bin the data. The pulse widths are sorted into bins of a certain width. The bin width is typically chosen to be a small fraction of the expected module width (e.g., 1-2%). |
The number of bins must be large enough to show the peaks but not so large that the histogram becomes noisy. A typical histogram has 50-100 bins. |
Section 4: The Frequency Histogram - The Standard Approach |
The frequency histogram is the standard histogram. The y-axis of the frequency histogram shows the number of pulses in each bin. The frequency histogram will have peaks at the module width and its multiples. |
The frequency histogram is easy to construct and easy to interpret. |
Section 5: The Cumulative Histogram - An Alternative Approach |
The cumulative histogram is a variation of the histogram. The y-axis of the cumulative histogram shows the cumulative number of pulses up to each bin. The cumulative histogram is a step function. |
The cumulative histogram can be easier to analyze for some applications. |

|
Section 6: Peak Detection - Finding the Module Width |
The next step is to find the first peak in the histogram. The first peak corresponds to the module width. The peak detection can be done by finding the bin with the maximum count, or by finding the point where the slope of the histogram changes. |
The peak detection must be robust to noise. The histogram is typically smoothed before peak detection. |
Section 7: Histogram Smoothing - Reducing the Noise |
The histogram can be smoothed to reduce the noise. The smoothing is done by applying a moving average filter to the histogram. The moving average filter averages the counts of adjacent bins. |
The smoothing reduces the noise and makes the peaks more distinct. |
Section 8: Honeywell's Histogram-Based Decoding |
Honeywell's Adaptus firmware uses a histogram-based module width estimation. The Adaptus decoder constructs a histogram of the captured pulse widths. The decoder then finds the first peak in the histogram, which corresponds to the module width. |
The histogram-based method is more robust than the shortest pulse method. It is used in all of Honeywell's imagers. |

|
Section 9: Datalogic's Auto-Adaptive Histogram |
Datalogic's Auto-Adaptive Decoding firmware also uses a histogram-based method. The Auto-Adaptive Decoding includes a histogram that is updated dynamically. The histogram is adjusted to changes in the scanning speed. |
The adaptive histogram provides a robust module width estimate in changing conditions. |
Section 10: Cognex's Histogram-Based Algorithms |
Cognex's machine vision algorithms also use histograms. The histograms are used for module width estimation, contrast analysis, and defect detection. |
Cognex's algorithms are highly sophisticated and are used in their DataMan series of barcode readers. |
Section 11: The Histogram and the Scanning Speed Variations |
The scanning speed can vary during a scan. The pulse widths will vary accordingly. The histogram must be able to handle the speed variations. |
The histogram can be constructed from the entire scan. The first peak will correspond to the minimum pulse width, which is the module width at the highest scanning speed. |

|
Section 12: The Histogram and the Print Quality Variations |
The print quality can vary across the barcode. The pulse widths will vary accordingly. The histogram is robust to these variations. The first peak will correspond to the nominal module width. |
Section 13: The Histogram and the Noise |
The histogram is robust to noise. The noise creates random pulses that are not clustered around any peak. The noise will not create a significant peak in the histogram. |
Section 14: The Histogram and the Outliers |
The histogram is robust to outliers. A single outlier will not create a significant peak. |

|
Section 15: The Histogram and the Distortion |
The histogram is robust to distortion. The distortion may shift the peaks slightly, but the first peak will still be identifiable. |
Section 16: The Histogram and the Module Width Resolution |
The histogram's resolution is determined by the bin width. A smaller bin width gives a higher resolution but requires more data. |
Section 17: The Histogram and the Data Length |
The histogram requires a sufficient amount of data. A short barcode may not have enough data to produce a clear histogram. |

|
Section 18: The Histogram and the Symbology |
The histogram is independent of the symbology. The histogram is used for module width estimation, which is the same for all symbologies. |
Section 19: The Histogram and the Decoder's Performance |
The histogram improves the decoder's performance. The histogram provides a more reliable module width estimate, which reduces the decoding errors. |
Section 20: The Histogram and the Decoder's Complexity |
The histogram adds complexity to the decoder. The histogram construction and analysis require additional code and processing time. |
Section 21: The Histogram in Microchip's Reference Design |
Microchip's reference design includes a histogram-based module width estimation. The reference design provides a complete code example. |

|
Section 22: The Histogram in NXP's Reference Design |
NXP's reference design also includes a histogram-based module width estimation. The reference design is optimized for the LPC microcontroller's DMA engine. |
Section 23: The Histogram in STMicroelectronics' Reference Design |
STMicroelectronics' reference design includes a histogram-based module width estimation. The reference design is optimized for the STM32 microcontroller. |
Section 24: The Histogram and the Real-Time Performance |
The histogram must be constructed and analyzed in real-time. The decoder must be fast enough to handle the data rate. |
Section 25: The Histogram and the Memory Usage |
The histogram requires memory to store the bin counts. The memory usage is typically small. |

|
Section 26: The Histogram and the Code Size |
The histogram code adds to the code size. The code size is typically small. |
Section 27: The Histogram and the Power Consumption |
The histogram adds to the power consumption. The power consumption is typically small. |
Section 28: The Histogram and the Microcontroller's Capabilities |
The histogram requires a microcontroller with sufficient processing power and memory. |
Section 29: The Histogram and the Development Tools |
The histogram requires development tools that support the required algorithms. |

|
Section 30: The Histogram and the Testing |
The histogram must be tested with a variety of barcodes and conditions. |
Section 31: The Histogram and the Future - Machine Learning |
Machine learning can be used to improve the histogram analysis. A neural network can be trained to identify the peaks in the histogram. |
Section 32: The Histogram and the Future - Adaptive Histograms |
Adaptive histograms can adjust the bin width and the smoothing based on the data. |
Section 33: The Histogram and the Future - Real-Time Histograms |
Real-time histograms can be constructed and analyzed on the fly. |

|
Section 34: The Histogram and the Future - Histograms for 2D Codes |
Histograms can also be used for 2D codes. The histogram of the pixel values can be used to find the threshold for binarization. |
Section 35: The Histogram and the Future - Histograms for Color Barcodes |
Histograms can be used for color barcodes. The histogram of the color channels can be used to identify the barcode's colors. |
Section 36: The Histogram - A Summary of Best Practices |
Based on our exploration, let us summarize the best practices for using a bar-width histogram in a barcode scanner: |
1. Use a Histogram for Module Width Estimation: The histogram is more robust than the shortest pulse method. |
2. Choose an Appropriate Bin Width: The bin width must be small enough to resolve the peaks. |
3. Smooth the Histogram: Smoothing reduces the noise and makes the peaks more distinct. |
4. Detect the First Peak: The first peak corresponds to the module width. |
5. Handle Outliers: The histogram is robust to outliers. |
6. Test the Histogram: The histogram must be tested with a variety of barcodes and conditions. |

|
Final Summary |
The bar-width histogram is a robust trick that improves the reliability of barcode decoding. The histogram is a statistical tool that shows the distribution of the measured pulse widths. The histogram has peaks at the module width and its multiples. The decoder finds the first peak, which corresponds to the module width. |
We have seen how major companies have implemented histogram-based decoding. Honeywell's Adaptus firmware uses a histogram-based module width estimation. Datalogic's Auto-Adaptive Decoding includes an adaptive histogram. Cognex's machine vision algorithms also use histograms. Microchip, NXP, and STMicroelectronics provide reference designs with histogram-based examples. |
The histogram is a fundamental technique that underpins the reliability of modern barcode decoders. It is a simple but powerful tool that rejects outliers and provides a reliable estimate even in the presence of noise and distortion. |