IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Calcul scientifique Python Discussion :

Obtenir signal créneau "pas à pas" [Python 3.X]


Sujet :

Calcul scientifique Python

  1. #1
    Membre éprouvé

    Homme Profil pro
    Technicien
    Inscrit en
    Août 2013
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2013
    Messages : 437
    Points : 1 190
    Points
    1 190
    Par défaut Obtenir signal créneau "pas à pas"
    Bonjour,

    Je cherche à "remonter" à un signal créneau en ajoutant successivement les signaux sinusoidaux de fréquence impair, sans passer par la TRF inverse !

    J'ai tenté ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    # Fonction de définition du signal
    def Signal(t,n):
        An=1/n
        fn=n*5.
        K = 2.*pi    
        s=An*sin(K*fn*t) 
        return s
     
     
    # définition du signal à traiter
    Fe = 400
    Te = 1./Fe
    # définition du vecteur temps
    t0 = 0.
    tmax = 0.5
    t = arange(t0,tmax,Te)
     
     
    # calcul du signal
    for n in range(1,10,2):
        s = s+Signal(t,n)
    Mais le résultat est loin de ce que j'attends. J'imagine que le problème est tout bête mais à force de lire et relire, je n'arrive pas à trouver mon erreur.
    Merci
    [Nouveau] Envie de tracer des circuits électriques : essayez le package LaTeX CircuiTikZ

    Pour créer une belle table des matières sur LibreOffice - N'oubliez pas de consulter les FAQ en cas de question !

    Envie de se lancer dans l'aventure Arduino : allez faire un tour sur ce cours.


    Ma réponse vous a plu ? Un petit vote serait sympa

  2. #2
    Membre chevronné
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2013
    Messages
    1 608
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2013
    Messages : 1 608
    Points : 2 072
    Points
    2 072
    Par défaut
    Un truc comme cela ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    import matplotlib.pyplot as plt
    import numpy as np
     
    Umax=1;omega=1
     
    def Carre(nmax):
    	 t=np.linspace(0,5*np.pi/omega,100)
    	 tmp_carre=np.zeros(100)
    	 for n in range(0,nmax):
    	 	  tmp_carre=tmp_carre+np.sin((2*n +1)* omega*t)/(2 *n +1)
    	 scale_carre=[4*Umax/np.pi]*100
    	 tmp_carre=scale_carre*tmp_carre
    	 plt.plot(t,tmp_carre)
     
    def Triangle(nmax):
    	 t=np.linspace(0,5*np.pi/omega,100)
    	 tmp_triangle=np.zeros(100)
    	 for n in range(0,nmax):
    	 	 tmp_triangle=tmp_triangle+np.cos((2*n +1)* omega*t)/((2 *n +1)*(2*n+1))
    	 scale_triangle=[4*Umax/np.pi]*100
    	 tmp_triangle=scale_triangle*tmp_triangle
    	 plt.plot(t,tmp_triangle)
     
    plt.figure()
    for i in range(0,5):
    	 Triangle(i)
    plt.show()
     
    plt.figure()
    for i in range(0,5):
    	 Carre(i)
    plt.show()
    Pas d'aide par mp.

  3. #3
    Membre chevronné
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2013
    Messages
    1 608
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2013
    Messages : 1 608
    Points : 2 072
    Points
    2 072
    Par défaut
    ou plus élaboré :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    # -*- coding: utf-8 -*-
    """
    Created on Mon Oct 16 11:19:15 2017
     
    @author: marco3
    """
     
    import numpy as np
    import tkinter as tk
    import matplotlib
    matplotlib.use('TkAgg')
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
    from matplotlib.figure import Figure
    from tkinter.constants import TOP, BOTH, BOTTOM, LEFT, RIGHT
     
    Umax=1
    omega=1
    nb_val=500
    t=np.linspace(0,4*np.pi/omega,nb_val)
     
    def carre(nb_harm):
        tmp_carre=np.zeros(nb_val)
        for n in range(0,nb_harm):
            tmp_carre=tmp_carre+np.sin((2*n+1)*omega*t)/(2 *n +1)
        scale_carre=[4*Umax/np.pi]*nb_val
        tmp_carre=scale_carre*tmp_carre
        return tmp_carre
     
    def triangle(nb_harm):
        tmp_triangle=np.zeros(nb_val)
        for n in range(0,nb_harm):
            tmp_triangle=tmp_triangle+np.cos((2*n+1)*omega*t)/((2*n+1)*(2*n+1))
        scale_triangle=[4*Umax/np.pi]*nb_val
        tmp_triangle=scale_triangle*tmp_triangle
        return tmp_triangle
     
    def scie(nb_harm):
        tmp_scie=np.zeros(nb_val)
        for n in range(1,nb_harm):
            tmp_scie=tmp_scie+np.sin(2*n*omega*t)/(n)
        scale_scie=[-2*Umax/np.pi]*nb_val
        tmp_scie=scale_scie*tmp_scie
        return tmp_scie
     
    def arche(nb_harm):
        tmp_arche=np.zeros(nb_val)
        for n in range(1,nb_harm):
            tmp_arche=tmp_arche+np.cos(2*n*omega*t)/(n)
        scale_arche=[-2*Umax/np.pi]*nb_val
        tmp_arche=1+scale_arche*tmp_arche
        return tmp_arche
     
    def mono(nb_harm):
        tmp_mono=np.zeros(nb_val)
        for n in range(1,nb_harm):
            tmp_mono=tmp_mono+np.cos(2*n*omega*t)/(4*n**2-1)
        scale_mono=-(2/np.pi)
        tmp_mono=(1/np.pi)+(0.5*np.sin(omega*t))+scale_mono*tmp_mono
        return tmp_mono
     
    def double(nb_harm):
        tmp_double=np.zeros(nb_val)
        for n in range(1,nb_harm):
            tmp_double=tmp_double+np.cos(2*n*omega*t)/(4*n**2-1)
        scale_double=-(4/np.pi)
        tmp_double=(2/np.pi)+scale_double*tmp_double
        return tmp_double
     
    def essai(nb_harm):
        tmp_arche=np.zeros(nb_val)
        for n in range(1,nb_harm):
            tmp_arche=tmp_arche+np.cos(2*n*omega*t)/(n)
        scale_arche=[-2*Umax/np.pi]*nb_val
        tmp_arche=scale_arche*tmp_arche
        return tmp_arche
     
    def figure_hide(figure):
        figure.canvas.get_tk_widget().pack_forget()
     
    def figure_raz(figure):
        axe = figure.axes[0]
        axe.clear()    
        figure.canvas.draw()
     
    def figure_show(figure):
        figure.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
     
    def plot_carre(nb_harm):
        nb_harm = val_harm.get()
        a.plot(carre(nb_harm))
        canvas.draw()
     
    def plot_triangle(nb_harm):
        nb_harm = val_harm.get()
        a.plot(triangle(nb_harm))
        canvas.draw()
     
    def plot_scie(nb_harm):
        nb_harm = val_harm.get()
        a.plot(scie(nb_harm))
        canvas.draw()
     
    def plot_arche(nb_harm):
        nb_harm = val_harm.get()
        a.plot(arche(nb_harm))
        canvas.draw()
     
    def plot_mono(nb_harm):
        nb_harm = val_harm.get()
        a.plot(mono(nb_harm))
        canvas.draw()
     
    def plot_double(nb_harm):
        nb_harm = val_harm.get()
        a.plot(double(nb_harm))
        canvas.draw()
     
    def plot_essai(nb_harm):
        nb_harm = val_harm.get()
        a.plot(essai(nb_harm))
        canvas.draw()
     
    def quitter():
        root.quit()
        root.destroy()
     
    def get_nb(val):
        global nb_harm
        nb_harm = val.get()
     
    root = tk.Tk()
    root.wm_title("Recomposition de Fourier")
     
    frame = tk.Frame(root)
    figure = Figure(figsize=(8,3), dpi=100)
    a = figure.add_subplot(111)
     
    canvas = FigureCanvasTkAgg(figure, master=root)
    #zone = canvas.get_tk_widget()
    #zone.pack(side=tk.TOP, fill=BOTH, expand=1)
    toolbar = NavigationToolbar2Tk(canvas, root)
    toolbar.update()
    canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)
     
    button1=tk.Button(frame,text='Carré',command=lambda: plot_carre(val_harm))
    button1.pack(side=LEFT)
    button2=tk.Button(frame,text='Triangle',command=lambda: plot_triangle(val_harm))
    button2.pack(side=LEFT)
    button3=tk.Button(frame,text='Scie',command=lambda: plot_scie(val_harm))
    button3.pack(side=LEFT)
    button4=tk.Button(frame,text='Arche',command=lambda: plot_arche(val_harm))
    button4.pack(side=LEFT)
    button5=tk.Button(frame,text='Mono',command=lambda: plot_mono(val_harm))
    button5.pack(side=LEFT)
    button6=tk.Button(frame,text='Double',command=lambda: plot_double(val_harm))
    button6.pack(side=LEFT)
    button7=tk.Button(frame,text='Essai',command=lambda: plot_essai(val_harm))
    button7.pack(side=LEFT)
     
    button10=tk.Button(frame, text='Raz', command=lambda f=figure: figure_raz(f))
    button10.pack(side=LEFT)
    button11=tk.Button(frame, text='Hide', command=lambda f=figure: figure_hide(f))
    button11.pack(side=LEFT)
    tk.Button(frame, text='show', command=lambda f=figure: figure_show(f)).pack(side=LEFT)
     
     
    harmo=tk.Label(frame, text="Harmoniques")
    harmo.pack(side=BOTTOM)
    val_harm = tk.IntVar() # On definit val_harm
    val_harm.set(1)        # On donne la valeur que prendra le curseur au départ
     
    # Création d'un widget Curseur
    echelle_harm = tk.Scale(frame,length=200, orient=tk.HORIZONTAL, troughcolor ='LightYellow2', \
    sliderlength =30, showvalue=1,from_=1,to=30, resolution=1, tickinterval=6, \
    variable = val_harm, command = get_nb(val_harm)) # width=10
    echelle_harm.set(0),
    echelle_harm.pack(side=BOTTOM)
     
    button20=tk.Button(frame, text='Quit',command=quitter)
    button20.pack(side=RIGHT)
     
    frame.pack(side=BOTTOM)
    tk.mainloop()
    Pas d'aide par mp.

  4. #4
    Membre éprouvé

    Homme Profil pro
    Technicien
    Inscrit en
    Août 2013
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Technicien
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2013
    Messages : 437
    Points : 1 190
    Points
    1 190
    Par défaut
    Bonsoir,

    Merci pour ce partage : effectivement, le 2ème est bien plus élaboré, c'est du chouette programme tout ça !

    Merci encore.
    [Nouveau] Envie de tracer des circuits électriques : essayez le package LaTeX CircuiTikZ

    Pour créer une belle table des matières sur LibreOffice - N'oubliez pas de consulter les FAQ en cas de question !

    Envie de se lancer dans l'aventure Arduino : allez faire un tour sur ce cours.


    Ma réponse vous a plu ? Un petit vote serait sympa

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Rate limiter, signal carré et pas variable
    Par JohnND dans le forum Simulink
    Réponses: 3
    Dernier message: 06/08/2014, 09h54
  2. signal ne passe pas
    Par patricx dans le forum POSIX
    Réponses: 2
    Dernier message: 18/10/2011, 22h50
  3. creer un signal créneau
    Par KolAr dans le forum Signal
    Réponses: 2
    Dernier message: 19/08/2009, 04h56
  4. ne peut pas simplement "aXSLProc.Process(aCursor);"
    Par didier.cabale dans le forum XMLRAD
    Réponses: 16
    Dernier message: 08/03/2006, 12h25
  5. Man signal, man scanf => pas de manuel
    Par weed dans le forum Applications et environnements graphiques
    Réponses: 6
    Dernier message: 17/05/2004, 16h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo