-
Notifications
You must be signed in to change notification settings - Fork 7
/
Opt_absWZ.m
58 lines (40 loc) · 1.41 KB
/
Opt_absWZ.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [W, valueOpt] = Opt_absWZ(Z,numBits)
% Syntex: [W, valueOpt] = Opt_absWZ(Z,numBits)
% Z is a complex vector. The software is to solve max |W^H Z|, where W is
% on unit circle uniformly.
% Author(s): Tiebin Mi, Rujing Xiong
% Date: 09-29-2022
%% check input argument
if ~exist('Z','var')
error('The Z is empty.')
end
if ~exist('numBits','var')
warning('The numBits is empty. Set numBits=4 by default.')
numBits = 4;
end
if ~isvector(Z)
error('Z must be a vector.')
end
%%
numElements = length(Z);
angleWeightRange = 2*pi/2^numBits;
%%
thetaZ = mod(angle(Z),2*pi);
thetaZNormalized = mod(thetaZ,angleWeightRange);
[~, indexThetaZ] = sort(thetaZNormalized,'ascend');
%%
thetaZShift = round((thetaZ-thetaZNormalized)/angleWeightRange);
thetaZShifting = repmat(thetaZShift.',2^numBits*numElements,1);
%%
angleWeightNormalized = zeros(numElements*2^numBits,numElements);
for iPart = 1:1:2^numBits
angleWeightNormalized((iPart-1)*numElements+indexThetaZ, indexThetaZ) = (iPart-1)*ones(numElements,numElements) + triu(ones(numElements,numElements)).';
end
angleWeightNormalized = angleWeightNormalized - thetaZShifting;
angleWeightNormalized = mod(angleWeightNormalized,2^numBits);
%%
weightChecked = exp(1i*angleWeightRange.*angleWeightNormalized);
[valueOpt, indexOpt] = max(abs(weightChecked*Z));
%%
W = weightChecked(indexOpt,:)';
end