You are on page 1of 2

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

## %%%%%% Generation of Hadamard Matrix %%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% Hadamard matrix of oder N is recursively defined as
%%%%% H(N) =
%%%%% [ H(N/2) H(N/2)
%%%%% [ H(N/2) -H(N/2)]
%%%%%% By definition H(1) = 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Hadamard matrix finds use in signal processing
%%%% One interesting property of Hadamard matrix is
%%%% H(N) * H(N)' = N * I ; I is N*N identity matrix
%%%%%%%%%%%% MATLAB has built-in function hadamard(n)
%%%%% S.R. Bhide
%%%%% 2 April , 2011
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Uses user created functions as follows:-
%%%%% function [is_pow2]= my_is_pow2(n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear ,clc
n=8;
fprintf('Hadamard matrix of %d x %d \n',n,n)
else
fprintf('You asked for Hadamard matrix of size n = %d\n ', n)
fprintf('By definition, Hadamard matrix is n x n where n is power of 2')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if (my_is_pow2(n))~= 1
% disp(' argument must be power of 2');
% return
% end
% if ( n==1)
%
% else
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function [is_pow2]=my_is_pow2(n)
% nnn =log2(n);
% nn = round(nnn);
% if ( nnn - nn ) == 0
% is_pow2 = 1 ;
% else
% is_pow2 = 0;
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

1
Hadamard matrix of 8 x 8
1 1 1 1 1 1 1 1
1 -1 1 -1 1 -1 1 -1
1 1 -1 -1 1 1 -1 -1
1 -1 -1 1 1 -1 -1 1
1 1 1 1 -1 -1 -1 -1
1 -1 1 -1 -1 1 -1 1
1 1 -1 -1 -1 -1 1 1
1 -1 -1 1 -1 1 1 -1

ans =
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1