TB065

Index Commits Files Refs
guias/8_07.py (1570B)
   1 # 8_07.py
   2 
   3 import numpy as np
   4 import matplotlib.pyplot as plt
   5 from numpy import pi, sin
   6 
   7 tau = 0.1
   8 
   9 T = 2 * pi  # Periodo
  10 w0 = 2 * pi / T
  11 D = 0.5 # duty cycle
  12 
  13 k_max = 100
  14 ks = np.arange(k_max, dtype=int)
  15 a_k = np.arange(k_max, dtype=float)
  16 b_k = np.arange(k_max, dtype=float)
  17 
  18 for k in range(k_max):
  19     if k == 0:
  20         a_k[k] = (w0*D*T) / (2*pi)
  21         b_k[k] = (1/((tau*2*pi/T)+1)) * (w0*D*T)/(2*pi)
  22     else:
  23         a_k[k] = sin(k*D*w0*T/2) / (k*pi)
  24         b_k[k] = (1/((tau*2*pi/T)+1)) * (sin(k*D*w0*T/2)/(k*pi))
  25 
  26 # magnitud a_k
  27 plt.subplot(1, 2, 1)
  28 markerline, stemlines, _ = plt.stem(ks, np.abs(a_k), basefmt=" ")
  29 plt.setp(markerline, 'markerfacecolor', 'blue')
  30 plt.title('Espectro de Magnitud $|a_k|$')
  31 plt.xlabel('Armónico (k)')
  32 plt.ylabel('Amplitud')
  33 plt.grid(True, linestyle='--')
  34 
  35 # fase a_k
  36 plt.subplot(1, 2, 2)
  37 plt.stem(ks, np.angle(a_k), basefmt=" ")
  38 plt.title('Espectro de Fase $\\angle a_k$ (rad)')
  39 plt.xlabel('Armónico (k)')
  40 plt.ylabel('Fase')
  41 plt.grid(True, linestyle='--')
  42 
  43 plt.tight_layout()
  44 plt.show()
  45 
  46 plt.figure(figsize=(10, 10))
  47 
  48 # magnitud b_k
  49 plt.subplot(1, 2, 1)
  50 markerline, stemlines, _ = plt.stem(ks, np.abs(b_k), basefmt=" ")
  51 plt.setp(markerline, 'markerfacecolor', 'blue')
  52 plt.title('Espectro de Magnitud $|b_k|$')
  53 plt.xlabel('Armónico (k)')
  54 plt.ylabel('Amplitud')
  55 plt.grid(True, linestyle='--')
  56 
  57 # fase b_k
  58 plt.subplot(1, 2, 2)
  59 plt.stem(ks, np.angle(b_k), basefmt=" ")
  60 plt.title('Espectro de Fase $\\angle b_k$ (rad)')
  61 plt.xlabel('Armónico (k)')
  62 plt.ylabel('Fase')
  63 plt.grid(True, linestyle='--')
  64 
  65 plt.tight_layout()
  66 plt.show()