Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. """
  2. EX1_WINDOWING Based on the input parameters, generate a n x m matrix of windowed
  3. frames, with n corresponding to frame_length and m corresponding to number
  4. of frames. The first frame starts at the beginning of the data.
  5. """
  6.  
  7. import os
  8. import numpy as np
  9.  
  10. def ex1_windowing(data, frame_length, hop_size, windowing_function):
  11. data = np.array(data)
  12. number_of_frames = None#Calculate the number of frames using the presented formula
  13. frame_matrix = np.zeros((frame_length,number_of_frames))
  14.  
  15. if windowing_function == 'rect':
  16. window = None# Implement this
  17. elif windowing_function == 'hann':
  18. window = None# Implement this
  19. elif windowing_function == 'cosine':
  20. window = None# Implement this
  21. elif windowing_function == 'hamming':
  22. window = None# Implement this
  23. else:
  24. os.error('Windowing function not supported')
  25.  
  26.  
  27. ## Copy each frame segment from data to the corresponding column of frame_matrix.
  28. ## If the end sample of the frame segment is larger than data length,
  29. ## zero-pad the remainder to achieve constant frame length.
  30. ## Remember to apply the chosen windowing function to the frame!
  31. for i in range(number_of_frames):
  32. frame = np.zeros(frame_length) # Initialize frame as zeroes
  33.  
  34. # Implement the rest!
  35.  
  36. frame_matrix[:,i] = frame # Copy frame to frame_matrix
  37. return frame_matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement