.

Barker code


Tags: dsp math
Reading time: about 2 minutes

A Barker code, also known as a Barker sequence, is a sequence of values with excellent autocorrelation properties. Thanks to this, it can be used for synchronization in DSP.

Since we have fast computers, we can come up with these sequences ourselves by trying all sequences and evaluating their autocorrelation properties.

Known Barker codes

Below is a table of the currently known Barker codes up to length 13.

Although the length‑1 sequence (often just 1) is technically a Barker code, practical interest usually begins at length 2.

Length Code
2 1, -1
2 1, 1
3 1, 1, -1
4 1, 1, -1, 1
4 1, 1, 1, -1
5 1, 1, 1, -1, 1
7 1, 1, 1, -1, -1, 1, -1
11 1, 1, 1, -1, -1, -1, 1, -1, -1, 1, -1
13 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1

These are the only ones that are known, and people have checked quite a lot of them. It’s conjectured that these ones are the only ones that exist.

Equivalent codes

If you negate a code, or reverse a code, you get an equivalent code with the same autocorrelation properties. We count them as the same code. Combinations of these “transforms” (such as negation of the reversal etc.) are also equivalent.

Negation of codes

This means in the sequence, every +1 becomes a -1, and every -1 becomes a +1.

Code Negation of the code
-1, -1, 1, -1 1, 1, -1, 1
1, -1, -1 -1, 1, 1

Reversal of codes

Just flip it around, instead of reading left-to-right, read it right-to-left.

Code Reversal of the code
-1, -1, -1, 1, -1 -1, 1, -1, -1, -1
-1, -1, -1, 1 1, -1, -1, -1

Normalizing codes

To simplify comparisons and storage, one can “normalize” a Barker code to a canonical representation chosen from its four equivalent forms.

One common approach is to generate the four equivalents (original, negated, reversed, and negated–reversed) and choose the lexicographically largest sequence.

I picked “largest” here arbitrarily. You can use any criteria, but largest seems like a good one.

Below is a Python snippet that does this.

def normalize_code(code: list[int]) -> list[int]:
    return max(
        code, # original
        [-x for x in code], # negated
        code[::-1], # reversed
        [-x for x in code[::-1]]) # negated and reversed

Sidelobe level ratio

You can calculate the sidelobe level ratio of the autocorrelation of a length $N$ barker code in dB as $20 * log_{10}(1/N)$.

The sidelobe level ratio, as given above, indicates how much weaker the largest sidelobe is relative to the main lobe (at zero lag). Lower values imply better discrimination against delayed copies of the signal.

Below are the sidelobe level ratios of all the code lengths with known Barker codes.

Code length Sidelobe level ratio
2 -6 dB
3 -9.5 dB
4 -12 dB
5 -14 dB
7 -16.9 dB
11 -20.8 dB
13 -22.3 dB

Useful links

Citation

If you find this work useful, please cite it as:
@article{yaltirakli,
  title   = "Barker code",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2022",
  url     = "https://www.gkbrk.com/barker-code"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Barker code", September, 2022. [Online]. Available: https://www.gkbrk.com/barker-code. [Accessed Apr. 17, 2025].
APA Style
Yaltirakli, G. (2022, September 07). Barker code. https://www.gkbrk.com/barker-code
Bluebook Style
Gokberk Yaltirakli, Barker code, GKBRK.COM (Sep. 07, 2022), https://www.gkbrk.com/barker-code

Comments

© 2025 Gokberk Yaltirakli