I am designing a pen-type barcode scanner (1D) which is operated by user, which means that the speed at which the scanner moves is random. Even worse is that it gets stuck sometimes, so the signal gets stretched or even goes back sometimes.

Well, all is not so bad as it sounds since I ran some tests and it seems that this distortion always happens at the 4th pulse. As it can be seen from picture, this pulse has a very long fall time. So here is the question:

What signal processing techniques can you recommend to make this right? I mean just to mark this pulse as a 1 without making the micro controller crazy? (The output of the photodiode of the scanner is fed to the ADC of a MSP430)enter image description here

  • 3
    \$\begingroup\$ What are we looking at, what are the axis, what created it? \$\endgroup\$ – PlasmaHH Jan 17 '17 at 13:13
  • \$\begingroup\$ This might also be a good question to move to DSP.stackexchange.com \$\endgroup\$ – Marcus Müller Jan 17 '17 at 13:13
  • \$\begingroup\$ It is the output of the photodiode, connected to the ADC of the MSP430, and read there \$\endgroup\$ – Sina Jan 17 '17 at 13:14
  • \$\begingroup\$ @Sina: so x axis is lux and y axis is square meters? \$\endgroup\$ – PlasmaHH Jan 17 '17 at 13:15
  • \$\begingroup\$ @PlasmaHH Horizontal axis is the sample numbers, and vertical axis is the voltage of the diode \$\endgroup\$ – Sina Jan 17 '17 at 13:16

You'll have to make some assumptions. A typical assumption is that the dragging speed of the user doesn't change very abruptly in the middle of a bar code.

Since barcodes contain regions of fixed, known width, it's easy to calculate the dragging speed based on that. Your algorithm just waits for the first strong "bright-dark-bright" transitions, and bases its timing on that.

For example, consider the ubiquitous EAN-13 barcodes (really, read the excellent wikipedia article from which this picture was taken):

They begin and end with two constant-width stripes. So you watch out for "bright-dark-bright" first, measure the duration of this "dark", then you expect the "bright" and the next "dark" to be as long as the first dark, and if you find that, ie. a equidistant "dark-bright-dark", you've

  1. found the beginning of an EAN barcode, and
  2. found out the "timing" of a thin stripe at the same time.

Based on the length of that "dark", you can then adjust your signal interpretation. Even slow microcontrollers will be able to do that; these barcodes were designed for 1970's electronics, after all, and they became popular when they were trivial to decode using 1980's electronics...

A note on the usage of an ADC: yes, if you have a microcontroller that has an ADC, feel free to use it. You don't have to – classically, barcode readers are implement using analog high-pass filters that only detect the edges between bright and dark (and then emit a 1 whenever there's such an edge) – you'd have to adjust your algorithms, but by reducing your analog input to a binary input, you potentially save a lot of CPU power.

| improve this answer | |
  • \$\begingroup\$ Very nive review and great resources t refresh the mind on the concept of barcode, we do the same, I mean, assuming a speed for the movement and coding based on that, but that pause in the middle does happen because of a problem of the case of the device and the signal gets stretched. \$\endgroup\$ – Sina Jan 17 '17 at 13:44
  • \$\begingroup\$ P.S. I will keep you note on outsourcing the ADC in mind, power is a big concern and if this helps, it would be very important for the final device \$\endgroup\$ – Sina Jan 17 '17 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.