JoelSjogren

stern-brocot wave

Jul 9th, 2017
351
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. def fracseq(n):
  2.     a = [0, 1]
  3.     for _ in range(n):
  4.         b = [0] * (len(a) * 2 - 1)
  5.         for i in range(len(a)-1):
  6.             b[2*i] = a[i]
  7.             b[2*i+1] = a[i]+a[i+1]
  8.         b[-1] = a[-1]
  9.         a = b
  10.     return a
  11.  
  12. n = 8
  13. fs = fracseq(n)
  14. zw = [x+y*1j for x, y in zip(reversed(fs), fs)]
  15.  
  16. def Q(z):
  17.     return z.real*z.real + z.imag*z.imag
  18.  
  19. def sample(z, w):
  20.     return z*z*w*w/Q(z*w)
  21.  
  22. sb = [sample(z, w) for z, w in zip(zw[:-1], zw[1:])]
  23.  
  24. sb_real = [v.real for v in sb]
  25. sb_imag = [v.imag for v in sb]
  26.  
  27. def writesamples(s):
  28.     import scipy.io.wavfile
  29.     scipy.io.wavfile.write('out.wav', 41000,
  30.         scipy.array(s, dtype='float32'))
  31.  
  32. writesamples(sb_imag * 10**3)
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment