clc
clear
N=4;                          % Number of the Antennas
K=3;                          % Number of the orthogonal signals
M=100;                        % Number of Worst-case directions
Pt=1;
P=ones(N,1)*Pt;               % Transmit Power of each antenna
Pd=ones(M,1)*(0);               % Desired pattern
Pd(35:55)=100;          % Desired pattern
teta=-pi/2:pi/M:pi/2;


cvx_begin sdp
variable  Ws(N*K) complex;
variable X(N*K,N*K) hermitian;
variable z
minimize (z)
subject to
for i=1:M
    -trace(matA(teta(i),N,K)*X)-z <= -Pd(i);
    trace(matA(teta(i),N,K)*X)-z <= Pd(i);
end

for i1=1:N*K
    SE=zeros(N*K,N*K);
    SE(i1,i1)=1;
    trace(SE*X) == Pt/K;
end

X  >= 0
cvx_end

counter=0;
for teta1=-pi/2:.1:pi/2
    counter=counter+1;
    teyf(counter)=trace(matA(teta1,N,K)*X);
end
plot((-pi/2:.01:pi/2)/pi*180,abs(teyf),'bo')