# Finding recorded sub-signal in the original audio signal

I have the original record of a song, and some fragment of the same song recorded by a microphone. I need to find the time where the fragment is appearing in the original. I have tried to use cross-correlation, the results are good but sometimes it gives a completely different part of the song that is similar (same notes but not the same words). How can I solve this problem ? Could the cross-correlation value be higher than the time when the sub-signal is found ? Different approaches are welcome also. Here is my code for the correlation implementation.

#compute correlation
correlation = correlate(reference,signal,mode='valid',method='direct')
#get maximum index
index = np.argmax(corr)
#extract from the reference
extract = reference[index:index + len(sec)]


You can see the highest peak in the beginning, but I know it should be later. How can I find the real signal in this case ?

Thanks !

• What do you mean by "not bad but could be better"? Could you show an example where it fails and explain why it fails? Then maybe we can suggest a solution for this particular problem. – Florian Jul 24 at 13:58
• I mean it gives me a close index, but it is like one or 0.5 seconds off. I need it to be as accurate as possible – Ymh Jul 24 at 14:14
• Well, if done correctly it shouldn't. Maybe your question should be "why is my correlation-based estimator off"? You may have to show a concrete example to understand your problem. – Florian Jul 24 at 14:16
• I see your point. My problem is a bit different now. I edited the question – Ymh Jul 24 at 14:22
• Thanks Florian for commenting :) – Ymh Jul 24 at 14:31