Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- EX1_WINDOWING Based on the input parameters, generate a n x m matrix of windowed
- frames, with n corresponding to frame_length and m corresponding to number
- of frames. The first frame starts at the beginning of the data.
- """
- import os
- import numpy as np
- def ex1_windowing(data, frame_length, hop_size, windowing_function):
- data = np.array(data)
- number_of_frames = None#Calculate the number of frames using the presented formula
- frame_matrix = np.zeros((frame_length,number_of_frames))
- if windowing_function == 'rect':
- window = None# Implement this
- elif windowing_function == 'hann':
- window = None# Implement this
- elif windowing_function == 'cosine':
- window = None# Implement this
- elif windowing_function == 'hamming':
- window = None# Implement this
- else:
- os.error('Windowing function not supported')
- ## Copy each frame segment from data to the corresponding column of frame_matrix.
- ## If the end sample of the frame segment is larger than data length,
- ## zero-pad the remainder to achieve constant frame length.
- ## Remember to apply the chosen windowing function to the frame!
- for i in range(number_of_frames):
- frame = np.zeros(frame_length) # Initialize frame as zeroes
- # Implement the rest!
- frame_matrix[:,i] = frame # Copy frame to frame_matrix
- return frame_matrix
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement