Barker Code Generator
Generate bipolar Barker Code
Libraries:
Communications Toolbox
Communications Toolbox /
Comm Sources /
Sequence Generators
Description
The Barker Code Generator block generates a bipolar Barker code. The short length and low correlation sidelobes make Barker codes useful for frame synchronization in digital communications systems. For more information, see Barker Codes.
Examples
Generate Barker Code With Various Code Lengths
The cm_ex_various_barker_code_length
model shows the output from Barker Code Generator
blocks configured for 15 samples per frame at a sample time of 1, and code lengths set to 3, 4, 7, and 13. The plot shows that the code sequence repeats, as needed, to fill a 15 sample frame.
Plot the Barker code sequences. Each Barker Code Generator
block outputs one frame with 15 samples. Comparing the code sequences you can see the code is repeated to fill the frame.
Detect Barker Code Preamble in Frames
Construct two frames consisting of a 7-bit Barker code preamble and a 14-bit payload field. Detect the preamble locations by using the Preamble Detector
block.
Based on detection of a Barker code preamble by the Preamble Detector
block, the model displays the index location of the last bit in each preamble detected. To load the model and to configure the runtime preamble setting, callback functions are used. For more information, see Model Callbacks (Simulink).
When loading the model, a
PostLoadFcn
callback initializes the preamble value of the Preamble Detector block.
For runtime execution, an
InitFcn
callback gets the runtime setting for the preamble from the Barker Code Generator block.
The Barker Code Generator block outputs a bipolar (-1,1) signal that must be converted to unipolar (0,1) for the Preamble Detector block. When you run the model, the display shows the numbers 7 and 28 corresponding to the locations at the end of the two preambles.
Extended Examples
Frame Synchronization Using Barker Code Preamble
Use a length 13 Barker code frame preamble for frame synchronization of data bits.
Ports
Output
output — Barker code frame
column vector
Barker code frame, returned as a column vector. If the frame length exceeds the Barker code length, the block fills the frame by repeating the Barker code.
Dependencies
Set the data type of the output with the Output data type parameter.
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
Code length — Length of generated code
7
(default) | 1
| 2
| 3
| 4
| 5
| 11
| 13
Length of the generated code, specified as 1
,
2
, 3
, 4
,
5
, 7
, 11
, or
13
. For more information, see Barker Codes.
Example: 2
outputs the Barker code
[–1;1].
Sample time — Output sample time
1
(default) | -1 | positive scalar
Positive scalars specify the time in seconds between each
sample of the output signal. If you set the sample time to -1
, the output
signal inherits the sample time from downstream. For information on the relationship between the
Sample time and Samples per frame parameters,
see
Sample Timing.
Samples per frame — Samples per output frame
1
(default) | positive integer
Samples per output frame, specified as a positive integer. If Samples per frame is M, the block outputs a frame containing M samples comprised of length N Barker code sequences. N is the length of the generated code, which is set by the Code length parameter. When M is not an integer multiple of N, consecutive frames maintain continuity of the Barker code across frame boundaries.
For information on the relationship between Sample time and Samples per frame, see Sample Timing.
Output data type — Output data type
double
(default) | int8
Output data type, specified as double
or
int8
.
Simulate using — Type of simulation to run
Code generation
(default) | Interpreted execution
Type of simulation to run, specified as Code generation
or
Interpreted execution
.
Code generation
— Simulate the model by using generated C code. The first time you run a simulation, Simulink generates C code for the block. The model reuses the C code for subsequent simulations unless the model changes. This option requires additional startup time, but the speed of the subsequent simulations is faster than with theInterpreted execution
option.Interpreted execution
— Simulate the model by using the MATLAB® interpreter. This option shortens startup time, but the speed of subsequent simulations is slower than with theCode generation
option. In this mode, you can debug the source code of the block.
For more information, see Interpreted Execution vs. Code Generation (Simulink).
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
More About
Barker Codes
Barker codes have a maximum autocorrelation sequence, which has off-peak autocorrelations no larger than 1.
A correlation sidelobe is the correlation of a codeword with a time-shifted version of itself. The correlation sidelobe, Ck, for a k-symbol shift of an N-bit code sequence, {Xj}, is
For j=1, 2, 3,..., N, Xj is an individual code symbol that is equal to +1 or –1. The adjacent symbols are assumed to be 0.
The output code is in a bipolar format with 0 and 1 mapped to 1 and –1. The maximum known Barker code length is 13. The short length and low correlation sidelobes make Barker codes useful for frame synchronization in digital communications systems. The Barker code generator outputs the Barker codes listed in this table.
Barker Code Length | Barker Code | Sidelobe Level |
---|---|---|
1
| [–1] | 0 dB |
2
| [–1; 1] | –6 dB |
3
| [–1; –1; 1] | –9.5 dB |
4
| [–1; –1; 1; –1] | –12 dB |
5
| [–1; –1; –1; 1; –1] | –14 dB |
7
| [–1; –1; –1; 1; 1; –1; 1] | –16.9 dB |
11
| [–1; –1; –1; 1; 1; 1; –1; 1; 1; –1; 1] | –20.8 dB |
13
| [–1; –1; –1; –1; –1; 1; 1; –1; –1; 1; –1; 1; –1] | –22.3 dB |
Sample Timing
The time between output updates is equal to the product of the
Samples per frame and Sample time parameter
values. For example, if Sample time and Samples per
frame each equal 1
, the block outputs one sample every
second. If you increase Samples per frame to 10, then the block outputs
a 10-by-1 vector every 10 seconds. This timing ensures that the equivalent output rate is
not dependent on the Samples per frame parameter.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Usage notes and limitations:
Does not support integer only code generation.
Version History
Introduced before R2006aR2020a: Existing models automatically update this block to current version
Starting in R2020a, Simulink no longer allows you to use the Barker Code Generator block version available before R2015b.
Existing models automatically update to load the Barker Code Generator block version announced in Source blocks output frames of contiguous time samples but do not use frame attribute. For more information on block forwarding, see Maintain Compatibility of Library Blocks Using Forwarding Tables (Simulink).
See Also
Blocks
Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)