MATLAB Answers

Why do I get a wrong XCORR result?

4 views (last 30 days)
Sapio L
Sapio L on 17 Aug 2016
Edited: Sapio L on 17 Aug 2016
There are two different audio signals. They contain approximately same context. The goal is to align them using xcorr. In the documentation, it is written that Fs=11025 Hz and there is no any additional info about it. However, while using some data, the result can be very weird.
Can I change Fs = 11025 Hz? Or is it not allowed?
Please see a code:
[Fs1, T1] = audioread('audio1.mp3'); [Fs2, T2] = audioread('audio2.mp3');
DelayTime= finddelay(Fs1,Fs2);
%Find mean of Nx2 matrix & convert to 1xN vector Mean_410= mean(Fs1,2); Mean_422= mean(Fs2,2);
Fs=11025; %As a default, Fs=11025Hz;
%Helps to plot, otherwise T1 & T2 are just numbers. %Plot each signal T1 = (0:length(Fs1)-1)/Fs; T2 = (0:length(Fs2)-1)/Fs;
%figure subplot(2,1,1) %plot(T1, Fs1) title('s_1')
subplot(2,1,2) %plot(T2, Fs2) title('s_2') xlabel('Time (s)')
%Plot the cross-correlation. %Express the delay as a number of samples and in seconds [acor,lag] = xcorr(Mean_422,Mean_410');
[~,I] = max(abs(acor)); lagDiff = abs(lag(I)) %difference in samples timeDiff = lagDiff/Fs %difference in seconds %what we need
%figure %plot(lag,acor) a3 = gca; a3.XTick = sort([-3000:1000:3000 lagDiff]);
%Align the two signals and replot them s1al = Fs1(abs(lagDiff):end); t1al = (0:length(s1al)-1)/Fs;

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!