TB065

Index Commits Files Refs
guias/7_20.py (767B)
   1 # 7_20.py
   2 
   3 import numpy as np
   4 import matplotlib.pyplot as plt
   5 from scipy import signal
   6 
   7 fs = 400
   8 T = 1/fs
   9 t = np.arange(0, 1, T)
  10 
  11 x_a = np.cos(2*np.pi*100*t)
  12 x_b = (1 + np.cos(2*np.pi*10*t)) * np.cos(2*np.pi*100*t)
  13 x_c = np.cos(2 * np.pi * 100 * t**2)
  14 
  15 sig = [x_a, x_b, x_c]
  16 
  17 plt.figure(figsize=(15, 5))
  18 
  19 for i, x in enumerate(sig):
  20     plt.subplot(1, 3, i+1)
  21 
  22     # `nperseg` tamaƱo de la ventana
  23     # `noverlap` solapamiento entre ventanas
  24     f, times, Sxx = signal.spectrogram(x, fs, window='hann',
  25                                        nperseg=128, noverlap=32)
  26 
  27     plt.pcolormesh(times, f, 10*np.log10(Sxx), cmap='inferno', shading='gouraud')
  28 
  29     if i == 0:
  30         plt.ylabel('Frecuencia [Hz]')
  31     plt.xlabel('Tiempo [s]')
  32 
  33 plt.tight_layout()
  34 plt.show()