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

Commit cf8e91f

Browse files
Chih-Kai YuChih-Kai Yu
Chih-Kai Yu
authored and
Chih-Kai Yu
committed
Fix reshape problem. Add findSyncFast, but still not working
1 parent b8b7a62 commit cf8e91f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

audioWatermarking.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def singleChannelEmbed(au, awmOpt):
2424
A1 = C2 * W2 * W1 * S1.transpose()
2525
B_1 = S1 * W1 * W2 * C2.transpose()
2626
B1 = S2 * W2 * W1 * C1.transpose()
27-
sync = awmOpt.syncSeq.reshape(int((awmOpt.syncFreqBand[1]-awmOpt.syncFreqBand[0])/2+1) , -1)
27+
sync = awmOpt.syncSeq.reshape(-1, int((awmOpt.syncFreqBand[1]-awmOpt.syncFreqBand[0])/2+1)).T
2828
dataSeq = AudioWatermarkingMCLT.string2binary(awmOpt.data)
2929
bitPerFrame = int((awmOpt.dataFreqBand[1]-awmOpt.dataFreqBand[0]+1) / awmOpt.spreadLen)
3030
syncFrameSize = int(np.size(sync) / ((awmOpt.syncFreqBand[1]-awmOpt.syncFreqBand[0])/2+1)*2)
@@ -36,7 +36,7 @@ def singleChannelEmbed(au, awmOpt):
3636
zeroToBePadded = np.zeros((1, dataFrameSize*bitPerFrame-np.size(dataSeq)), dtype=int)
3737
remainPart = np.size(zeroToBePadded)
3838
dataSeq = np.concatenate((dataSqe, zeroToBePadded), 1)
39-
data = np.kron(np.ones((awmOpt.spreadLen, 1)), dataSeq).reshape(awmOpt.dataFreqBand[1]-awmOpt.dataFreqBand[0]+1, -1)
39+
data = np.kron(np.ones((awmOpt.spreadLen, 1)), dataSeq).T.reshape(-1, awmOpt.dataFreqBand[1]-awmOpt.dataFreqBand[0]+1).T
4040

4141
# fast MCLT
4242
#fmcltk = np.array(range(0, M+1), dtype=np.float64)
@@ -74,6 +74,26 @@ def singleChannelEmbed(au, awmOpt):
7474

7575
#def awmExtract(self):
7676

77+
@staticmethod
78+
def findSyncFast(y, base, length, awmOpt):
79+
M = int(awmOpt.frameSize/2)
80+
cor = np.matrix(np.zeros((length, 1), dtype=np.complex_))
81+
sync = awmOpt.syncSeq.reshape(-1, int((awmOpt.syncFreqBand[1]-awmOpt.syncFreqBand[0])/2+1)).T
82+
syncFrameSize = int(np.size(sync) / ((awmOpt.syncFreqBand[1]-awmOpt.syncFreqBand[0])/2+1)*2)
83+
i = np.arange(1, syncFrameSize, 2)
84+
k = np.arange(awmOpt.syncFreqBand[0], awmOpt.syncFreqBand[1]+1, 2)
85+
86+
fmcltk = np.array(range(0, M+1), dtype=np.float64)
87+
fmcltc = AudioWatermarkingMCLT.compExpo(8, 2*fmcltk+1) * AudioWatermarkingMCLT.compExpo(4*M, fmcltk)
88+
for i in range(base, base+length):
89+
truncated = util.enframe(y[i:i+(syncFrameSize-1)*512+1024], awmOpt.frameSize, awmOpt.overlap)
90+
embed = AudioWatermarkingMCLT.fmclt3(truncated, fmcltc)
91+
cor[i-base, 0] = np.sum(np.divide(np.multiply(embed[k, j], sync), np.absolute(embed[k, j])))
92+
return cor
93+
94+
95+
96+
7797
@staticmethod
7898
def compExpo(M, r):
7999
return np.exp(-1j*2*np.pi*r/M)
@@ -106,7 +126,7 @@ def fmclt2(frameMat):
106126
@staticmethod
107127
def fmclt3(frameMat, c):
108128
# MCLT of a frame matrix
109-
M = frameMat.shape[0]/2
129+
M = int(frameMat.shape[0]/2)
110130
X = np.matrix(np.zeros((M, frameMat.shape[1]), dtype=np.complex_))
111131
for i in range(frameMat.shape[1]):
112132
U = np.matrix(np.sqrt(1/(2*M)) * np.fft.fft(frameMat[:, i].T)).T

awmOptSet.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def __init__(self, method):
1212
self.spreadLen = 36
1313
self.overlap = 512
1414
self.data = 'Mirlab'
15-
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]])
15+
#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]])
16+
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])
1617
self.method = 'mclt'
1718
elif method == 'dct':
1819
pass

0 commit comments

Comments
 (0)