<jupyter_start><jupyter_text>***Introduction to Radar Using Python and MATLAB*** <NAME> - Copyright (C) 2019 Artech House Analog to Digital Conversion*** Referring to Section 5.8.2, the step size between levels for an N-bit ADC may be written as$$    Q = {LSB} = \frac{V_{{FS}}}{2^N-1} \hspace{0.5in} \text{(V)}$$*** Begin by setting the library path<jupyter_code>import lib_path<jupyter_output><empty_output><jupyter_text>Set the number of bits and sampling frequency (Hz) in the ADC<jupyter_code>number_of_bits = 3

sampling_frequency = 100<jupyter_output><empty_output><jupyter_text>Set the start frequency (Hz), end frequency (Hz), amplitude modulation frequency (Hz) and amplitude (relative) for a sample analog signal<jupyter_code>start_frequency = 10

end_frequency = 40

am_amplitude = 0.1

am_frequency = 20<jupyter_output><empty_output><jupyter_text>Generate the "analog" signal using the `linspace` and `chirp` routines from `scipy`<jupyter_code>from numpy import linspace, sin

from scipy.constants import pi

from scipy.signal import chirp

t = linspace(0.0, 1.0, 4196)

a_signal = chirp(t, start_frequency, t[-1], end_frequency)

a_signal *= (1.0 + am_amplitude * sin(2.0 * pi * am_frequency * t))<jupyter_output><empty_output><jupyter_text>Set up the waveform<jupyter_code>from numpy import arange

time = arange(sampling_frequency + 1) / sampling_frequency

if_signal = chirp(time, start_frequency, time[-1], end_frequency)

if_signal *= (1.0 + am_amplitude * sin(2.0 * pi * am_frequency * time))<jupyter_output><empty_output><jupyter_text>Calculate the envelope using the `quantize` routine<jupyter_code>from Libs.receivers import quantization

quantized_signal, error_signal = quantization.quantize(if_signal, number_of_bits)<jupyter_output><empty_output><jupyter_text>Use the `matplotlib` routines to display the resulting quantized signal<jupyter_code>from matplotlib import pyplot as plt

from matplotlib.figure import Figure


# Set the figure size

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


# Display the results

fig, (axes1, axes2) = plt.subplots(2, 1)

axes1.plot(t, a_signal, '', label='Analog Signal')

axes1.plot(time, quantized_signal, '-.', label='Digital Signal')

axes2.plot(time, error_signal, '', label='Quadrature')


# Set the plot title and labels

axes1.set_title('Analog to Digital Conversion', size=14)

axes2.set_xlabel('Time (s)', size=12)

axes1.set_ylabel('Amplitude (V)', size=12)

axes2.set_ylabel('Error (V)', size=12)


# Set the tick label size

axes1.tick_params(labelsize=12)

axes2.tick_params(labelsize=12)


# Turn on the grid

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

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


# Show the legend

axes1.legend(loc='lower left', prop={'size': 10})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12283236994219653, 'fraction_numerical': 0.028901734104046242, 'mean_word_length': 6.463611859838275, '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': '201449', 'license': 'Apache-2.0', 'n_tokens_mistral': 1050, 'n_tokens_neox': 975, 'n_words': 246, 'path': 'jupyter/Chapter05/adc.ipynb', 'repo_name': 'miltondsantos/software', 'size': '2775'}