Created
January 8, 2018 12:18
-
-
Save RicherMans/6cf412327ced9a23b50ac11baf68ecc4 to your computer and use it in GitHub Desktop.
Assignment3 in dsp coursera course. Efficient matrix implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def subband_filtering(x, h): | |
""" ASSIGNMENT 3 | |
Write a routine to implement the efficient version of the subband filter | |
as specified by the MP3 standard | |
Arguments: | |
x: a new 512-point data buffer, in time-reversed order [x[n],x[n-1],...,x[n-511]]. | |
h: The prototype filter of the filter bank you found in the previous assignment | |
Returns: | |
s: 32 new output samples | |
""" | |
# Time reverse input and muliply by filter response | |
r = np.multiply(h,x) | |
# Reshape for further processing into 64 sub | |
r = r.reshape(-1,64) | |
# The weights, in this case only of size 8 : -1 1 -1 1 ... | |
weights = np.array([1,-1]*4) | |
# do the sum(weights * r[:,q] for q in range(8)) with a matrix multiplication | |
c = np.dot(np.transpose(r),weights) | |
# generate two coordintes, ii and qq, which just loop over the array | |
ii , qq = np.ogrid[:32,:c.shape[0]] | |
# Do \sum cos(....) * c[q], but with .dot | |
s = np.squeeze(np.dot(np.cos(np.pi / 64 * (2*ii +1)*(qq -16)),c[qq].transpose())) | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment