i have a function that is defined as p(t) =sin(t/k) from 0<t<2pik and p(t)=0 from 2pik<t<T. And i have to approximate how many fourier coefficients i have to use to get a reasnoble result. Don´t know how to plot the fourier series but the first bit to get the fourier coefficients seems to work. Please give me tips.
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
import sympy as smp
from scipy.integrate import quad
#the function
def x(t, k):
return np.sin(t/k)
#getting the fourier coefficients
def get_x_FT(x, n, k, T):
x_FT_integrand_real = lambda t: np.real(x(t, k)*np.exp(-2*np.pi*1j*(n/T)*t))
x_FT_integrand_comp = lambda t: np.imag(x(t, k)*np.exp(-2*np.pi*1j*(n/T)*t))
x_FT_real = quad(x_FT_integrand_real, 0, 2*np.pi*T/30)[0]
x_FT_comp = quad(x_FT_integrand_comp, 0, 2*np.pi*T/30)[0]
return x_FT_real + 1j*x_FT_comp
#multiplying coefficients by explonential to get functions
def f(x, N,T):
f = np.array([2*get_x_FT(i)*np.exp(1j*2*i*np.pi*x/T) for i in range(-N,N+1)])
return f.sum()