# -*- coding: utf-8 -*-
"""
DÉVELOPPEMENT DE FOURIER D'UN SIGNAL CRÉNEAU
"""

import numpy as np
import matplotlib.pyplot as plt
plt.close('all')

# Paramètres du signal
T = 1   # unité arbitraire
w = 2 * np.pi / T # pulsation
t = np.linspace(-T, T, 10000)  # temps

E = 1  # amplitude du signal

N = 3  # nombre de termes de la série de Fourier
y = E/2 * np.ones_like(t)  # initialisation du signal reconstitué

for p in range(20,500):
    y += (2 * E / (np.pi * (2*p + 1))) * np.sin((2*p + 1) * w * t)

plt.figure()
plt.plot(t,y)
plt.xlabel('t (période unité)')
plt.ylabel('y(t)')
plt.grid()
plt.xlim([-1,1])
