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)