import numpy as np
import matplotlib.pyplot as plt

def main():
    # Parameters
    samples = 512
    x = np.linspace(-2, 2, samples)
    # Generate a sinc wave
    sinc_wave = np.sinc(x)
    # Normalize to 16-bit range
    sinc_wave = sinc_wave / np.max(np.abs(sinc_wave)) * 32767
    imaginary_part = np.zeros(samples)
    # Save to a file
    with open('sinc_wave.bin', 'wb') as f:
        for i in range(samples):
            f.write(np.int16(sinc_wave[i]).tobytes())
            f.write(np.int16(imaginary_part[i]).tobytes())

    data = b''
    with open('sinc_wave.bin', 'rb') as f:
        data = f.read()
    
    print(len(data))
    wave_q = np.array([], dtype=np.int16)
    wave_i = np.array([], dtype=np.int16)

    for i in range(len(data) // 4):
        wave_q = np.append(wave_q, np.frombuffer(data, dtype=np.int16, count=1, offset=4*i))
        wave_i = np.append(wave_i, np.frombuffer(data, dtype=np.int16, count=1, offset=4*i+2))

    plt.plot(x, wave_q)
    plt.plot(x, wave_i)
    plt.show()

if __name__ == "__main__":
    main()

