You are on page 1of 1

#Name : Prathamesh Jadhav ,Reg. No.2020BCS151 ,Roll No.

A66

import numpy as np
import matplotlib.pyplot as plt

time_of_view = 1.0 # seconds


analog_time = np.linspace(0, time_of_view, num=1000000)

sampling_rate = 20.0 # Hz
sampling_period = 1.0 / sampling_rate
sample_number = int(time_of_view / sampling_period)
sampling_time = np.linspace(0, time_of_view, num=sample_number, endpoint=False)

carrier_frequency = 9.0 # Hz
amplitude = 1.0
phase = 0.0

quantizing_bits = 4
quantizing_levels = 2 ** quantizing_bits
quantizing_step = 1.0 / quantizing_levels

def analog_signal(time_point):
return amplitude * np.cos(2 * np.pi * carrier_frequency * time_point + phase)

np.random.seed(123) # Set the random seed for reproducibility


sampling_signal = analog_signal(sampling_time)
quantizing_signal = np.round(sampling_signal / quantizing_step) * quantizing_step

fig = plt.figure()
plt.plot(analog_time, analog_signal(analog_time))
plt.stem(sampling_time, quantizing_signal, linefmt='r-', markerfmt='rs', basefmt='r-')
plt.title("Analog to digital signal conversion")
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")
plt.show()

OUTPUT :

You might also like