Create a Fourier series model and optimize

Suppose I have the following function:
Here x is the input, and a_i and omega are the parameters (so there are n+2 parameters in total).

Let’s say n = 10. I want to find the best parameters that will fit the training dataset (y_i, f(x_i)). I know how to optimize neural networks, but I have no idea how to apply Adam for this function.

How to create such a model? Could you please help?