how to plot the auto and cross correlation of walsh hadamard codes

4 次查看(过去 30 天)
i need a program to plot auto and cross corelation of walsh hadamard codes please
i have this program to generate a Walsh Hadamard Matrix of given codeword size=64
codeSize=64;
N=2;
H=[0 0 ; 0 1];
if bitand(codeSize,codeSize-1)==0
while(N~=codeSize)
N=N*2;
H=repmat(H,[2,2]);
[m,n]=size(H);
for i=m/2+1:m
for j=n/2+1:n
H(i,j)=~H(i,j);
end
end
end
else
disp('INVALID CODE SIZE:The code size must be a power of 2');
end

回答(1 个)

vidyesh
vidyesh 2024-9-5
编辑:vidyesh 2024-9-5
Hello Yas Mine,
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.
H = hadamard(8);
[c,lags] = xcorr(H(2));
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’, we can visualize the values of autocorrelation at different delays.
Now, in our case, you are trying to find auto and cross correlation between the hadamard codes:
x1 = H(2,:);
x2 = H(3,:);
Then use ‘xcorr’ function to find cross correlation between them.
[c,lags] = xcorr(x1,x2);
stem(lags,c);
I would also advise to change 0 to -1 when you are first declaring 'H' and replace the line inside the nested for loop:
% H(i,j)=~H(i,j);
with
% H(i,j)= -1 *H(i,j);
Hope this will help you.
For more information you can follow these links.

Community Treasure Hunt

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

Start Hunting!

Translated by