Analiza coerenței a două semnale: Diferență între versiuni

De la YO3ITI
Sari la navigare Sari la căutare
Pagină nouă: <source lang="Python"> import numpy as np import matplotlib.pyplot as plt # https://matplotlib.org/gallery/index.html # Fixing random state for reproductibility np.random.seed(196...
 
Fără descriere a modificării
 
(Nu s-au afișat 29 de versiuni intermediare efectuate de același utilizator)
Linia 1: Linia 1:
<source lang="Python">
[[Fișier:Semnale - coerență.png|800px|Se observă componenta coerentă de 10Hz; restul e zgomot.]]
<syntaxhighlight lang="python">
import numpy as np
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
# https://matplotlib.org/gallery/index.html
# https://matplotlib.org/gallery/index.html


# Fixing random state for reproductibility
# Fixarea stării aleatorii (pentru reproductibilitate)
np.random.seed(19680801)
np.random.seed(19680801)


Linia 12: Linia 13:
nse2 = np.random.randn(len(t))  # white noise 2
nse2 = np.random.randn(len(t))  # white noise 2


# Two signals with a coherent part at 10Hz and a random part
# Două semnale cu o componentă coerentă de 10Hz și o componentă aleatorie
# componenta coerentă va fi afișată ca un vârf pe grafic; restul e zgomot
s1 = np.sin(2 * np.pi * 10 * t) + nse1
s1 = np.sin(2 * np.pi * 10 * t) + nse1
s2 = np.sin(2 * np.pi * 10 * t) + nse2
s2 = np.sin(2 * np.pi * 10 * t) + nse2
Linia 20: Linia 22:
axs[0].plot(t, s1, t, s2)
axs[0].plot(t, s1, t, s2)
axs[0].set_xlim(0, 2)
axs[0].set_xlim(0, 2)
axs[0].set_xlabel('time')
axs[0].set_xlabel('timp')
axs[0].set_ylabel('s1 and s2')
axs[0].set_ylabel('s1 și s2')
axs[0].grid(True)
axs[0].grid(True)


cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
axs[1].set_ylabel('coherence')
axs[1].set_ylabel('coerența')
axs[1].set_xlabel('frecvența')


fig.tight_layout()
fig.tight_layout()
plt.show()
plt.show()
</source>
</syntaxhighlight >

Versiunea curentă din 9 februarie 2026 22:17

Se observă componenta coerentă de 10Hz; restul e zgomot.

import numpy as np
import matplotlib.pyplot as plt
# https://matplotlib.org/gallery/index.html

# Fixarea stării aleatorii (pentru reproductibilitate)
np.random.seed(19680801)

dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t))  # white noise 1
nse2 = np.random.randn(len(t))  # white noise 2

# Două semnale cu o componentă coerentă de 10Hz și o componentă aleatorie
# componenta coerentă va fi afișată ca un vârf pe grafic; restul e zgomot
s1 = np.sin(2 * np.pi * 10 * t) + nse1
s2 = np.sin(2 * np.pi * 10 * t) + nse2

axs: object
fig, axs = plt.subplots(2, 1)
axs[0].plot(t, s1, t, s2)
axs[0].set_xlim(0, 2)
axs[0].set_xlabel('timp')
axs[0].set_ylabel('s1 și s2')
axs[0].grid(True)

cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
axs[1].set_ylabel('coerența')
axs[1].set_xlabel('frecvența')

fig.tight_layout()
plt.show()