Démo TP : Signal, Energie et Puissance, Corrélations

Опубликовано: 03 Август 2026
на канале: Assia Kourgli
1,467
29

Code
-*- coding: utf-8 -*-
"""
Created on Fri Mar 3 19:45:54 2023

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


'''---------------------- Quelques Signaux Usuels Discrets -----------------'''
#Dirac
N=32;
x = np.zeros(N);
x[0]=1;
plt.figure(1)
plt.stem(x)
plt.title('Un Dirac'); plt.xlabel('n'); plt.ylabel('Amplitude')
#Echellon
x=np.zeros(N); y = np.ones(N); z=np.concatenate((x,y));
t=np.arange(-N,N,1)
plt.figure(2)
plt.stem(z)
plt.title('Un Echelon'); plt.grid(True); plt.xlabel('n'); plt.ylabel('Amplitude')
#Sinusoïde
N = 128; f0=1000; fe=10000.; Te=1/fe
t = np.arange(0,N,1)*Te
x = np.cos(2.0*np.pi*f0*t)
plt.figure(3)
plt.plot(t,x, 'r',label='points interpolés'); plt.xlabel('s)'); plt.ylabel('Amplitude')
plt.stem(t, x,'b', label='dessin points'); plt.xlabel('(s)'); plt.ylabel('Amplitude')
plt.legend()
Signal aléatoire Gaussienne moyenne = 0 et de variance 4
N=1000; sigma =3; Moy=0
b = Moy+ sigma * np.random.randn(N)
plt.figure(4)
plt.plot(b); plt.grid();plt.title(label='Réalisation d un processus aléatoire moy %d et var%d'%(Moy,pow(sigma,2)));


'''---------------------- Energie et Autocorrélation ---------------------'''
N = 30; A=4; Te=1;
t = np.arange(0,N)*Te
x = A*np.concatenate((np.zeros(10),np.ones(10),np.zeros(10)))
plt.figure(5)
plt.subplot(121); plt.stem(t, x); plt.grid(True); plt.xlabel('S'); plt.ylabel('Amp')
tt = np.arange(-(N-1),N)*Te
Rxx = np.correlate(x,x,mode='full');
plt.subplot(122); plt.title('Autocorr');plt.plot(tt,Rxx); plt.grid(True); plt.xlabel('S'); plt.ylabel('Amp')
Energie=sum(abs(x)**2)


'''----------------------------- Corrélation ------------------------------'''
N = 500; sigma = 0.5 ; moy = 0;
x = np.zeros(N); x[0:10]=1;
b = sigma * np.random.randn(N) + moy
y = np.roll(x,50)+ b
Ryx = np.correlate(y,x,mode='full');
Ryx=Ryx[N-1:2*N-1]
plt.figure(6)
plt.subplot(311); plt.plot(x); plt.title('signal émis')
plt.subplot(312); plt.plot(y); plt.title('signal reçu')
plt.subplot(313); plt.plot(Ryx); plt.title('Intercorrélation entre signal émis et signal reçu')
TAR_estim=np.argmax(Ryx);


'''----------------------------- Convolution ------------------------------'''
N = 128; f0=500; fe=10000.; Te=1/fe; T=3;
t = np.arange(0,N)*Te
x = np.cos(2.0*np.pi*f0*t);
sigma = 0.3; Moy=0 ;
b = Moy + sigma * np.random.randn(N) ;
xb = x + b
h = 1.0/T*np.ones(T)
y = np.convolve (xb, h, mode='full')
th = np.arange(0,T)*Te ;
ty = np.arange(0,N+T-1)*Te
plt.figure(7)
plt.subplot(311); plt.plot(t,x, label='signal originalx(n)');plt.plot(t,xb,label='signal bruité ');
plt.legend(); plt.title('Signal d entrée x(n) bruité + signal x(n) original')
plt.subplot(312); plt.stem(th, h); plt.title('Le filtre h(n)')
plt.subplot(313); plt.plot(t,x, label='signal original x(n)');plt.plot(ty,y,label='signal de sortie y(n)');
plt.legend(); plt.title('Signal de sortie y(n)+ signal x(n) original')




Exercices    • Exercices - Signal, Energie et Puissance, ...  
Systèmes Linéaires et Invariant dans le temps :    • Systèmes Linéaires et Invariants dans le t...  
Produit de Convolution discret :    • Exemples de calcul d'un produit de convolu...  
Produit de Convolution en continu:    • Calcul d'un produit de convolution pour le...  
Auto-Corrélation et corrélation :    • Auto-Corrélation , corrélation et applicat...  
Causalité et stabilité :    • Causalité et stabilité des Systèmes Linéai...  
Démo de TP :