Skip to content
This repository was archived by the owner on Feb 13, 2020. It is now read-only.

Commit 3852a3b

Browse files
committed
Fix matrix problem, but only fmclt, fmclt2, fimcl, and fimclt2 are fixed in audioWatermarking.py
1 parent 8772be2 commit 3852a3b

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

audioWatermarking.py

+38-13
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,61 @@ def compExpo(M, r):
6767
def fmclt(x):
6868
# MCLT of a single vector
6969
M = len(x)/2
70-
U = np.float64(np.sqrt(1/(2*M))) * np.fft.fft(x)
71-
k = np.array(range(0, M+1), dtype=np.float64)
72-
c = AudioWatermarkingMCLT.compExpo(8, 2*k+1) * AudioWatermarkingMCLT.compExpo(4*M, k)
73-
V = c * U[0:M+1]
70+
U = np.matrix(np.sqrt(1/(2*M)) * np.fft.fft(x))
71+
k = np.matrix(range(0, M+1), dtype=np.float64).reshape(-1, 1)
72+
c = np.multiply(AudioWatermarkingMCLT.compExpo(8, 2*k+1), AudioWatermarkingMCLT.compExpo(4*M, k))
73+
V = np.multiply(c, U[0:M+1])
7474
X = 1j * V[0:M] + V[1:M+1]
7575
return X
7676

7777
@staticmethod
7878
def fmclt2(frameMat, c):
7979
# MCLT of a frame matrix
8080
M = frameMat.shape[0]/2
81-
X = np.zeros((M, frameMat.shape[1]), dtype=np.complex_)
81+
X = np.matrix(np.zeros((M, frameMat.shape[1]), dtype=np.complex_))
8282
for i in range(frameMat.shape[1]):
83-
U = np.float64(np.sqrt(1/(2*M))) * np.fft.fft(frameMat[:, i])
84-
V = c * U[0:M+1]
83+
U = np.matrix(np.sqrt(1/(2*M)) * np.fft.fft(frameMat[:, i]))
84+
V = np.multiply(c, U[0:M+1])
8585
X[:, i] = 1j * V[0:M] + V[1:M+1]
8686
return X
8787

8888
@staticmethod
8989
def fimclt(X):
9090
M = len(X)
91-
Y = np.zeros((2*M,), dtype=np.complex_)
92-
k = np.array(range(1, M), dtype=np.float64)
93-
c = AudioWatermarkingMCLT.compExpo(8, 2*k+1) * AudioWatermarkingMCLT.compExpo(4*M, k)
94-
Y[1:M] = (1/4) * np.conj(c) * (X[0:M-1] - 1j * X[1:M])
91+
Y = np.matrix(np.zeros((2*M, 1), dtype=np.complex_))
92+
k = np.matrix(range(1, M), dtype=np.float64).reshape(-1, 1)
93+
c = np.multiply(AudioWatermarkingMCLT.compExpo(8, 2*k+1), AudioWatermarkingMCLT.compExpo(4*M, k))
94+
Y[1:M] = (1/4) * np.multiply(np.conj(c), (X[0:M-1] - 1j * X[1:M]))
9595
Y[0] = np.sqrt(1/8) * (X[0].real + X[0].imag)
9696
Y[M] = -np.sqrt(1/8) * (X[M-1].real + X[M-1].imag)
9797
Y[M+1:2*M] = np.conj(Y[range(M-1, 0, -1)])
98-
y = np.fft.ifft(np.sqrt(2*M) * Y).real
99-
return y
98+
yBar = np.matrix(np.fft.ifft(np.sqrt(2*M) * Y).real)
99+
return yBar
100+
101+
@staticmethod
102+
def fimclt2(X, awmOpt):
103+
M = X.shape[0]
104+
Y = np.matrix(np.zeros((2*M, 1), dtype=np.complex_))
105+
yBar = np.matrix(np.zeros((2*M, X.shape[1]), dtype=np.float64))
106+
k = np.matrix(range(1, M), dtype=np.float64).reshape(-1, 1)
107+
c = np.multiply(AudioWatermarkingMCLT.compExpo(8, 2*k+1), AudioWatermarkingMCLT.compExpo(4*M, k))
108+
# fast inverse mclt
109+
for i in range(0, X.shape[1]):
110+
Y[1:M] = (1/4) * np.multiply(np.conj(c), (X[0:M-1, i] - 1j * X[1:M, i]))
111+
Y[0] = np.sqrt(1/8) * (X[0, i].real + X[0, i].imag)
112+
Y[M] = -np.sqrt(1/8) * (X[M-1, i].real + X[M-1, i].imag)
113+
Y[M+1:2*M] = np.conj(Y[range(M-1, 0, -1)])
114+
yBar[:, i] = np.matrix(np.fft.ifft(np.sqrt(2*M) * Y).real)
115+
116+
# overlap add
117+
for i in range(1, yBar.shape[1]-1):
118+
yBar[:, i] = np.vstack((yBar[awmOpt.frameSize/2:, i-1], yBar[0:awmOpt.frameSize/2, i+1])) + yBar[:, i]
119+
# deal with first and last frame
120+
yBar[awmOpt.frameSize/2:, 0] = yBar[awmOpt.frameSize/2:, 0] + yBar[0:awmOpt.frameSize/2, 1]
121+
yBar[0:awmOpt.frameSize/2, -1:] = yBar[0:awmOpt.frameSize/2, -1:] + yBar[awmOpt.frameSize/2:, -2]
122+
output = np.vstack((yBar[:, 0], yBar[awmOpt.frameSize/2:, 1:].reshape(-1, 1)))
123+
return output
124+
100125

101126
@staticmethod
102127
def string2binary(message):

awmOptSet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, method):
1111
self.spreadLen = 36
1212
self.overlap = 512
1313
self.data = 'Mirlab'
14-
self.syncSeq = np.array([[1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1], [1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1, 1, -1], [1, -1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1], [-1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 1, -1], [-1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1], [-1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1]])
14+
self.syncSeq = np.matrix([[1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1], [1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1, 1, -1], [1, -1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1], [-1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 1, -1], [-1, -1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1], [-1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1]])
1515
self.method = 'mclt'
1616
elif method == 'dct':
1717
pass

awmPython.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def main():
1111
fs, au = util.audioread('./testAudio/classical.wav')
1212
frame = util.enframe(au, awmOpt.frameSize, awmOpt.overlap)
1313
M=512
14-
fmcltk = np.array(range(0, M+1), dtype=np.float64)
15-
fmcltc = awm.compExpo(8, 2*fmcltk+1) * awm.compExpo(4*M, fmcltk)
14+
fmcltk = np.matrix(range(0, M+1), dtype=np.float64).reshape(-1, 1)
15+
fmcltc = np.multiply(awm.compExpo(8, 2*fmcltk+1), awm.compExpo(4*M, fmcltk))
1616
X = awm.fmclt2(frame, fmcltc)
1717
print(X.shape)
1818
print(X.dtype)

util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ def audioread(fileName):
4141
else:
4242
au = np.matrix(au.astype(np.float64)).reshape(au.shape[0], -1)
4343
'''
44-
return (fs, au, bitPerSample)
44+
return (fs, au)
4545

4646
def main():
4747
import os
4848
fileList = os.listdir('./testAudio/')
4949
for i in fileList:
50-
fs, au, bitPerSample = audioread(os.path.join(os.getcwd(), 'testAudio', i))
50+
fs, au = audioread(os.path.join(os.getcwd(), 'testAudio', i))
5151
print('==========================')
5252
print(i)
53-
print(bitPerSample)
5453
print(au.dtype)
5554
print(au.shape)
55+
print(au[44100])
5656
print('==========================')
5757

5858

0 commit comments

Comments
 (0)