% Generation of GM Orthogonolization Waveforms 
clear;clc;close all

stmat = [1 1 1 1;0.5 0.5 -0.5 -0.5;0.5 -0.5 0.5 -0.5 ];% This is the set of sm(t) signals on page 343 of Proakis
stmat = [1 1 1 1 1 1;0.5 0.5 0.5 -0.5 -0.5 -0.5;0.5 0.5 -0.5 -0.5 0.5 0.5];
Tn = length(stmat(1,:));M = length(stmat(:,1));
Ep1 = stmat(1,:)*stmat(1,:)';
Fit1 = stmat(1,:)/sqrt(Ep1);
c21 = stmat(2,:)*Fit1';d2t = stmat(2,:) - c21*Fit1;
Ep2 = d2t*d2t';Fit2 = d2t/sqrt(Ep2);
if d2t < 1e-12;Fit2 = zeros(1,Tn);end
Fitmat = [Fit1;Fit2];
for n = 3:M
    cnis = 0;
for i = 1:n - 1
    cni = stmat(n,:)*Fitmat(i,:)';
    cnis = cnis + cni*Fitmat(i,:);
end
dnt = stmat(n,:) - cnis;
Epn = dnt*dnt';
Fitn = dnt/sqrt(Epn);if dnt < 1e-12;Fitn = zeros(1,Tn);end
Fitmat = [Fitmat;Fitn];
end
Fitmat  
Fitmat(2,:)*Fitmat(3,:)'
s31 = stmat(3,:)*Fitmat(1,:)'
s32 = stmat(3,:)*Fitmat(2,:)'
s33 = stmat(3,:)*Fitmat(3,:)'
