K F U P & M: Name: Syed Awais Wahab Shah ID: 201303510

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

KING FAHD UNIVERSITY OF PETROLEUM & MINERALS

DIGITAL COMMUNICATIONS I
ASSIGNMENT 1

Name: Syed Awais Wahab Shah
ID: 201303510

Task: Matlab code for Gram-Schmidth Process, also show No. of orthonormal vectors and verify that
vectors are orthonormal to each other.
Solution:
% v is the input matrix of m * n
% where m = No. of elements of vectors
% and n = No. dimensions of vectors
% u is the output orthonormal matrix of order m * min(m,n)
function gram_schmidth(v)
n=size(v); %this will extract the index of v
u=zeros(n(1), min(n)); %initally making output matrix zero
for i=1:min(n) %loop from 1 to min(m,n)
x=zeros(n(1),1); %vector for computing projections
for j=1:i %loop for computing projections
x=x+(v(:,i)'*u(:,j))*u(:,j); %sum of projections
end
u(:,i)=v(:,i)-x; %subtract projections from vector
u(:,i)=u(:,i)/norm(u(:,i)); %normalizing to get unit vector
end
sprintf('No. of Orthonormal Vectors are %d', length(u(1,:)))
disp('Orthogonal vectors are')
u
%Verification of orthonormality of vectors
flag=0; %flag for orthonormality
for i=2:length(u(1,:))
for j=1:i-1
if(u(:,i)'*u(:,j)>0.1) %condition of orthonormality
sprintf('vector %d is not orthogonal to %d',i,j)
flag=1;
end
end
end
if(flag==0)
disp('all vectors are orthonormal to each other')
end

You might also like