Advertisement
Guest User

Waves_ex3a

a guest
Oct 26th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. w1 = 5 #1st freq
  5. w2 = 7 # 2nd freq
  6. t_f = 10 # timespan
  7.  
  8. t = np.arange(0,t_f,0.001)
  9.  
  10. wave_a = np.cos( w1*t )
  11. wave_b = np.cos( w2*t )
  12. wave_sum = np.cos( w1*t ) + np.cos( w2*t )
  13. wave_product = 2* np.cos(( w1 + w2)*t/2 ) * np.cos( (w1-w2)*t/2 )
  14.  
  15. plt.figure(1) # initialisierung
  16. p = plt.subplot(3,1,1)
  17. plt.plot(t,wave_a,label=str(w1)+" Hz")
  18. plt.plot(t,wave_b,label=str(w2)+" Hz")
  19. plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
  20.            ncol=2, mode="expand", borderaxespad=0.)
  21.  
  22. p = plt.subplot(3,1,2)
  23. plt.plot(t,wave_sum,label="Summe = cos( w1*t ) + cos( w2*t )")
  24. plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
  25.            ncol=2, mode="expand", borderaxespad=0.)
  26.  
  27. p = plt.subplot(3,1,3)
  28. plt.plot(t,wave_product,label="Produkt = 2* cos( (w1 + w2)*t/2 ) * cos( (w1-w2)*t/2 )")
  29. plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
  30.            ncol=2, mode="expand", borderaxespad=0.)
  31.  
  32. plt.tight_layout()
  33. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement