diff --git a/Day 7 Homework.md b/Day 7 Homework.md index 461d6a1..c5fc226 100644 --- a/Day 7 Homework.md +++ b/Day 7 Homework.md @@ -50,6 +50,53 @@ From the histogram shown above, we can say that jitter is expected to be more fl ![Jitter & Duration relationship](https://gogs.gtsplab.com:5432/j/python-bootcamp/src/Branch_Karen/jitter%20relationship.png) +``` +import numpy as np + +# Durations to measure in seconds +durations = [0.01, 0.1, 1.0] + +# Number of repetitions +num_repetitions = 100 + +# Lists to store jitter and duration for each measurement +jitter = [] +duration = [] + +# Function to measure jitter +def measure_jitter(duration): + start_time = time.perf_counter_ns() + time.sleep(duration) + end_time = time.perf_counter_ns() + return end_time - start_time + +# Measure jitter for each duration and repeat for num_repetitions times +for dur in durations: + for _ in range(num_repetitions): + jitter.append(measure_jitter(dur)) + duration.append(dur) + +# Convert lists to NumPy arrays +jitter = np.array(jitter) +duration = np.array(duration) + +# Fit a polynomial curve of degree 2 +coeffs = np.polyfit(duration, jitter, 2) +poly_func = np.poly1d(coeffs) + +# Generate data points for the curve +duration_range = np.linspace(min(duration), max(duration), 100) +jitter_fit = poly_func(duration_range) + +# Plot the measured data points and the polynomial curve +plt.scatter(duration, jitter, color='b', alpha=0.5, label='Measured Data') +plt.plot(duration_range, jitter_fit, color='r', label='Polynomial Fit (Degree 2)') +plt.xlabel('Sleep Duration (s)') +plt.ylabel('Jitter (ns)') +plt.title('Polynomial Relationship between Sleep Duration and Jitter') +plt.legend() +plt.show() +``` **2. Create a dict with 1 million integer keys, each with 64 bytes of random values.**