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 ? Cross-Correlation plot

Thanks !

  • $\begingroup$ 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. $\endgroup$ – Florian Jul 24 at 13:58
  • $\begingroup$ 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 $\endgroup$ – Ymh Jul 24 at 14:14
  • $\begingroup$ 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. $\endgroup$ – Florian Jul 24 at 14:16
  • $\begingroup$ I see your point. My problem is a bit different now. I edited the question $\endgroup$ – Ymh Jul 24 at 14:22
  • $\begingroup$ Thanks Florian for commenting :) $\endgroup$ – Ymh Jul 24 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.