#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 23 15:02:00 2023

@author: julie
"""
import matplotlib.pyplot as plt
import numpy as np

S0 = 1  # Amplitude 
f0 = 1
omega0 = 2*np.pi*f0  # Pulsation de fréquence centrale ou moyenne
T0 = 2*np.pi/omega0  # Période moyenne du signal
Deltaomega=omega0/10
omegamax = omega0+ Deltaomega/2
omegamin=omega0-Deltaomega/2

' Définition des spectres '

sigma=Deltaomega/2.35

def spectreGauss(omega) :
    y = np.exp(-(omega-omega0)**2/(2*(sigma)**2))
    return y

def spectrePorte(omega) :
    if omega <= omegamax and omega >= omegamin :
        u= 1
    else :
        u = 0
    return u

tau = 8*T0
def spectreSinc(omega) :
    u = np.sin((omega-omega0)*tau)/((omega-omega0)*tau)
    return u


'Tracé des spectres '
k=1000
x=np.linspace(omega0-2*Deltaomega,omega0+2*Deltaomega,k)
yG = spectreGauss(x)
yP = np.zeros(k)
yS = spectreSinc(x)

for i in range (len(yP)) :
    yP[i] = spectrePorte(x[i])

plt.plot(x,yG)
plt.plot(x,yP)
plt.plot(x,yS)
plt.grid()
plt.show()


' Tracé ses signaux s '
N1 = 500 # nombre de composantes
NT = 5001

sG = np.zeros(NT)
tp = np.linspace(-10*T0,20*T0,NT)

def sporte(t):
    dom= Deltaomega/(N1-1)
    print(dom)
    u=0
    for j in range (N1) :
        u = u + 1/N1*spectrePorte(omegamin+j*dom)*np.cos((omegamin+j*dom)*t)
    return u

NG= 3*N1
omegaminG = omega0 - 3*Deltaomega/2
omegamaxG = omega0 + 3*Deltaomega/2
domegaG = 3*Deltaomega/(NG-1)

def sgauss(t) : 
    u=0
    for j in range (NG) :
        u = u + 3.5/NG*spectreGauss(omegaminG+j*domegaG)*np.cos((omegaminG+j*domegaG)*t)
    return u

NC= 3*N1
omegaminC = omega0 - 3*Deltaomega/2
omegamaxC = omega0 + 3*Deltaomega/2
domegaC = 3*Deltaomega/(NC-1)

def ssinC(t) :
    u=0
    for j in range (NG) :
        u = u + 4.5/NG*spectreSinc(omegaminC+j*domegaC)*np.cos((omegaminC+j*domegaC)*t)
    return u    

' Tracé ses signaux s ' 

sP = sporte(tp)
sS = ssinC(tp)
sG = sgauss(tp) 

plt.plot(tp,sG)
plt.plot(tp,sP + 3)
plt.plot(tp,sS+6)
plt.grid()
plt.show()
