-
Notifications
You must be signed in to change notification settings - Fork 17
/
Fa2h.py
52 lines (45 loc) · 1.51 KB
/
Fa2h.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 04 17:59:00 2016
from Matlab
@author: Tobias Heinl, Gerald Schuller
Function extracts analysis baseband impulse response (reverse window function)
from the folding matrix Fa of a cosine
modulated filter bank, with modulation function for the analysis IR :
h_k(n)=h(n)*cos(pi/N*(k+0.5)*(L-1-n+0.5-N/2));
"""
def Fa2h(Fa):
""" Function extracts analysis baseband impulse response (reverse window function)
from the folding matrix Fa of a cosine modulated filter bank.
"""
import numpy as np
from polmatmult import polmatmult
[N,y,blocks] = np.shape(Fa)
h0 = np.zeros(blocks * N)
#First column of DCT-4:
T = np.zeros((N,1,1))
T[:,0,0]=np.cos(np.pi/N*(0.5)*(np.arange(N)+0.5))
#Compute first column of Polyphase matrix Pa(z):
Pa = polmatmult(Fa,T)
#Extract impulse response h0(n):
for m in range(blocks):
h0[m*N+np.arange(N)] = np.flipud(Pa[:,0,m])
#Baseband prototype h(n), divide by modulation func.:
#h = h0 / np.cos(np.pi/N*0.5*(np.arange(blocks*N)+ 0.5+(N/2)))
h = -h0 / np.cos(np.pi/N*0.5*(np.arange(blocks*N-1,-1,-1)+ 0.5-(N/2)))
return h;
#Testing:
if __name__ == '__main__':
import numpy as np
from symFmatrix import *
from Dmatrix import *
from polmatmult import *
f=np.arange(1,7)
print("f=", f)
Fa=symFmatrix(f)
N=4
D=Dmatrix(N)
Faz=polmatmult(Fa,D)
print("Faz=", Faz[:,:,0],"\n", Faz[:,:,1])
h=Fa2h(Faz)
print("h=", h)