Pretty much all of Fall 2024

This commit is contained in:
Aidan Sharpe
2024-11-10 14:46:30 -05:00
parent 87f9c55360
commit faa05b88f9
116 changed files with 8295 additions and 1683 deletions

View File

@ -0,0 +1,56 @@
# ECOMMS Homework 2 - Aidan Sharpe
## Problem 1
```python
import numpy as np
f_c = 1250
f_m = 125
A_c = 10
a = 1
def g(t):
return A_c * (1 + a*(0.2*np.cos(2*np.pi*f_m*t) + 0.5*np.sin(2*np.pi*f_c*t)))
# First derivative of g(t)
def dg_dt(t):
return -0.2*2*f_m*np.pi*A_c*a*np.sin(2*np.pi*f_m*t) \
+ 2*np.pi*0.5*f_c*A_c*np.cos(2*np.pi*f_c*t)
# Second derivative of g(t)
def ddg_dtt(t):
return -0.2*(2*np.pi*f_m)**2*A_c*a*np.cos(2*np.pi*f_m*t) \
- 0.5*(2*np.pi*f_c)**2*A_c*a*np.sin(2*np.pi*f_c*t)
# Use Newton's method to find the maximum of the function
def newton_method(t):
for i in range(10):
t = t - dg_dt(t)/ddg_dtt(t)
print("Newton method:", t, np.max(g(t)))
return np.max(g(t))
def dc_dt(t):
return A_c*a*np.pi*f_c*np.cos(2*np.pi*f_c*t)
# Sample g(t) at the maxima and minima of the carrier signal
def sample_method():
samples = f_c / f_m
n = np.arange(samples)
t = (2*n + 1) / (4*f_c)
t = t[np.argmax(g(t))]
print("Sampling method:", t, g(t))
return t
if __name__ == '__main__':
t_max = sample_method()
A_max = newton_method(t_max)
a_coeff = (A_max - A_c) / A_c
print("Value of a where positive modulation is 90%:", 0.9/a_coeff)
```
### Sampling Method
$t_max = 0.0002$, $g_max = 16.9754$
### Newton Method
$t_max = 0.000199206$, $g_max = 16.9755$
Positive modulation is 90% when $a=1.2902$

View File

@ -0,0 +1,42 @@
import numpy as np
f_c = 1250
f_m = 125
A_c = 10
a = 1
def g(t):
return A_c * (1 + a*(0.2*np.cos(2*np.pi*f_m*t) + 0.5*np.sin(2*np.pi*f_c*t)))
# first derivative of g(t)
def dg_dt(t):
return -0.2*2*f_m*np.pi*A_c*a*np.sin(2*np.pi*f_m*t) + 2*np.pi*0.5*f_c*A_c*np.cos(2*np.pi*f_c*t)
# second derivative of g(t)
def ddg_dtt(t):
return -0.2*(2*np.pi*f_m)**2*A_c*a*np.cos(2*np.pi*f_m*t) - 0.5*(2*np.pi*f_c)**2*A_c*a*np.sin(2*np.pi*f_c*t)
# use Newton's method to find the maximum of the function
def newton_method(t):
for i in range(10):
t = t - dg_dt(t)/ddg_dtt(t)
print("Newton method:", t, np.max(g(t)))
return np.max(g(t))
def dc_dt(t):
return A_c*a*np.pi*f_c*np.cos(2*np.pi*f_c*t)
# Sample g(t) at the maxima and minima of the carrier signal
def sample_method():
samples = f_c / f_m
n = np.arange(samples)
t = (2*n + 1) / (4*f_c)
t = t[np.argmax(g(t))]
print("Sampling method:", t, g(t))
return t
if __name__ == '__main__':
t_max = sample_method()
A_max = newton_method(t_max)
a_coeff = (A_max - A_c) / A_c
print("Value of a where positive modulation is 90%:", 0.9/a_coeff)

View File

@ -0,0 +1,33 @@
import numpy as np
f_m = 0.2
f_c = 2*f_m
A_c = 1
a = 1
def g(t):
return A_c*np.cos(2*np.pi*f_m*t) + A_c*np.cos(2*np.pi*f_c*t)
# first derivative of g(t)
def dg_dt(t):
return -(2*np.pi*f_m)*A_c*np.sin(2*np.pi*f_m*t) + -(2*np.pi*f_c)*A_c*np.sin(2*np.pi*f_c*t)
# second derivative of g(t)
def ddg_dtt(t):
return -(2*np.pi*f_m)**2*A_c*np.cos(2*np.pi*f_m*t) + -(2*np.pi*f_c)**2*A_c*np.cos(2*np.pi*f_c*t)
# use Newton's method to find the maximum of the function
def newton_method(t):
for i in range(3):
t = t - dg_dt(t)/ddg_dtt(t)
print(f"Iteration {i+1}: {t}\t{g(t)}")
def dc_dt(t):
return A_c*a*np.pi*f_c*np.cos(2*np.pi*f_c*t)
if __name__ == '__main__':
T_c = 1/f_c
t_min = T_c/2
newton_method(t_min)
newton_method(0)

View File

@ -0,0 +1,24 @@
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
f_c = 1
f_m = f_c/4
omega_m = 2*np.pi*f_m
omega_c = 2*np.pi*f_c
T_c = f_c
t = np.arange(0,10,T_c/10)
m = np.cos(omega_m * t)
plt.plot(t, m)
plt.show()
D_p = np.pi
D_f = np.pi
S_p = np.cos(omega_c + D_p*m)
plt.plot(t,S_p)
plt.show()

View File

@ -0,0 +1,26 @@
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
# Modulation index
beta = 2.0
# Number of impulses is 2*(beta+1) + 1.
# For beta=2, the number of impulses is 3 either side of the center frequency
# plus 1 for the center frequency, for a total of 7 impulses.
# Message frequency
f_m = 15E+3
# Transmission bandwidth
B_T = 2*(beta+1)*f_m
n = np.arange(0,10,1)
bessel_values = sp.special.jv(n,beta)
bessel_power = np.cumsum(bessel_values)
plt.stem(n, bessel_values)
plt.plot(n, bessel_power)
plt.hlines(0.98*bessel_power[-1], xmin=n[0], xmax=n[-1])
plt.show()
#