Invalid quadratic form: product is complex. Thanks

This is a beamforming problem. I am confused with this error for long. I will appreciate it if someone can help me.

clear all;

% select array geometry
ARRAY_GEOMETRY = ‘1D_UNIFORM_LINE’;
% ARRAY_GEOMETRY = ‘1D_UNIFORM_LINE’;
% ARRAY_GEOMETRY = ‘2D_UNIFORM_LATTICE’;

%********************************************************************
% problem specs
%********************************************************************
lambda = 1; % wavelength
theta_tar = 0; % target direction (should be an integer – discretization)
half_beamwidth = 10; % half beamwidth around the target direction
L = 20; % number of filter taps at each antenna element
fs = 50000; % sampling rate = 8000 Hz
T = 1/fs; % sampling spacing
c = 1500; % wave speed
i=sqrt(-1);
theta_tar = 0; % target direction
half_beamwidth = 10; % half beamwidth around the target direction
f_low = 7500; % low frequency bound for the desired band
f_high = 25000; % high frequency bound for the desired band
min_sidelobe =-20;
deta = 0.01;
theta_inf = 50;
%********************************************************************
% random array of n antenna elements

%********************************************************************
% uniform 1D array with n elements with inter-element spacing d
%********************************************************************
if strcmp( ARRAY_GEOMETRY, ‘1D_UNIFORM_LINE’ )
% (unifrom array on a line)
n = 10;
d=1/3c/f_high;
%d = 0.45
lambda;
loc = [d*[0:n-1]’ zeros(n,1)];
angleRange = 180;
end
%********************************************************************
% construct optimization data
%********************************************************************
% build matrix A that relates w and y(theta), ie, y = A*w

numtheta = 180;
numfreqs = 20;

theta = linspace(-90,90,numtheta)’;
freqs = linspace(f_low,f_high,numfreqs)’;

for k = 1:3:numfreqs
% FIR portion of the main matrix
Afir = kron( ones(numtheta,n), [0:L-1]/fs );

% cos/sine part of the main matrix
Alocx = kron(loc(:,1)’, ones(1,L) );

Aloc = kron( sin(pitheta/180)/c, Alocx )
% create the main matrix for each frequency sample
A(:,:,k) = exp(-2
piifreqs(k)(Afir+Aloc));
% Atotal(:,:,k) = exp(2
piifreqs(k)*(Aloc));
end
% target constraint matrix
[diff_closest, ind_closest] = min( abs(theta - theta_tar) );
Atar = A(ind_closest,:,:);

% stopband constraint matrix
ind = find(theta <= (theta_tar-half_beamwidth) | …
theta >= (theta_tar+half_beamwidth) );

As = A(ind,:,:);

sum = 0
for k =1:3:numfreqs
for i = 1:length(ind)
sum = sum + As(i,:,k)’*As(i,:,k)
end
end

%********************************************************************
% optimization problem
%********************************************************************
cvx_begin
variable w(n*L) complex

minimize(abs(w’sumw))
subject to
for k = 1:3:numfreqs
Atar(:,:,k)w == 1%Atar(:,:,k)w == sin(102pi*freqs(k)/fs); % target constraint
A(theta_inf,:,k)w < deta
end
cvx_end
%
*******************************************************************
% plots
%********************************************************************

% plot array pattern
%
for k = 1:3:numfreqs
res(:,k) = w;

y = abs(A(:,:,k)*res(:,k));
y = y./max(y)


plot(theta, 20*log10(abs(y)))

axis([-90 90 -50 0]);

xlabel('look angle'), ylabel('mag y(theta) in dB');
hold on;
end

I believe your error message is due to numerical inaccuraciy. sum came out exactly hermitian for me, and with min eigenvalue -2.8e-11 (“almost” semidefinite). If sum is even slightly non-hermitian, you will get the error message you got. So symmetrize sum before use to avoid this error.

Removing abs from the objective function allowed it to be accepted by CVX. Apparently, the -2.8e-11 eigenvalue didn’t cause a problem. However, subtracting 1e-10*eye(200) from sum was enough to produce an error message (The second argument must be positive or negative semidefinite.). So perhaps you might need to add a small multiple of eye(200) to sum to make it work, even though I didn’t.

A(theta_inf,:,k)*w < deta is an “illegal” inequality with complex on the LHS and real on the RHS. Changing this to real(A(theta_inf,:,k)*w) <= deta alllowedi it to be accepted by CVX, and CVX solved the problem. I leave it to you to determine whether that is the correct problem to have solved.