Guest User

Untitled

a guest
Jan 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def subband_filtering(x, h):
  4. """ ASSIGNMENT 3
  5.  
  6. Write a routine to implement the efficient version of the subband filter
  7. as specified by the MP3 standard
  8.  
  9. Arguments:
  10. x: a new 512-point data buffer, in time-reversed order [x[n],x[n-1],...,x[n-511]].
  11. h: The prototype filter of the filter bank you found in the previous assignment
  12.  
  13. Returns:
  14. s: 32 new output samples
  15. """
  16. # Time reverse input and muliply by filter response
  17. r = np.multiply(h,x)
  18. # Reshape for further processing into 64 sub
  19. r = r.reshape(-1,64)
  20. # The weights, in this case only of size 8 : -1 1 -1 1 ...
  21. weights = np.array([1,-1]*4)
  22. # do the sum(weights * r[:,q] for q in range(8)) with a matrix multiplication
  23. c = np.dot(np.transpose(r),weights)
  24. # generate two coordintes, ii and qq, which just loop over the array
  25. ii , qq = np.ogrid[:32,:c.shape[0]]
  26. # Do \sum cos(....) * c[q], but with .dot
  27. s = np.squeeze(np.dot(np.cos(np.pi / 64 * (2*ii +1)*(qq -16)),c[qq].transpose()))
  28. return s
Add Comment
Please, Sign In to add comment