<jupyter_start><jupyter_text>***Introduction to Radar Using Python and MATLAB*** <NAME> - Copyright (C) 2019 Artech House Barker Ambiguity Function*** Referring to Section 8.7.1, a common set of binary phase codes for radar applications is Barker codes, which have several unique properties.  The time sidelobe level of the normalized ambiguity function is $1/N$, where $N$ is the length of the code.  The ambiguity function has a length of $2N\tau_n$, the main lobe has a width of $2\tau_n$, and there are $(N-1)/2$ sidelobes on either side of the main lobe.  There are only seven known Barker codes, and these are given in Table 8.1.While these are the only known Barker codes, much research has been performed to find longer binary phase codes with low time sidelobe levels.  Although the time sidelobe levels are not $1/N$ as with the Barker codes, some codes have been found to have quite small sidelobe levels.  A Barker code of length $4$ is illustrated in Figure 8.20.  Another approach to obtain longer codes is to combine or embed one code within another.  For example, a Barker code of length $5$ may be used with a Barker code of length $3$ to give (Equation 8.71)\begin{equation}    B_{MN} = [\; \; 0\;\; 0\;\; 0\;\; \pi\;\; 0\,,   \; 0\;\; 0\;\; 0\;\; \pi\;\; 0\,,   \; \pi\;\; \pi\;\; \pi\;\; 0\;\; \pi\;].\end{equation}The compression ratio of the combined Barker code is $MN$.  However, the sidelobe level of the combined code is not $1/MN$.  When using combined Barker codes, a number of sidelobes may be reduced to zero if the matched filter is followed by a linear transversal filter.*** Begin by getting the library path<jupyter_code>import lib_path<jupyter_output><empty_output><jupyter_text>Set the chip width (s) and the code length (2, 3, 4, 5, 7, 11, 13)<jupyter_code>chip_width = 0.1

code_length = 5<jupyter_output><empty_output><jupyter_text>Set the Barker code<jupyter_code>if code_length == 2:

    code = [1, -1]

elif code_length == 3:

    code = [1, 1, -1]

elif code_length == 4:

    code = [1, 1, -1, 1]

elif code_length == 5:

    code = [1, 1, 1, -1, 1]

elif code_length == 7:

    code = [1, 1, 1, -1, -1, 1, -1]

elif code_length == 11:

    code = [1, 1, 1, -1, -1, -1, 1, -1, -1, 1, -1]

elif code_length == 13:

    code = [1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1]<jupyter_output><empty_output><jupyter_text>Calculate the ambiguity function for the Barker code<jupyter_code>from Libs.ambiguity.ambiguity_function import phase_coded_wf


ambiguity, time_delay, doppler_frequency = phase_coded_wf(code, chip_width)<jupyter_output><empty_output><jupyter_text>Display the zero-Doppler cut, the zero-range cut, and the 2D contour plot using the `matplotlib` routines<jupyter_code>from matplotlib import pyplot as plt


# Set the figure size

plt.rcParams["figure.figsize"] = (15, 10)



# Plot the ambiguity function

plt.plot(time_delay, ambiguity[round(len(doppler_frequency) / 2)], '')



# Set the time axis limits

plt.xlim(-len(code) * chip_width, len(code) * chip_width)



# Set the x and y axis labels

plt.xlabel("Time (s)", size=12)

plt.ylabel("Relative Amplitude", size=12)



# Turn on the grid

plt.grid(linestyle=':', linewidth=0.5)


# Set the plot title and labels

plt.title('Barker Code Ambiguity Function', size=14)



# Set the tick label size

plt.tick_params(labelsize=12)<jupyter_output><empty_output><jupyter_text>Create the zero-range cut<jupyter_code># Plot the ambiguity function

plt.plot(doppler_frequency,  ambiguity[:, round(len(time_delay) / 2)], '')



# Set the x and y axis labels

plt.xlabel("Doppler (Hz)", size=12)

plt.ylabel("Relative Amplitude", size=12)



# Turn on the grid

plt.grid(linestyle=':', linewidth=0.5)


# Set the plot title and labels

plt.title('Barker Code Ambiguity Function', size=14)



# Set the tick label size

plt.tick_params(labelsize=12)<jupyter_output><empty_output><jupyter_text>Create the two-dimensional contour plot<jupyter_code>from numpy import meshgrid


# Create the grid

t, f = meshgrid(time_delay, doppler_frequency)



# Plot the ambiguity function

plt.contour(t, f, ambiguity, 30, cmap='jet', vmin=-0.2, vmax=1.0)



# Set the time axis limits

plt.xlim(-len(code) * chip_width, len(code) * chip_width)



# Set the x and y axis labels

plt.xlabel("Time (s)", size=12)

plt.ylabel("Doppler (Hz)", size=12)



# Turn on the grid

plt.grid(linestyle=':', linewidth=0.5)



# Set the plot title and labels

plt.title('Barker Code Ambiguity Function', size=14)



# Set the tick label size

plt.tick_params(labelsize=12)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12218579234972678, 'fraction_numerical': 0.0312568306010929, 'mean_word_length': 4.259770114942529, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '167041', 'license': 'Apache-2.0', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1541, 'n_words': 566, 'path': 'jupyter/Chapter08/barker_ambiguity.ipynb', 'repo_name': 'miltondsantos/software', 'size': '4582'}