MGM657 Outils Numériques pour l Ingénieur



Documents pareils
TD1 Signaux, énergie et puissance, signaux aléatoires

INTRODUCTION A L ELECTRONIQUE NUMERIQUE ECHANTILLONNAGE ET QUANTIFICATION I. ARCHITECTURE DE L ELECRONIQUE NUMERIQUE

Cours 7 : Utilisation de modules sous python

Traitement du signal avec Scilab : la transformée de Fourier discrète

M1107 : Initiation à la mesure du signal. T_MesSig

LABO PROJET : IMPLEMENTATION D UN MODEM ADSL SOUS MATLAB

Python - introduction à la programmation et calcul scientifique

SUJET ZÉRO Epreuve d'informatique et modélisation de systèmes physiques

Chapitre 1 Régime transitoire dans les systèmes physiques

Oscillations libres des systèmes à deux degrés de liberté

Amphi 3: Espaces complets - Applications linéaires continues

Exercices types Algorithmique et simulation numérique Oral Mathématiques et algorithmique Banque PT

Correction de l examen de la première session

Projet de Traitement du Signal Segmentation d images SAR


Introduction. Mathématiques Quantiques Discrètes

3 Approximation de solutions d équations

Chapitre I La fonction transmission

Continuité et dérivabilité d une fonction

Donner les limites de validité de la relation obtenue.

TP 7 : oscillateur de torsion

1.1.1 Signaux à variation temporelle continue-discrète

SYSTEMES LINEAIRES DU PREMIER ORDRE

Précision d un résultat et calculs d incertitudes

La fonction exponentielle

Exercices - Polynômes : corrigé. Opérations sur les polynômes

Compatibilité Électromagnétique

BTS Groupement A. Mathématiques Session Spécialités CIRA, IRIS, Systèmes électroniques, TPIL

CHAPITRE V. Théorie de l échantillonnage et de la quantification

5. Analyse des signaux non périodiques

Systèmes de transmission

Communication parlée L2F01 TD 7 Phonétique acoustique (1) Jiayin GAO <jiayin.gao@univ-paris3.fr> 20 mars 2014

Chapitre 2 Le problème de l unicité des solutions

FAG Detector II le collecteur et l analyseur de données portatif. Information Technique Produit

Cours de Mécanique du point matériel

Chapitre 3. Mesures stationnaires. et théorèmes de convergence

Calcul Formel et Numérique, Partie I

I. Polynômes de Tchebychev

LE PRODUIT SCALAIRE ( En première S )

Capes Première épreuve

CHAPITRE V SYSTEMES DIFFERENTIELS LINEAIRES A COEFFICIENTS CONSTANTS DU PREMIER ORDRE. EQUATIONS DIFFERENTIELLES.

Initiation à la programmation en Python

Intérêt du découpage en sous-bandes pour l analyse spectrale

Quantification Scalaire et Prédictive

TP Modulation Démodulation BPSK

Champ électromagnétique?

Licence Professionnelle de Génie Industriel Université Paris VI-Jussieu ; CFA Mecavenir Année Cours de Génie Electrique G.

TP 1. Prise en main du langage Python

Chapitre 2 Les ondes progressives périodiques

Calcul Scientifique avec 3

10ème Congrès Français d'acoustique Lyon, Avril 2010

P1PY7204 Acquisition de données Cours

LES CARACTERISTIQUES DES SUPPORTS DE TRANSMISSION

Exercices - Nombres complexes : corrigé. Formes algébriques et trigonométriques, module et argument

Exercice 1. Exercice n 1 : Déséquilibre mécanique

Echantillonnage Non uniforme

Transmission d informations sur le réseau électrique

FAG Detector III la solution pour la surveillance et l équilibrage. Information Technique Produit

Son et Mathématiques

L informatique en BCPST

Simulation de variables aléatoires

Notions d asservissements et de Régulations

1 Complément sur la projection du nuage des individus

Texte Agrégation limitée par diffusion interne

Introduction à l approche bootstrap

8563A. SPECTRUM ANALYZER 9 khz GHz ANALYSEUR DE SPECTRE

Commun à tous les candidats

SIGNAUX NUMERIQUES ET MODULATIONS NUMERIQUES

Rappels sur les suites - Algorithme

Statistiques Descriptives à une dimension

Méthodes de quadrature. Polytech Paris-UPMC. - p. 1/48

aux différences est appelé équation aux différences d ordre n en forme normale.

STATIQUE GRAPHIQUE ET STATIQUE ANALYTIQUE

Chapitre 6. Fonction réelle d une variable réelle

Equipement. électronique

Signaux numériques : Multiplexage temporel : TDM

ÉVALUATION FORMATIVE. On considère le circuit électrique RC représenté ci-dessous où R et C sont des constantes strictement positives.

Numérisation du signal

Chaine de transmission

TOUT CE QU IL FAUT SAVOIR POUR LE BREVET

A. N(p) B + C p. + D p2

Chapitre 0 Introduction à la cinématique

5.2 Théorème/Transformée de Fourier a) Théorème

Charges électriques - Courant électrique

UEO11 COURS/TD 1. nombres entiers et réels codés en mémoire centrale. Caractères alphabétiques et caractères spéciaux.

TS 35 Numériser. Activité introductive - Exercice et démarche expérimentale en fin d activité Notions et contenus du programme de Terminale S

Première partie. Préliminaires : noyaux itérés. MPSI B 6 juin 2015

Caractéristiques des ondes

Michel Henry Nicolas Delorme

Recherche De Coalescences Binaires Étalonnage Du Détecteur

Résonance Magnétique Nucléaire : RMN

Exemple d acquisition automatique de mesures sur une maquette de contrôle actif de vibrations

Programmes des classes préparatoires aux Grandes Ecoles

Loi binomiale Lois normales

LABO 5 ET 6 TRAITEMENT DE SIGNAL SOUS SIMULINK

OM 1 Outils mathématiques : fonction de plusieurs variables

Complément d information concernant la fiche de concordance

Dynamique des protéines, simulation moléculaire et physique statistique

Transcription:

Traitement de signal ludovic.charleux@univ-savoie.fr www.polytech.univ-savoie.fr 1 Introduction 2 Notations 3 Outils 4 Signaux 5 Échantillonnage 6

Introduction Plan 1 Introduction 2 Notations 3 Outils 4 Signaux 5 Échantillonnage 6 Outils numériques pour l ingénieur 2/83

Introduction Vibration d une poutre (salle C114) Force, f [N] Acceleration, a [g] 60 50 40 30 20 10 0 10 0 2 4 6 8 0.10 0.12 30 20 10 0 10 20 30 0 2 4 6 Time, t [s] 8 0.10 0.12 Outils numériques pour l ingénieur 3/83

Introduction Vibration d une cloche (salle C114) 0.6 0.4 0.2 Signal x 0.2 0.4 0.6 0 5 0.10 0.15 0.20 0.25 0.30 0.35 0.40 Temps t Outils numériques pour l ingénieur 4/83

Notations Plan 1 Introduction 2 Notations 3 Outils 4 Signaux 5 Échantillonnage 6 Outils numériques pour l ingénieur 5/83

Notations Notations Un signal? Dans ce cours on étudie le comportement d un signal x issu de la mesure d une grandeur physique (vitesse, température,... ). Le signal dépend d une variable unique t qui peut représenter le temps, une position... Signal quelconque D un point de vue mathématique, le signal x(t) défini par : x : t x(t), x [0, t max ] Signal périodique Si x est périodique, on note T sa période et f sa fréquence avec : f = 1 T Outils numériques pour l ingénieur 6/83

Outils Plan 1 Introduction 2 Notations 3 Outils 4 Signaux 5 Échantillonnage 6 Outils numériques pour l ingénieur 7/83

Outils Python, c est quoi? Python, c est quoi? Pourquoi Python? La lourdeur des calculs nécessite des outils numériques. Les signaux expérimentaux sont numérisés et donc aisément traités par ces outils. Python est un langage simple, au spectre d applications vaste. Python est libre et donc gratuit, vous pouvez donc l installer rapidement sur toute machine. Il est présent sur la majorité des distributions de Linux. Pour l installer et lire les documentations : http ://www.python.org/ Modules utilisés : Graphisme : Matplotlib Calcul scientifique : Scipy Calcul numérique : Numpy Outils numériques pour l ingénieur 8/83

Outils Python : comment ça marche? Python : comment ça marche? Outils nécessaires Un éditeur de texte reconnaissant la syntaxe. Un terminal. Exemple On crée un fichier test.py dont le contenu est (voir dossier / listings ) : 1 # l i s t i n g s / t e s t. py 2 p r i n t " H e l l o w o r l d! " On execute Python dans un terminal avec une des commandes suivantes : 1 python t e s t. py Ou : 1 python 2 e x e c f i l e ( t e s t. py ) La seconde solution a l intérêt de ne pas fermer l interpréteur après l exécution ce qui permet de débugger ou de modifier le code plus aisément. Outils numériques pour l ingénieur 9/83

Signaux Plan 1 Introduction 2 Notations 3 Outils 4 Signaux 5 Échantillonnage 6 Outils numériques pour l ingénieur 10/83

Signaux Signal sinusoïdal Signal sinusoïdal (1/3) Définition 1 # s i g n a l _ s i n u s o i d a l. py 2 from math i m p o r t sin, p i 3 # T : p e r i o d e, k : a m p l i t u d e, p h i : d e p h a s a g e 4 d e f s i g n a l _ s i n u s o i d a l ( t, T=1., k =1., p h i =0.) : 5 r e t u r n k s i n (2 p i t /T+p h i ) Fonction de tracé On construit une fonction qui assure le tracé : 1 # t r a c e _ s i g n a l. py 2 i m p o r t m a t p l o t l i b. p y p l o t a s p l t 3 4 d e f t r a c e _ s i g n a l ( t, x, f i c h i e r, x l a b e l= T e m p s $ t $, 5 y l a b e l= S i g n a l $ x $, g r i d=true, s t y l e= r - ) : 6 p l t. f i g u r e ( 0, f i g s i z e =(9,5) ) 7 p l t. c l f ( ) 8 p l t. p l o t ( t, x, s t y l e, l i n e w i d t h =2.0) 9 p l t. x l a b e l ( x l a b e l, f o n t s i z e =15) 10 p l t. y l a b e l ( y l a b e l, f o n t s i z e =15) 11 p l t. g r i d ( g r i d ) 12 p l t. s a v e f i g ( f i c h i e r ) Outils numériques pour l ingénieur 11/83

Signaux Signal sinusoïdal Signal sinusoïdal (2/3) Tracé du signal 1 # l i s t i n g s / exemple1. py 2 # On c h a r g e l a f o n c t i o n s i g n a l _ s i n u s o i d a l 3 from s i g n a l _ s i n u s o i d a l i m p o r t 4 # On c h a r g e l a f o n c t i o n t r a c e _ s i g n a l 5 from t r a c e _ s i g n a l i m p o r t 6 from numpy i m p o r t a r a n g e 7 s i g n a l = s i g n a l _ s i n u s o i d a l # On d e f i n i t l e s i g n a l u t i l i s e 8 T = 1. # P e r i o d e du s i g n a l 9 t_min = 0. # Debut du c a l c u l du s i g n a l 10 t_max = 2. # F i n du c a l c u l du s i g n a l 11 np = 10000 # Nombre de p o i n t s c a l c u l e s 12 # On d e f i n i t l i n t e r v a l de temps a t r a c e r 13 t = a r a n g e ( np ) / f l o a t ( np ) ( t_max t_min )+t_min 14 # F i c h i e r dans l e q u e l t r a c e r 15 f i c h i e r =.. / f i g u r e s / s i n u s o i d e. p d f 16 x = [ s i g n a l ( t t, T=T) f o r t t i n t ] 17 t r a c e _ s i g n a l ( t, x, f i c h i e r ) Outils numériques pour l ingénieur 12/83

Signaux Signal sinusoïdal Signal sinusoïdal (3/3) On obtient le fichier (vectoriel) sinusoide.pdf Signal x 1.5 2.0 Temps t Outils numériques pour l ingénieur 13/83

Signaux Signal carré Signal carré (1/3) Construction de la fonction 1 #l i s t i n g s / s i g n a l _ c a r r e. py 2 from numpy i m p o r t f l o o r 3 # T : p e r i o d e, k : a m p l i t u d e 4 d e f s i g n a l _ c a r r e ( t, T=1., k =1.) : 5 t = t f l o o r ( t /T) 6 x = 1. 7 i f t > T / 2. : x = 1. 8 r e t u r n x Outils numériques pour l ingénieur 14/83

Signaux Signal carré Signal carré (2/3) Tracé du signal 1 # l i s t i n g s / exemple2. py 2 # On c h a r g e l a f o n c t i o n s i g n a l _ c a r r e 3 from s i g n a l _ c a r r e i m p o r t 4 # On c h a r g e l a f o n c t i o n t r a c e _ s i g n a l 5 from t r a c e _ s i g n a l i m p o r t 6 from numpy i m p o r t a r a n g e 7 s i g n a l = s i g n a l _ c a r r e # On d e f i n i t l e s i g n a l u t i l i s e 8 T = 1. # P e r i o d e du s i g n a l 9 t_min = 0. # Debut du c a l c u l du s i g n a l 10 t_max = 2. # F i n du c a l c u l du s i g n a l 11 np = 1000 # Nombre de p o i n t s c a l c u l e s 12 # On d e f i n i t l i n t e r v a l de temps a t r a c e r 13 t = a r a n g e ( np ) / f l o a t ( np ) ( t_max t_min )+t_min 14 f i c h i e r =.. / f i g u r e s / c a r r e. p d f 15 x = [ s i g n a l ( t t, T=T) f o r t t i n t ] 16 t r a c e _ s i g n a l ( t, x, f i c h i e r ) Outils numériques pour l ingénieur 15/83

Signaux Signal carré Signal carré (3/3) On obtient le fichier (vectoriel) carre.pdf Signal x 1.5 2.0 Temps t Outils numériques pour l ingénieur 16/83

Signaux Signal expérimental : mesure d accélération sur une cloche Signal expérimental : mesure d accélération sur une cloche Intérêt Ce signal pseudo périodique est obtenu expérimentalement au moyen d un accéléromètre fixé sur une cloche (visible en salle C114) et excitée par un battant. Il est fourni dans une fichier sérialisé par le module Python Pickle. Tracé 1 # l i s t i n g s / exemple4. py 2 i m p o r t p i c k l e 3 from numpy i m p o r t a r a n g e 4 from t r a c e _ s i g n a l i m p o r t 5 f i c h i e r = open ( c l o c h e. p c k l, r ) # O u v e r t u r e du f i c h i e r 6 c l o c h e = p i c k l e. l o a d ( f i c h i e r ) # Chargement d e s d o n n e e s 7 f i c h i e r. c l o s e ( ) # F e r m e t u r e du f i c h i e r 8 x = c l o c h e [ x ] [ : : 3 2 ] # Redimensionnement d e s d o n n e e s 9 f e = c l o c h e [ fe ] # D e f i n i t i o n de l a f r e q u e n c e d e c h a n t i l l o n a g e 10 t = a r a n g e ( l e n ( x ) ) / f l o a t ( f e ) 11 f i c h i e r =.. / f i g u r e s / c l o c h e. p d f 12 t r a c e _ s i g n a l ( t, x, f i c h i e r ) Outils numériques pour l ingénieur 17/83

Signaux Signal expérimental : mesure d accélération sur une cloche Signal expérimental : mesure d accélération sur une cloche On obtient le fichier (vectoriel) cloche.pdf 0.6 0.4 0.2 Signal x 0.2 0.4 0.6 0 5 0.10 0.15 0.20 0.25 0.30 0.35 0.40 Temps t Outils numériques pour l ingénieur 18/83

Échantillonnage Plan 1 Introduction 2 Notations 3 Outils 4 Signaux 5 Échantillonnage 6 Outils numériques pour l ingénieur 19/83

Échantillonnage Les bases Les bases Principe Échantilloner un signal x consiste à l évaluer sur une grille comportant N points définie par : t n = t min + n f e, n [0, N[ La fréquence f e est la fréquence échantillonnage. La durée d observation du signal notée D est donc obtenue par : D = N/f e Le signal échantillonné est alors obtenu par : x n = x(t n) On note [t n] et [x n] les vecteurs ainsi obtenus. Paramètres importants D T : ajustable en modifiant la durée d observation D f ef : ajustable en modifiant la fréquence d échantillonnage f e. Outils numériques pour l ingénieur 20/83

Échantillonnage Choix de la durée d observation Choix de la durée d observation (1/2) 0.8 f =, f e /f =16.0, D/T =0.3 signal signal echantillone Signal x 0.6 0.4 0.2 0 5 0.10 0.15 0.20 0.25 0.30 Temps d observation D trop court! Temps t Outils numériques pour l ingénieur 21/83

Échantillonnage Choix de la durée d observation Choix de la durée d observations (2/2) f =, f e /f =16.0, D/T =2.0 signal signal echantillone Signal x Conclusion 1.5 2.0 Temps t Il faut que D/T 1 Idéalement, D/T N Outils numériques pour l ingénieur 22/83

Échantillonnage Une borne basse de la fréquence d échantillonage? Une borne basse de la fréquence d échantillonage? f =, f e /f =16.0, D/T =2.0 signal signal echantillone Signal x 1.5 2.0 Échantillonage correct. Temps t Outils numériques pour l ingénieur 23/83

Échantillonnage Une borne basse de la fréquence d échantillonage? Une borne basse de la fréquence d échantillonage? f =, f e /f =4.0, D/T =2.0 signal signal echantillone Signal x 1.5 2.0 Échantillonage correct. Temps t Outils numériques pour l ingénieur 24/83

Échantillonnage Une borne basse de la fréquence d échantillonage? Une borne basse de la fréquence d échantillonage? f =, f e /f =2.0, D/T =2.0 signal signal echantillone Signal x 1.5 2.0 Fréquence d échantillonage trop basse. Temps t Outils numériques pour l ingénieur 25/83

Échantillonnage Une borne basse de la fréquence d échantillonage? Borne basse de la fréquence d échantillonage? f =, f e /f =2.0, D/T =2.0 signal signal echantillone Signal x 1.5 2.0 Fréquence d échantillonage f e trop basse. Bilan : le théorème de Shannon-Nyquist Temps t Toute composante du signal dont la fréquence est supérieure ou égale à f e/2 sera perdue lors de l échantillonage. Outils numériques pour l ingénieur 26/83

Échantillonnage Hautes fréquences et aliasing Hautes fréquences et aliasing f =, f e /f =1.2, D/T =1 signal signal echantillone Signal x 0 2 4 6 8 10 Temps t Hautes fréquences et aliasing Les fréquences trop hautes vis-à-vis de la fréquence d échantillonnage (i. e. f f e/2) sont non seulement perdues mais peuvent produire des artefacts sous la forme de basses fréquences. Il est donc impératif de filtrer le signal préalablement à son échantillonnage pour couper toutes les fréquences supérieures à f e/2. Outils numériques pour l ingénieur 27/83

Échantillonnage Hautes fréquences et aliasing Hautes fréquences et aliasing Explication mathématique Intéressons nous aux signaux de fréquence f = f + kf e avec k Z. On les échantillonne : xn = sin(2π f n) f e = sin(2π f + kfe f e n) = sin(2πnk + 2π f f e n) = sin(2π f f e n) = x n Ce qu il faut comprendre Les signaux de fréquence f = f + kf e avec k Z sont indiscernables par échantillonnage. Dans le cadre d une étude expérimentale, il faut donc s assurer qu une seule de ces fréquences est présente dans le signal échantillonné. Outils numériques pour l ingénieur 28/83

Échantillonnage Hautes fréquences et aliasing Mises en pratique (1/2) 1 # l i s t i n g s / e x e m p l e _ a l i a s i n g. py 2 from m a t p l o t l i b i m p o r t p y p l o t a s p l t 3 from math i m p o r t sin, p i 4 from s i g n a l _ s i n u s o i d a l i m p o r t s i g n a l _ s i n u s o i d a l a s s i g n a l 5 from numpy i m p o r t arange, f l o o r 6 beaucoup = 1000 7 f = 1. # F r e q u e n c e du s i g n a l 8 D = 2. / f # Duree d o b s e r v a t i o n 9 t_min = 0. # Debut du c a l c u l du s i g n a l 10 t_max = t_min+d # F i n du c a l c u l du s i g n a l 11 f e = 2. 1 f # F r e q u e n c e d e c h a n t i l l o n a g e 12 N = i n t ( f l o o r (D f e ) ) # Nombre de p o i n t s d e v a l u a t i o n 13 p l t. f i g u r e ( 0 ) 14 p l t. c l f ( ) 15 p l t. x l a b e l ( T e m p s $ t $, f o n t s i z e =20) 16 p l t. y l a b e l ( S i g n a l $ x $, f o n t s i z e =20) 17 kmin, kmax = 1, 2 18 t = a r a n g e ( beaucoup ) / f l o a t ( beaucoup ) ( t_max t_min )+t_min 19 f o r k i n x r a n g e ( kmin, kmax ) : 20 f1 = f + k f e 21 x = [ s i g n a l ( t t, T=1./ f 1 ) f o r t t i n t ] 22 p l t. p l o t ( t, x, b -, l i n e w i d t h =1.) 23 tn = arange (N) /(D f e ) (t_max t_min )+t_min 24 xn = [ s i g n a l ( t t, T=1./ f ) f o r t t i n t n ] 25 p l t. p l o t ( tn, xn, or ) 26 x = [ s i g n a l ( t t, T=1./ f ) f o r t t i n t ] 27 p l t. p l o t ( t, x, r -, l i n e w i d t h =2.) 28 p l t. s a v e f i g (.. / f i g u r e s / e x e m p l e _ a l i a s i n g. p d f ) Outils numériques pour l ingénieur 29/83

Échantillonnage Hautes fréquences et aliasing Mises en pratique (2/2) Signal x 1.5 2.0 Temps t Outils numériques pour l ingénieur 30/83

Plan 1 Introduction 2 Notations 3 Outils 4 Signaux 5 Échantillonnage 6 Outils numériques pour l ingénieur 31/83

Décomposition des signaux périodiques Fonctions de base On peut projeter les signaux de fréquence f sur une base de dimension infinie constituée de fonctions de la forme : f n(t) = sin(2πnft) et g n(t) = cos(2πnft) Décomposition sur la base Un signal périodique x(t) peut donc s écrire sous la forme : + x(t) = a nsin(2πnft) + b n cos(2πnft) n=0 Points essentiels Connaître [a n] et [b n], c est connaître x(t) en tout point. Cette décomposition donne une interprétation fréquentielle de x(t). La question est donc de savoir comment calculer analytiquement et numériquement [a n] et [b n]. Outils numériques pour l ingénieur 32/83

Développement en séries de Fourier Les grandes lignes Les séries de Fourier permettent d effectuer la projection des signaux périodiques sur la base [f n(t), g n(t)] de manière analytique. Quand N tend vers l infini, la somme converge vers le signal x(t). Pour les signaux présentant des singularités (triangle, carré), elle converge plus lentement. Formulation +N n= N c n(x)e 2jπnft x(t) N Où les coefficients complexes c n(x) C sont définis par : T c n(x) = 1 T 0 x(t)e 2jπnft dt avec : T = 1 f Outils numériques pour l ingénieur 33/83

Exercices Remarques et notations x(t), y(t) et z(t) sont des fonctions de période T du temps t. α est un nombre réel. On pourra introduire la pulsation ω = 2πf pour simplifier les calculs. On rappelle que : cos(a b) = cos(a) cos(b)+sin(a) sin(b) ; sin(a+b) = sin(a) cos(b)+sin(b) cos(a) cos(a) = eja + e ja 2 ; sin(a) = eja e ja 2j Pour chaque signal x, trouver l ensemble des coefficients c n(x) 1 x(t) = cos(2πft) 2 x(t) = cos 2 (2πft) 3 x(t) = αy(t) 4 x(t) = y(t) + z(t) Outils numériques pour l ingénieur 34/83

Exercice : signal sinusoïdal Réécriture x(t) = sin(2πft) = e2jπft e 2jπft 2j = j 2 e 2iπft j 2 e2jπft Coefficients j 2 si : n = 1 c n(x) = j si : n = 1 2 0 n Z {1, 1} Outils numériques pour l ingénieur 35/83

Interprétation des coefficients c n Comment passer de [c n] à [a n, b n] On note R la fonction partie réelle et I la fonction partie imaginaire. On remarque que dans le cas des signaux à valeurs réels (ce qui est majoritairement le cas en physique) : c n = R(c n) ji(c n) = c n Les coefficients associés à n < 0 sont donc inutiles car conjugués de coefficients obtenus pour n >= 0. On remarque aussi que les coeffients a n et b n peuvent être calculés pour n 0 : a n = 2R(c n) b n = 2I(c n) Outils numériques pour l ingénieur 36/83

Exercice : signal carré Calculs Donc : x(t) = { 1 si : t ]0, T /2[ 1 si : t ]T /2, T [ c n(x) = 1 T x(t)e 2jπnft dt T 0 = 1 T /2 e 2jπnft dt + 1 T e 2jπnft dt T 0 T T /2 ( [ = 1 ] j T /2 [ ] ) j T T 2πnf e 2jπnft + 0 2πnf e 2jπnft T /2 Coefficients 2 c n(x) = j πn avec : n = 2k + 1 et : k Z Outils numériques pour l ingénieur 37/83

Exercice : signal carré Mise en pratique : voyons si ça marche 1 # l i s t i n g s / s e r i e F _ c a r r e. py 2 from cmath i m p o r t exp 3 from numpy i m p o r t arange, a r r a y 4 from math i m p o r t p i 5 from m a t p l o t l i b i m p o r t p y p l o t a s p l t 6 from t r a c e _ c o m p l e x e s i m p o r t 7 N = 1 # Nombre de c o e f f i c i e n t s c a l c u l e s 8 f o r N i n [ 1, 2, 4, 8, 1 6, 3 2, 6 4, 1 2 8, 2 5 6, 1 0 2 4 ] : # V a l e u r s de N 9 # I n d i c e s n i m p a i r s 10 n = [ 2 k+1 f o r k i n r a n g e ( N, 0 ) ]+[2 k+1 f o r k i n r a n g e (N) ] 11 c = [ 2 j /( p i nn ) f o r nn i n n ] # C o e f f i c i e n t s c 12 T, beaucoup= 1., 2000 13 t, f = a r a n g e ( beaucoup ) / f l o a t ( beaucoup ) T, a r r a y ( n [N: 2 N ] ) /T 14 t r a c e _ c o m p l e x e s ( f, c [N: 2 N],.. / f i g u r e s / s e r i e F _ c a r r e _ c _ { 0 }. p d f. f o r m a t ( N), t i t l e = C o e f f i c i e n t s $ c _ n $ p o u r $N = { 0 } $. f o r m a t (N) ) 15 x = [ ] 16 f o r t t i n t : 17 x. append ( 0. ) 18 f o r i i n x r a n g e ( l e n ( n ) ) : 19 x [ 1] = x [ 1]+ c [ i ] exp (2 j p i n [ i ] t t /T) 20 x1 = [ xx. r e a l f o r xx i n x ] 21 p l t. f i g u r e ( 0, f i g s i z e =(10,2) ) 22 p l t. c l f ( ) 23 p l t. p l o t ( t, x1 ) 24 p l t. t i t l e ( $N = { 0 } $. f o r m a t (N) ) 25 p l t. s a v e f i g (.. / f i g u r e s / s e r i e F _ c a r r e _ { 0 }. p d f. f o r m a t (N) ) Outils numériques pour l ingénieur 38/83

Exercice : signal carré Programme de tracé de vecteurs complexes 1 # trace_ complexes. py 2 i m p o r t m a t p l o t l i b. p y p l o t a s p l t 3 4 d e f t r a c e _ c o m p l e x e s ( x, y, f i c h i e r, x l a b e l= F r e q u e n c e $ f $, t i t l e =, s t y l e= ro ) : 5 p l t. f i g u r e ( 0, f i g s i z e =(9,5) ) 6 p l t. c l f ( ) 7 p l t. g r i d ( True ) 8 p0 = p l t. s u b p l o t ( 2, 1, 1 ) 9 p0. s e t _ t i t l e ( t i t l e ) 10 p0. g r i d ( ) 11 p0. p l o t ( x, [ yy. r e a l f o r yy i n y ], s t y l e, l i n e w i d t h =2.0) 12 p0. s e t _ y l a b e l ( P a r t i e r e e l l e, f o n t s i z e =15) 13 p1 = p l t. s u b p l o t ( 2, 1, 2 ) 14 p1. g r i d ( ) 15 p1. p l o t ( x, [ yy. imag f o r yy i n y ], s t y l e, l i n e w i d t h =2.0) 16 p1. s e t _ x l a b e l ( x l a b e l, f o n t s i z e =15) 17 p1. s e t _ y l a b e l ( P a r t i e i m a g i n a i r e, f o n t s i z e =15) 18 p l t. s a v e f i g ( f i c h i e r ) Outils numériques pour l ingénieur 39/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =1 4 2 0 2 4 6 0.94 0.60 0.96 0.98 0 2 4 6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.94 0.96 0.98 0 Frequence f 2 4 6 Outils numériques pour l ingénieur 40/83

Exercice : signal carré 1.5 N =1 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 41/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =2 4 2 0 2 4 6 0.20 1.5 2.0 2.5 3.0 0.25 0.30 0.35 0.40 0.45 0 5 0.60 0.65 1.5 2.0 2.5 3.0 Frequence f Outils numériques pour l ingénieur 42/83

Exercice : signal carré 1.5 N =2 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 43/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =4 4 2 0 2 4 6 1 2 3 4 5 6 7 0.1 0.2 0.3 0.4 0.6 0.7 1 2 3 4 Frequence f 5 6 7 Outils numériques pour l ingénieur 44/83

Exercice : signal carré 1.5 N =4 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 45/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =8 4 2 0 2 4 6 0 2 4 6 8 10 12 14 16 0.1 0.2 0.3 0.4 0.6 0.7 0 2 4 6 8 Frequence f 10 12 14 16 Outils numériques pour l ingénieur 46/83

Exercice : signal carré 1.5 N =8 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 47/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =16 4 2 0 2 4 6 0 5 10 15 20 25 30 35 0.1 0.2 0.3 0.4 0.6 0.7 0 5 10 15 20 Frequence f 25 30 35 Outils numériques pour l ingénieur 48/83

Exercice : signal carré 1.5 N =16 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 49/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =32 4 2 0 2 4 6 0 10 20 30 40 50 60 70 0.1 0.2 0.3 0.4 0.6 0.7 0 10 20 30 40 Frequence f 50 60 70 Outils numériques pour l ingénieur 50/83

Exercice : signal carré 1.5 N =32 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 51/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =64 4 2 0 2 4 6 0 20 40 60 80 100 120 140 0.1 0.2 0.3 0.4 0.6 0.7 0 20 40 60 80 Frequence f 100 120 140 Outils numériques pour l ingénieur 52/83

Exercice : signal carré 1.5 N =64 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 53/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =128 4 2 0 2 4 6 0 50 100 150 200 250 300 0.1 0.2 0.3 0.4 0.6 0.7 0 50 100 150 Frequence f 200 250 300 Outils numériques pour l ingénieur 54/83

Exercice : signal carré 1.5 N =128 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 55/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =256 4 2 0 2 4 6 0 100 200 300 400 500 600 0.1 0.2 0.3 0.4 0.6 0.7 0 100 200 300 Frequence f 400 500 600 Outils numériques pour l ingénieur 56/83

Exercice : signal carré 1.5 N =256 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 57/83

Exercice : signal carré Partie reelle Partie imaginaire 6 Coefficients c n pour N =1024 4 2 0 2 4 6 0 500 1000 1500 2000 2500 0.1 0.2 0.3 0.4 0.6 0.7 0 500 1000 1500 Frequence f 2000 2500 Outils numériques pour l ingénieur 58/83

Exercice : signal carré 1.5 N =1024 1.5 0.2 0.4 0.6 0.8 Outils numériques pour l ingénieur 59/83

Extention aux signaux apériodiques Transformées de Fourier Formulation + x(t) F X (f ) = x(t)e 2jπft dt + X (f ) F 1 x(t) = X (f )e 2jπft df Points clés F est la tranformée de Fourier et F 1 la transformée de Fourier inverse. F s applique à tous les signaux, même apériodiques. X (f ) est le spectre de x(t). Un signal apériodique possède un spectre continu. Un signal périodique possède un spectre discret. Outils numériques pour l ingénieur 60/83

La Transformée de Fourier Discrète (DFT) La Transformée de Fourier Discrète ou DFT Formulation On considère un signal échantilloné [x n] comportant N échantillons. Sa transformée de Fourier discrètre [X k ] s écrit : [x n] DFT n=n 1 [X k ] = x ne 2jπ kn N n=0 1 DFT [X k ] [x n] = 1 k=n 1 X k e 2jπ kn N N k=0 Interprétation de [X k ] Le vecteur X k représente le spectre discret de [x n]. Chaque coefficient X k est associé à une fréquence f k obtenue par : f k = k/d = kf e/n Outils numériques pour l ingénieur 61/83

La Transformée de Fourier Rapide (FFT) La Transformée de Fourier Discrète ou DFT Interprétation de [X k ] Dans le cas ou le signal x(t) est réel, les coefficients X k pour k > N/2 sont les conjugués des coefficients d indice k < N/2. On peut donc se contenter d interprêter les N/2 premiers coefficients. Liens entre [X k ] et [a k, b k ] Les coefficients a k et b k peuvent être déterminés par : a k = 2 N R(X k) b k = 2 N I(X k) Outils numériques pour l ingénieur 62/83

La Transformée de Fourier Rapide (FFT) Mise en pratique : calcul de la DFT Programme de calcul de la DFT 1 # l i s t i n g s /exemple_dft. py 2 from s i g n a l _ s i n u s o i d a l i m p o r t 3 from s i g n a l _ c a r r e i m p o r t 4 from t r a c e _ c o m p l e x e s i m p o r t 5 from numpy i m p o r t arange, f l o o r 6 from cmath i m p o r t exp 7 s i g n a l = s i g n a l _ s i n u s o i d a l #s i g n a l = s i g n a l _ c a r r e 8 beaucoup, r i e n = 1000, 1. e 10 9 f = 3. 3 # F r e q u e n c e du s i g n a l 10 D = 4. # Duree d o b s e r v a t i o n 11 t_min = 0. # Debut du c a l c u l du s i g n a l 12 t_max = t_min+d # F i n du c a l c u l du s i g n a l 13 f e = 1 6. # F r e q u e n c e d e c h a n t i l l o n a g e 14 N = i n t ( f l o o r (D f e ) ) # Nombre de p o i n t s d e v a l u a t i o n 15 t n = a r a n g e (N) /(D f e ) ( t_max t_min )+t_min # D i s c r e t i s a t i o n du temps 16 xn = [ s i g n a l ( t t, T=1./ f, k =4.) f o r t t i n t n ] # D i s c r e t i s a t i o n du s i g n a l 17 Xk = [ ] # DFT de xn 18 f o r k i n r a n g e (N) : # B o u c l e s u r k 19 Xk. append ( 0. ) 20 f o r n i n r a n g e (N) : # B o u c l e s u r n 21 Xk[ 1] = Xk[ 1] + xn [ n ] exp ( 2 j p i n k/n) # C a l c u l de Xk 22 i f abs ( Xk [ 1 ]. r e a l ) < r i e n : Xk[ 1] = Xk[ 1] Xk [ 1 ]. r e a l 23 i f abs ( Xk [ 1 ]. imag ) < r i e n : Xk[ 1] = Xk[ 1] 1 j Xk [ 1 ]. imag 24 Xk[ 1] = Xk[ 1] 2/N 25 f k = a r a n g e (N) /D # D i s c r e t i s a t i o n d e s f r e q u e n c e s 26 t i t = $ D F T (\ s i n ( 2 \ pi nf / f _ e ) ) * 2 / N$ : N ={0}, f ={1}, D = { 2 }. f o r m a t (N, f,d) 27 t r a c e _ c o m p l e x e s ( f k [ : N/ 2 ], Xk [ : N/ 2 ],.. / f i g u r e s / D F T _ s i n u s. p d f, t i t l e = t i t ) Outils numériques pour l ingénieur 63/83

La Transformée de Fourier Rapide (FFT) Vérification la DFT sur un signal sinusoïdal Partie reelle Partie imaginaire 2.5 DFT(sin(2πnf/f e )) 2/N: N=64, f=3.3, D=4.0 2.0 1.5 0 1 2 3 4 5 6 7 8 1.5 2.0 2.5 3.0 3.5 0 1 2 3 4 5 6 7 8 Frequence f On retrouve donc bien la série de Fourier avec le coefficient 2/N. Outils numériques pour l ingénieur 64/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) La FFT, pourquoi? Comment? Pourquoi? Le calcul direct de la DFT demande de l ordre de N 2 opérations alors que des algorithmes optimisés dits FFT demandent N log N opérations. Le gain de temps est très significatif quand N est grand. L utilisation de langages rapides (C, Fortran) dans le module FFTPack disponible dans Scipy permet typiquement d augmenter d un facteur 400 la vitesse d execution par rapport Python. Comment? Restrictions de la FFT : N doit être une puissance de 2. Utilisation : 1 # l i s t i n g s /exemple_fft. py 2 from math i m p o r t pi, s i n 3 from s c i p y. f f t p a c k i m p o r t f f t 4 N = 8 5 xn = [ s i n (2 p i n/n) f o r n i n x r a n g e (N) ] 6 Xk = f f t ( xn ) Renvoie X n = [0, 2j, 0, 2j] ce qui est identique au résultat obtenu par DFT. On utilisera donc préférentiellement la FFT pour des raisons de commodité et vitesse. Outils numériques pour l ingénieur 65/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de la fréquence f Programme 1 # l i s t i n g s / exemple_fft_frequence. py 2 from math i m p o r t pi, sin, exp 3 from s c i p y. f f t p a c k i m p o r t f f t 4 from random i m p o r t g a u s s 5 from numpy i m p o r t array, arange, f l o o r 6 from m a t p l o t l i b i m p o r t p y p l o t a s p l t 7 i m p o r t m a t p l o t l i b. g r i d s p e c a s g r i d s p e c 8 from s i g n a l _ s i n u s o i d a l i m p o r t 9 beaucoup = 1000 10 f e = 6 4. # F r e q u e n c e d e c h a n t i l l o n a g e 11 N = 4096 # Nombre de p o i n t s d e c h a n t i l l o n a g e 12 D = N/ f e # Duree d o b s e r v a t i o n 13 f = 8. /D # F r e q u e n c e du s i g n a l 14 t_min = 0. # Debut du c a l c u l du s i g n a l 15 t_max = t_min+d # F i n du c a l c u l du s i g n a l 16 s t d d e v = 0. # E c a r t t y p e du b r u i t 17 nom =.. / f i g u r e s / F F T _ f r e q u e n c e. p d f 18 amort = 0. 19 v a l = [ f e 2, 6 4. /D, 1 6. / D, 8. / D] # F r e q u e n c e 20 l a b = $f = { 0 } $ 21 t n = a r a n g e (N) /(D f e ) D+t_min 22 f o r i i n x r a n g e (N) : 23 i f t n [ i ] <=1./ f : i _t = i 24 xn = [ s i n (2 p i f t ) f o r t i n t n ] 25 f k = a r a n g e (N) /D # D i s c r e t i s a t i o n d e s f r e q u e n c e s 26 p l t. f i g u r e ( 0, f i g s i z e =(12,8) ) 27 p l t. c l f ( ) 28 gs = g r i d s p e c. G r i d S p e c ( 4, 3) # G r i l l e de zone de t r a c e Outils numériques pour l ingénieur 66/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de la fréquence f Programme 29 p0 = p l t. s u b p l o t ( gs [ :, : 2 ] ) 30 p0. s e t _ t i t l e ( r $x ( t ) = \ s i n (2 \ pi f t ) $ a v e c $ f $ v a r i a b l e, $ f _ e = { } $. f o r m a t ( f e ) ) 31 p0. g r i d ( ) 32 p0. s e t _ x l a b e l ( r $ f _ k $, f o n t s i z e =20) 33 p0. s e t _ y l a b e l ( r $ \ f r a c { 2 } { N } X _ k $, f o n t s i z e =20) 34 p0. s e t _ x s c a l e ( l o g ) 35 p0. s e t _ y s c a l e ( l o g ) 36 f o r z i n x r a n g e ( l e n ( v a l ) ) : 37 v = v a l [ z ] 38 #s t d d e v = v 39 f = v 40 xn = [ s i n (2 p i f t ) f o r t i n t n ] 41 v_amort = a r r a y ( [ exp( t amort ) f o r t i n t n ] ) 42 c o l o r = [ r, b, g, c ] [ z ] 43 b r u i t = a r r a y ( [ g a u s s ( 0, s t d d e v ) f o r i i n x r a n g e (N) ] ) 44 xxn = ( xn + b r u i t ) v_amort 45 Xk = abs ( f f t ( xxn ) ) 2. /N 46 p0. p l o t ( f k [ 0 : N/ 2 ], Xk [ 0 : N/ 2 ], - +c o l o r, l a b e l = l a b. f o r m a t ( v ) ) 47 p0. l e g e n d ( ) 48 p1 = p l t. s u b p l o t ( gs [ z, 1]) 49 p1. g r i d ( ) 50 p1. p l o t ( t n [ : i_t ], xxn [ : i_t ], - +c o l o r ) 51 p1. s e t _ x l a b e l ( T e m p s $ t $ ) 52 p l t. s a v e f i g (nom) Outils numériques pour l ingénieur 67/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de la fréquence f 2 X N k 10-1 10-3 10-5 10-7 10-9 10-11 10-13 10-15 10-17 x(t) =sin(2πft) avec f variable, f e =64.0 f =62.0 f = f =0.25 f =0.125 10-19 10-2 10-1 10 0 10 1 10 2 f k Changer la fréquence, c est translater horizontalement le pic. 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 Temps t 6 7 8 Outils numériques pour l ingénieur 68/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de la durée d observation D Programme 1 # l i s t i n g s /exemple_fft_d. py 2 from math i m p o r t pi, sin, exp 3 from s c i p y. f f t p a c k i m p o r t f f t 4 from random i m p o r t g a u s s 5 from numpy i m p o r t array, arange, f l o o r, hanning 6 from m a t p l o t l i b i m p o r t p y p l o t a s p l t 7 i m p o r t m a t p l o t l i b. g r i d s p e c a s g r i d s p e c 8 from s i g n a l _ s i n u s o i d a l i m p o r t 9 beaucoup = 1000 10 f e = 1 2 8. # F r e q u e n c e d e c h a n t i l l o n a g e 11 f = 1. # F r e q u e n c e du s i g n a l 12 t_min = 0. # Debut du c a l c u l du s i g n a l 13 s t d d e v = 0. # E c a r t t y p e du b r u i t 14 nom =.. / f i g u r e s / F F T _ D. p d f 15 amort = 0. 16 v a l = 8. / f a r r a y ( [. 8, 1., 1. 2, 1. 6 ] ) 17 l a b = $D / T = { 0 } $ 18 19 20 p l t. f i g u r e ( 0, f i g s i z e =(12,8) ) 21 p l t. c l f ( ) 22 gs = g r i d s p e c. G r i d S p e c ( 4, 3) # G r i l l e de zone de t r a c e 23 p0 = p l t. s u b p l o t ( gs [ :, : 2 ] ) 24 p0. s e t _ t i t l e ( r $x ( t ) = \ s i n (2 \ pi f t ) $ a v e c $ D $ v a r i a b l e ) 25 p0. g r i d ( ) 26 p0. s e t _ x l a b e l ( r $ f _ k $, f o n t s i z e =20) 27 p0. s e t _ y l a b e l ( r $ \ f r a c { 2 } { N } X _ k $, f o n t s i z e =20) 28 p0. s e t _ x s c a l e ( l o g ) Outils numériques pour l ingénieur 69/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de la durée d observation D Programme 29 p0. s e t _ y s c a l e ( l o g ) 30 f o r z i n x r a n g e ( l e n ( v a l ) ) : 31 v = v a l [ z ] 32 D = v 33 i_t= 1 34 N = i n t (D f e ) 35 f k = a r a n g e (N) /D # D i s c r e t i s a t i o n d e s f r e q u e n c e s 36 t_max = t_min+d # F i n du c a l c u l du s i g n a l 37 t n = a r a n g e (N) / f l o a t (N) D+t_min 38 xn = [ s i n (2 p i f t ) f o r t i n t n ] 39 v_amort = a r r a y ( [ exp( t amort ) f o r t i n t n ] ) 40 c o l o r = [ r, b, g, c ] [ z ] 41 b r u i t = a r r a y ( [ g a u s s ( 0, s t d d e v ) f o r i i n x r a n g e (N) ] ) 42 xxn = ( xn + b r u i t ) v_amort # h a n n i n g (N) 43 Xk = abs ( f f t ( xxn ) ) 2. /N 44 p0. p l o t ( f k [ 0 : N/ 2 ], Xk [ 0 : N/ 2 ], - +c o l o r, l a b e l = l a b. f o r m a t ( v f ) ) 45 p1 = p l t. s u b p l o t ( gs [ z, 1]) 46 p1. g r i d ( ) 47 p1. p l o t ( t n [ : i_t ], xxn [ : i_t ], - +c o l o r ) 48 p0. l e g e n d ( ) 49 p1. s e t _ x l a b e l ( T e m p s $ t $ ) 50 p l t. s a v e f i g (nom) Outils numériques pour l ingénieur 70/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de la durée d observation D 2 X N k x(t) =sin(2πft) avec D variable D/T =6.4 D/T =8.0 D/T =9.6 0 1 2 3 4 5 6 7 D/T =12.8 0 1 2 3 4 5 6 7 8 0 2 4 6 8 10 10-2 10-1 10 0 10 1 10 2 10 0 10-2 10-4 10-6 10-8 10-10 10-12 10-14 10-16 10-18 0 2 4 6 8 10 12 14 Temps t f k Lorque D n est pas multiple de la période T, la hauteur du pic est réduite. Outils numériques pour l ingénieur 71/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de la durée d observation D 2 X N k 10 0 10-1 10-2 10-3 10-4 10-5 10-6 10-7 10-8 10-9 10-10 x(t) =sin(2πft)e t/τ avec D variable D/T =6.4 D/T =8.0 D/T =9.6 D/T =12.8 10-11 10-2 10-1 10 0 10 1 10 2 f k 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 0 2 4 6 8 10 0 2 4 6 8 Temps t 10 12 14 Le fenetrage temporel de Hann permet d augmenter la hauteur du pic. Outils numériques pour l ingénieur 72/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet du bruit Programme 1 # l i s t i n g s / exemple_fft_bruit. py 2 from math i m p o r t pi, sin, exp 3 from s c i p y. f f t p a c k i m p o r t f f t 4 from random i m p o r t g a u s s 5 from numpy i m p o r t array, arange, f l o o r 6 from m a t p l o t l i b i m p o r t p y p l o t a s p l t 7 i m p o r t m a t p l o t l i b. g r i d s p e c a s g r i d s p e c 8 from s i g n a l _ s i n u s o i d a l i m p o r t 9 beaucoup = 1000 10 f e = 6 4. # F r e q u e n c e d e c h a n t i l l o n a g e 11 N = 4096 # Nombre de p o i n t s d e c h a n t i l l o n a g e 12 D = N/ f e # Duree d o b s e r v a t i o n 13 f = 8. /D # F r e q u e n c e du s i g n a l 14 t_min = 0. # Debut du c a l c u l du s i g n a l 15 t_max = t_min+d # F i n du c a l c u l du s i g n a l 16 s t d d e v = 0. # E c a r t t y p e du b r u i t 17 nom =.. / f i g u r e s / F F T _ b r u i t. p d f 18 amort = 0. 19 v a l = [ 1., 1. e 1,1. e 2, 0. ] # B r u i t 20 l a b = Ecart type bruit : {0} 21 t n = a r a n g e (N) /(D f e ) D+t_min 22 f o r i i n x r a n g e (N) : 23 i f t n [ i ] <=1./ f : i _t = i 24 xn = [ s i n (2 p i f t ) f o r t i n t n ] 25 f k = a r a n g e (N) /D # D i s c r e t i s a t i o n d e s f r e q u e n c e s 26 p l t. f i g u r e ( 0, f i g s i z e =(12,8) ) 27 p l t. c l f ( ) 28 gs = g r i d s p e c. G r i d S p e c ( 4, 3) # G r i l l e de zone de t r a c e Outils numériques pour l ingénieur 73/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet du bruit Programme 29 p0 = p l t. s u b p l o t ( gs [ :, : 2 ] ) 30 p0. s e t _ t i t l e ( r $x ( t ) = \ s i n (2 \ pi f t ) + $ b r u i t ) 31 p0. g r i d ( ) 32 p0. s e t _ x l a b e l ( r $ f _ k $, f o n t s i z e =20) 33 p0. s e t _ y l a b e l ( r $ \ f r a c { 2 } { N } X _ k $, f o n t s i z e =20) 34 p0. s e t _ x s c a l e ( l o g ) 35 p0. s e t _ y s c a l e ( l o g ) 36 f o r z i n x r a n g e ( l e n ( v a l ) ) : 37 v = v a l [ z ] 38 s t d d e v = v 39 v_amort = a r r a y ( [ exp( t amort ) f o r t i n t n ] ) 40 c o l o r = [ r, b, g, c ] [ z ] 41 b r u i t = a r r a y ( [ g a u s s ( 0, s t d d e v ) f o r i i n x r a n g e (N) ] ) 42 xxn = ( xn + b r u i t ) v_amort 43 Xk = abs ( f f t ( xxn ) ) 2. /N 44 p0. p l o t ( f k [ 0 : N/ 2 ], Xk [ 0 : N/ 2 ], - +c o l o r, l a b e l = l a b. f o r m a t ( v ) ) 45 p0. l e g e n d ( ) 46 p1 = p l t. s u b p l o t ( gs [ z, 1]) 47 p1. g r i d ( ) 48 p1. p l o t ( t n [ : i_t ], xxn [ : i_t ], - +c o l o r ) 49 p1. s e t _ x l a b e l ( T e m p s $ t $ ) 50 p l t. s a v e f i g (nom) Outils numériques pour l ingénieur 74/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet du bruit 2 X N k 10 1 10-1 10-3 10-5 10-7 10-9 10-11 10-13 10-15 10-17 x(t) =sin(2πft) + bruit Ecart type bruit: Ecart type bruit: 0.1 Ecart type bruit: 1 Ecart type bruit: 10-19 10-2 10-1 10 0 10 1 10 2 f k Le bruit réduit la hauteur du pic. 4 3 0 12 3 21 0 1 2 3 4 5 6 7 8 1.5 1.5 0 1 2 3 4 5 6 7 8 1.5 1.5 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Temps t Outils numériques pour l ingénieur 75/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de l amortissement Programme 1 # l i s t i n g s / exemple_fft_amortissement. py 2 from math i m p o r t pi, sin, exp 3 from s c i p y. f f t p a c k i m p o r t f f t 4 from random i m p o r t g a u s s 5 from numpy i m p o r t array, arange, f l o o r, hanning 6 from m a t p l o t l i b i m p o r t p y p l o t a s p l t 7 i m p o r t m a t p l o t l i b. g r i d s p e c a s g r i d s p e c 8 from s i g n a l _ s i n u s o i d a l i m p o r t 9 beaucoup = 1000 10 f e = 6 4. # F r e q u e n c e d e c h a n t i l l o n a g e 11 N = 1024 # Nombre de p o i n t s d e c h a n t i l l o n a g e 12 D = N/ f e # Duree d o b s e r v a t i o n 13 f = 3 2. /D # F r e q u e n c e du s i g n a l 14 t_min = 0. # Debut du c a l c u l du s i g n a l 15 t_max = t_min+d # F i n du c a l c u l du s i g n a l 16 s t d d e v = 0. # E c a r t t y p e du b r u i t 17 nom =.. / figures / FFT_ amortissement - hann. pdf 18 amort = 0. 19 v a l = [ 0.,. 0 0 1,. 1, 1. ] # A m o r t i s s e m e n t 20 l a b = r $1 /\ t a u = { 0 } $ 21 t n = a r a n g e (N) /(D f e ) D+t_min 22 xn = [ s i n (2 p i f t ) f o r t i n t n ] 23 f k = a r a n g e (N) /D # D i s c r e t i s a t i o n d e s f r e q u e n c e s 24 p l t. f i g u r e ( 0, f i g s i z e =(12,8) ) 25 p l t. c l f ( ) 26 gs = g r i d s p e c. G r i d S p e c ( 4, 3) # G r i l l e de zone de t r a c e 27 p0 = p l t. s u b p l o t ( gs [ :, : 2 ] ) 28 p0. s e t _ t i t l e ( r $x ( t ) = \ s i n (2 \ pi f t ) e ^{ t /\ t a u } $ a v e c $ \ t a u $ v a r i a b l e + H a n n ) Outils numériques pour l ingénieur 76/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de l amortissement Programme 29 p0. g r i d ( ) 30 p0. s e t _ x l a b e l ( r $ f _ k $, f o n t s i z e =20) 31 p0. s e t _ y l a b e l ( r $ \ f r a c { 2 } { N } X _ k $, f o n t s i z e =20) 32 p0. s e t _ x s c a l e ( l o g ) 33 p0. s e t _ y s c a l e ( l o g ) 34 35 f o r z i n x r a n g e ( l e n ( v a l ) ) : 36 v = v a l [ z ] 37 amort = v 38 v_amort = a r r a y ( [ exp( t amort ) f o r t i n t n ] ) 39 c o l o r = [ r, b, g, c ] [ z ] 40 b r u i t = a r r a y ( [ g a u s s ( 0, s t d d e v ) f o r i i n x r a n g e (N) ] ) 41 xxn = ( xn + b r u i t ) v_amort h a n n i n g (N) 42 Xk = abs ( f f t ( xxn ) ) 2. /N 43 p0. p l o t ( f k [ 0 : N/ 2 ], Xk [ 0 : N/ 2 ], - +c o l o r, l a b e l = l a b. f o r m a t ( v ) ) 44 p0. l e g e n d ( ) 45 p1 = p l t. s u b p l o t ( gs [ z, 1]) 46 p1. g r i d ( ) 47 p1. p l o t ( t n [ : ], xxn [ : ], - +c o l o r ) 48 p1. s e t _ x l a b e l ( T e m p s $ t $ ) 49 p l t. s a v e f i g (nom) Outils numériques pour l ingénieur 77/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : effet de l amortissement 2 X N k 10 0 10-2 10-4 10-6 10-8 10-10 10-12 10-14 10-16 x(t) =sin(2πft)e t/τ avec τ variable 1/τ = 1/τ =01 1/τ =0.1 1/τ = 10-18 10-2 10-1 10 0 10 1 10 2 f k L amortissement entraine une perte de hauteur du pic. 0 2 4 6 8 10 12 14 16 0 2 4 6 8 10 12 14 16 0 2 4 6 8 10 12 14 16 0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8 0 2 4 6 8 10 12 14 16 Temps t Outils numériques pour l ingénieur 78/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) FFT : amortissement et fenetrage de Hann 2 X N k 10 0 x(t) =sin(2πft)e t/τ avec τ variable + Hann 1/τ = 10-1 1/τ =01 10-2 1/τ =0.1 1/τ = 0 2 4 6 8 10 12 14 16 10-3 10-4 10-5 0 2 4 6 8 10 12 14 16 0.6 0.4 10-6 0.2 0.2 10-7 0.4 0.6 0 2 4 6 8 10 12 14 16 10-8 20 15 10 05 10-9 00 05 10 15 10-2 10-1 10 0 10 1 20 10 2 0 2 4 6 8 10 12 14 16 Temps t f k 10-10 Le fenêtrage de Hann (méthode dite hanning) induit une hauteur de pic 1000!! Outils numériques pour l ingénieur 79/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) Vibration d une poutre : spectre Force, fft(f) [N] Acceleration, fft(a) [g] 180 160 140 120 100 80 60 40 20 0 0 2000 4000 6000 8000 10000 2500 2000 1500 1000 500 0 0 2000 4000 6000 8000 10000 Frequency, f [Hz] Outils numériques pour l ingénieur 80/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) Application à la cloche 1 # l i s t i n g s / exemple_fft_cloche. py 2 from s c i p y. f f t p a c k i m p o r t f f t 3 from numpy i m p o r t array, arange, hanning 4 from m a t p l o t l i b i m p o r t p y p l o t a s p l t 5 i m p o r t p i c k l e 6 nom =.. / f i g u r e s / F F T _ c l o c h e - l o g. p d f 7 f i c h i e r = open ( c l o c h e. p c k l, r ) # O u v e r t u r e du f i c h i e r 8 c l o c h e = p i c k l e. l o a d ( f i c h i e r ) # Chargement d e s d o n n e e s 9 f i c h i e r. c l o s e ( ) # F e r m e t u r e du f i c h i e r 10 xn = c l o c h e [ x ] [ : : 3 2 ] # Redimensionnement d e s d o n n e e s 11 f e = f l o a t ( c l o c h e [ fe ] ) # D e f i n i t i o n de l a f r e q u e n c e d e c h a n t i l l o n a g e 12 t n = a r a n g e ( l e n ( xn ) ) / f l o a t ( f e ) 13 N = l e n ( t n ) 14 D = N/ f e 15 p l t. f i g u r e ( 0, f i g s i z e =(12,8) ) 16 p l t. c l f ( ) 17 f k = a r a n g e (N) /D # D i s c r e t i s a t i o n d e s f r e q u e n c e s 18 Xk = abs ( f f t ( xn ) ) 2. /N 19 Xkh = abs ( f f t ( xn h a n n i n g (N) ) ) 2. /N 20 p l t. p l o t ( f k [ 0 : N/ 2 ], Xk [ 0 : N/ 2 ], -, l a b e l= S i g n a l b r u t ) 21 p l t. p l o t ( f k [ 0 : N/ 2 ], Xkh [ 0 : N/ 2 ], -, l a b e l= F e n e t r a g e H a n n ) 22 p l t. x l a b e l ( r $ f _ k $, f o n t s i z e =20) 23 p l t. y l a b e l ( r $ \ f r a c { 2 } { N } X _ k $, f o n t s i z e =20) 24 p l t. x s c a l e ( l o g ) 25 p l t. y s c a l e ( l o g ) 26 p l t. g r i d ( True ) 27 p l t. l e g e n d ( l o c= u p p e r l e f t ) 28 p l t. s a v e f i g (nom) Outils numériques pour l ingénieur 81/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) Application à la cloche 10-1 Signal brut Fenetrage Hann 10-2 10-3 2 X N k 10-4 10-5 10-6 10 0 10 1 10 2 10 3 10 4 f k Outils numériques pour l ingénieur 82/83

Optimisation de la DFT : la Transformée de Fourier Rapide (FFT) Application à la cloche 8 7 Signal brut Fenetrage Hann 6 5 2 X N k 4 3 2 1 0 0 500 1000 1500 2000 2500 3000 f k Outils numériques pour l ingénieur 83/83