📄 walshhadmard.m
字号:
% Program to generate Walsh-Hadamard codes.
% These codes are orthogonal codes and when used in synchronous CDMA
% produce zero interference between signal carried by same RF frequency.
clc
clear
code_length=32; % length of each code word: you can change.
code=[-1 -1; -1 +1]; % Initialization: -1=0 and +1=1
[r1 c1]=size(code);
while r1<code_length
% loop#1: Copying the code matrix itself below for new code matrix
for i=1:r1
for j=1:c1
code(i+r1,j)=code(i,j);
end
end
% Loop#2: Copying the code matrix on right to itself for new matrix
for j=1:c1
for i=1:r1
code(i,j+c1)=code(i,j);
end
end
% Loop#3: Copying cojugate of code matrix for complentary diagonal part
for i=1:r1
for j=1:c1
code(i+r1,j+c1)=-1*code(i,j);
end
end
[r1 c1]=size(code);
end
% Checking mutual orthogonality of all rows
sum=0;
data=[];
rows=[];
for i=1:r1
A=code(i,:);
for j=1:r1
B=code(j,:);
for k=1:c1
sum=sum+A(k)*B(k);
end
data=[data sum];
sum=0;
end
count=0;
for h=1:length(data)
if data(h)>0
count=count+1;
end
end
data=[];
if count<=1
rows=[rows i];
end
end
if length(rows)==r1
fprintf('All rows are orthgnal with each other')
else
fprintf('Following given rows are orthognal with each other')
rows
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -