import numpy as np
import matplotlib.pyplot as plt

def accz_wave(T=100, A=0.8, P=0.16, omega_d=100e6, theta=0, a2=0.1, phi=0, sample_rate=1e9, plot=False):
    N = int(T / (1/sample_rate * 1e9))
    A_scaled = A * 2**15
    t = np.linspace(0, N, N)
    env = A_scaled/(np.sqrt(1 + P**2)) * (np.sin(np.pi * t / N) + P * np.sin(3*np.pi * t / N))
    f = env * (np.cos(omega_d * t + theta) + a2 * np.cos(2*omega_d*t + 2*theta + phi))
    fint16 = np.int16(f)
    if plot:
        plt.figure()
        plt.plot(t, env)
        plt.show()
    return env

# 示例：外部调用
# env = accz_wave(T=200, A=1.0, plot=True)
# print(env)