To perform correlation between two signals, you can use ‘xcorr’ function.
In ‘xcorr’, if you provide only one input, output will be the autocorrelation of the signal for different lags.
Here, ‘lags’ array stores the amounts of lags by which the signal is delayed, and ‘c’ array stores the corresponding values of the autocorrelation for that value of delays. Hence, after plotting ‘c’ against ‘lags’, you can visualize the values of autocorrelation at different delays.
To get normalized output (i.e. autocorrelation at zero delay will be 1 (max value when two signals are same) and for other delays it will be normalized with respect to this max value), you can use this command
[c,lags] = xcorr(x,'normalized');
Now, in your case if you are trying to find correlation between two versions of the input signal (one is with amplitude r1=0.6 and delay=5 sec and other is with amplitude r2=0.3 and delay=12 sec), then first generate those using ‘delayseq(input, delay, fs)’ function of ‘Phased Array System Toolbox’. Here, ‘delay’ is in seconds and ‘fs’is the sampling frequency.
x1 = delayseq(x,5,8000)
x2 = delayseq(x,12,8000)
x1 = 0.6*x1;
x2 = 0.3*x2;
Then you can use ‘xcorr’ function to find correlation between them.
[c,lags] = xcorr(x1,x2);
stem(lags,c);
Hope this will help you.
For more information you can follow these links.
Best Answer