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

Commit 98ad817

Browse files
committed
extractMCLT is done and tested
1 parent 1338558 commit 98ad817

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

audioWatermarking.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,32 @@ def singleChannelEmbed(au, awmOpt):
7373
return output
7474

7575
#def awmExtract(self):
76-
76+
77+
@staticmethod
78+
def extractMCLT(y, index, awmOpt):
79+
dataSeq = AudioWatermarkingMCLT.string2binary(awmOpt.data)
80+
bitPerFrame = int((awmOpt.dataFreqBand[1]-awmOpt.dataFreqBand[0]+1) / awmOpt.spreadLen)
81+
syncFrameSize = int(np.size(awmOpt.syncSeq) / ((awmOpt.syncFreqBand[1]-awmOpt.syncFreqBand[0])/2+1)*2)
82+
dataFrameSize = int(np.ceil(np.size(dataSeq)/bitPerFrame))
83+
blockSize = syncFrameSize + dataFrameSize
84+
tmp = util.enframe(y[index:index+(blockSize-1)*(awmOpt.frameSize-awmOpt.overlap)+awmOpt.frameSize], awmOpt.frameSize, awmOpt.overlap)
85+
block = AudioWatermarkingMCLT.fmclt2(tmp)
86+
cipher = np.matrix(np.zeros((1, bitPerFrame*dataFrameSize), dtype=np.int))
87+
count = 0
88+
rowIndex = np.arange(awmOpt.dataFreqBand[0], awmOpt.dataFreqBand[1]+1, awmOpt.spreadLen)
89+
for i in range(syncFrameSize, block.shape[1]):
90+
for j in range(bitPerFrame):
91+
positive = len(np.nonzero(np.sign(block[rowIndex[j]:rowIndex[j]+awmOpt.spreadLen, i].real) == 1)[0])
92+
negative = len(np.nonzero(np.sign(block[rowIndex[j]:rowIndex[j]+awmOpt.spreadLen, i].real) == -1)[0])
93+
if positive >= negative:
94+
cipher[0, count] = 1
95+
else:
96+
cipher[0, count] = -1
97+
count = count + 1
98+
if (dataSeq.shape[1] % bitPerFrame) != 0:
99+
cipher = cipher[0, 0:dataSeq.shape[1]]
100+
return cipher
101+
77102
@staticmethod
78103
def findSyncFast(y, base, length, awmOpt):
79104
M = int(awmOpt.frameSize/2)
@@ -91,9 +116,6 @@ def findSyncFast(y, base, length, awmOpt):
91116
cor[i-base, 0] = np.sum(np.divide(np.multiply(embed[np.ix_(k, j)], sync), np.absolute(embed[np.ix_(k, j)])))
92117
return cor
93118

94-
95-
96-
97119
@staticmethod
98120
def compExpo(M, r):
99121
return np.exp(-1j*2*np.pi*r/M)
@@ -215,11 +237,12 @@ def main():
215237
awmOpt = awmOptSet('mclt')
216238
output = AudioWatermarkingMCLT.singleChannelEmbed(au, awmOpt)
217239
startTime = time.time()
218-
cor = AudioWatermarkingMCLT.findSyncFast(output, 0, 44100, awmOpt)
240+
cor = AudioWatermarkingMCLT.findSyncFast(output, 0, 100, awmOpt)
219241
print('Elapsed time: %s\n', (time.time() - startTime))
220-
scipy.io.savemat('cor.mat', {'cor': cor})
221-
print(cor.shape)
222-
print(cor.dtype)
242+
pos = np.nonzero(cor.real > 100)
243+
ci = AudioWatermarkingMCLT.extractMCLT(output, pos[0][0], awmOpt)
244+
plain = AudioWatermarkingMCLT.cipher2plain(ci)
245+
print(plain)
223246

224247
if __name__ == '__main__':
225248
main()

0 commit comments

Comments
 (0)