# -*- coding: utf-8 -*-
"""
Created on Tue Sep 23 16:06:32 2025

@author: erwan
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

#Variable
f_e = 20e3 #Hz fréquence d'échantillonnage


#Paramètres
T_e = 1/f_e
f = 10e3 #Hz fréquence du signal à numériser
t = np.linspace(0,7/f,1000) #s vecteurs instants 
s = np.cos(2*np.pi*f*t) #V signal "analogique"

nombre_échantillons = int(t[-1]*f_e)
t_échantillon = np.zeros(nombre_échantillons)
s_échantillon = np.zeros(nombre_échantillons)

for k in range(nombre_échantillons):
    t_échantillon[k] = T_e*k
    s_échantillon[k] = np.cos(2*np.pi*f*(T_e*k))

def ajustement(t, f_e, f):
    if f < f_e/2:
        s = np.cos(2*np.pi*f*t)
    else:
        s = np.cos(2*np.pi*(f_e - f)*t)
    return s

s_ajustée = ajustement(t, f_e, f)

figure_1, axes = plt.subplots(1)
axes.plot(t, s, label='signal', linewidth=6)
axes.plot(t_échantillon, s_échantillon,'ro', label='échantillonnage')
axes.plot(t, s_ajustée,'--r')
axes.set(ylabel='Signal $s$ (V)')
axes.set(xlabel='Instants $t$ (s)')
axes.set_title('$f_e$  = {:.2e} Hz'.format(f_e) )
axes.legend()
axes.grid()
plt.show()