Rowan-Classes/7th-Semester-Fall-2024/ECOMMS/homework/homework-5/problem-1.py
2025-01-15 17:59:04 -05:00

31 lines
731 B
Python

import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
def laplacian_distribution(n_0, std_dev):
return np.exp(-np.sqrt(2)*np.abs(n_0)/std_dev) / (np.sqrt(2)*std_dev)
def main():
r_0 = np.linspace(-5,5,1000)
A = 1
std_dev = 1
low_dist = laplacian_distribution(r_0 - A, std_dev)
up_dist = laplacian_distribution(r_0 + A, std_dev)
plt.plot(r_0, low_dist, label="$s_1$")
plt.plot(r_0, up_dist, label="$s_2$")
P_error = (up_dist + low_dist - np.abs(up_dist-low_dist))/2
plt.fill_between(r_0, P_error, color=(0,0,0,0), hatch="//", edgecolor='k', label="$P_e$")
plt.legend()
plt.savefig("Probability of error")
plt.show()
if __name__ == "__main__":
main()