Pretty much all of Fall 2024
This commit is contained in:
51
7th-Semester-Fall-2024/ECOMMS/exams/exam-1/problem-1.py
Normal file
51
7th-Semester-Fall-2024/ECOMMS/exams/exam-1/problem-1.py
Normal file
@ -0,0 +1,51 @@
|
||||
import numpy as np
|
||||
|
||||
f_1 = 5
|
||||
f_2 = 5E3
|
||||
omega_1 = 2*np.pi*f_1
|
||||
omega_2 = 2*np.pi*f_2
|
||||
|
||||
A_c = 10
|
||||
a = 1
|
||||
|
||||
def m(t):
|
||||
return 0.2*np.cos(omega_1*t) + 0.8*np.cos(omega_2*t)
|
||||
|
||||
def dm_dt(t):
|
||||
return -0.2*omega_1*np.sin(omega_1*t) - 0.8*omega_2*np.sin(omega_2*t)
|
||||
|
||||
def ddm_dtt(t):
|
||||
return -0.2*omega_1**2*np.cos(omega_1*t) - 0.8*omega_2**2*np.cos(omega_2*t)
|
||||
|
||||
def g(t):
|
||||
return A_c + A_c*m(t)
|
||||
|
||||
# first derivative of g(t)
|
||||
def dg_dt(t):
|
||||
return A_c*dm_dt(t)
|
||||
|
||||
# second derivative of g(t)
|
||||
def ddg_dtt(t):
|
||||
return A_c**2*ddm_dtt(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.min(m(t)))
|
||||
return np.min(g(t))
|
||||
|
||||
# Sample g(t) at the maxima and minima of the carrier signal
|
||||
def sample_method():
|
||||
f_s = 4*max(f_1, f_2)
|
||||
T_s = 1/f_s
|
||||
T_0 = 1/min(f_1, f_2)
|
||||
|
||||
t = np.arange(0,T_0,T_s)
|
||||
|
||||
t = t[np.argmin(m(t))]
|
||||
print("Sampling method:", t, m(t))
|
||||
return t
|
||||
|
||||
if __name__ == '__main__':
|
||||
newton_method(0.1)
|
37
7th-Semester-Fall-2024/ECOMMS/exams/exam-1/problem-2.py
Normal file
37
7th-Semester-Fall-2024/ECOMMS/exams/exam-1/problem-2.py
Normal file
@ -0,0 +1,37 @@
|
||||
import numpy as np
|
||||
import scipy as sp
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
A_c = 1
|
||||
|
||||
f_1 = 500
|
||||
T_1 = 1/f_1
|
||||
omega_1 = 2*np.pi*f_1
|
||||
|
||||
f_c = 20000
|
||||
T_c = 1/f_c
|
||||
omega_c = 2*np.pi*f_c
|
||||
|
||||
def m(t):
|
||||
return 2*np.cos(2*omega_1*t) + 3*np.cos(3*omega_1*t)
|
||||
|
||||
def s(t):
|
||||
return A_c*m(t)*np.cos(omega_c*t)
|
||||
|
||||
f_s = 40*f_c
|
||||
T_s = 1/f_s
|
||||
t = np.arange(0,T_1,T_s)
|
||||
|
||||
plt.plot(t,s(t))
|
||||
plt.plot(t,m(t))
|
||||
plt.show()
|
||||
|
||||
S = sp.fft.fft(s(t))[35:45]
|
||||
f = t*f_s/T_1
|
||||
f = f[35:45]
|
||||
for i in range(len(f)):
|
||||
print(f[i], S[i].real)
|
||||
|
||||
plt.stem(f,S.real/1600)
|
||||
plt.show()
|
||||
|
Reference in New Issue
Block a user