from Walsh Hadmard code generation by Islam Mohammed
generate Walsh code

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.
% Original File produced by Imran Ali 
% Optimization for the code by Islam mohammed
clc
clear
code_length=100;             % 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 
    % this line is equivelant to the next 3 loops
    code = [code,code;code,-1*code];
    
%     % 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
% this part is just verification you my disable it. 
% 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

Contact us at files@mathworks.com