Correlation-Auto,Cross MATLAB source code
This section of MATLAB source code covers correlation matlab code. correlation types auto and cross correlation basics including matlab function is covered.
Correlation determines how much two signals or vectors are similar or different in phase and magnitude. There are two types auto correlation and cross correlation. correlation is maximum when two signals are similar. correlation is equivalent to multiplying the complex conjugate of frequency spectrum of one signal by the frequency spectrum of the other.
In auto correlation same signal is correlated to itself or with shifted version of it. In cross correlation two different time series signals are correlated.The example below is for cross correlation. If one set both in1 and in2 as same vectors ( or append zeros initially in one) then it becomes auto correlation.
correlation output z[n] = ∑X[k] * Y[n+k]
Setting up input parameters
in2=[9 11 12 13 4 5 16 17 18 19];
Cross correlation MATLAB Code
pad = length(in1)-length(in2);
in2 = [in2 zeros(1,pad)];
pad = length(in2)-length(in1);
in1 = [in1 zeros(1,pad)];
out_len = length(in1);
out = zeros(1,out_len);
tmp = in2;
for k = 1:out_len
out(k) = in1*tmp';
tmp = [0 tmp(1:end-1)];
[m,n]=max(out) % max value in the correlation and its index
MATLAB Built in function-xcorr
z=y(index:1:end); %extacting one side of the result
figure;plot(z);title('MATLAB xcorr function OUTPUT'); % output plot as per matlab function
[m1,n1]=max(z) % max value in the correlation and its index
OUTPUT Plots in MATLAB
Useful Links to MATLAB codes
Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation Time off estimation corr Freq off estimation corr channel estimation 11a WLAN channel PN sequence generation OFDMA Tx Rx AES DES carrier aggregation CCDF FIR Filter IIR Filter Low Pass FIR Viterbi decoder CRC8 CRC32