├── Array_Thinning_With_Natural_Selection_Genetic_Algorithm.m
├── HFSS_pattern_import.m
├── Initial_ULA.m
├── LICENSE
├── PSO_on_Linear_Array_For_Null.m
├── PSO_on_Linear_Array_For_SLL.m
├── Pattern_Visualization.m
├── Plot_Circular_Array_Response.m
├── Plot_Circular_Array_With_Element_Response.m
├── Plot_Linear_Array_Response.m
├── Plot_Linear_Array_With_Element_Response.m
├── Plot_Planar_Array_Response.m
├── Plot_Planar_Array_With_Element_Response.m
├── README.md
├── SLC_on_Linear_Array_For_Null.m
├── Test_Array
├── Far_Field_Data
│ └── 5ELx2 FarField Tx Only.mat
├── Near_Field_Data
│ └── 5ELx2 1meter NearField Tx Only.mat
├── PSO_Cancellation.m
├── Power_Point
│ └── 2x5 Element Array NF Datas.pptx
├── ReadTouchstone.m
└── S_Parameters
│ ├── 5ELx2 NearField 1 to 6G.s10p
│ ├── 5ELx2 NearField 20 to 500M.s10p
│ └── 5ELx2 NearField 500M to 1G.s10p
├── Uniform_Circular_Array.m
├── Uniform_Linear_Array.m
├── Uniform_Planar_Array.m
├── generate_HFSS_field_vectors.m
└── generate_phi_theta.m
/Array_Thinning_With_Natural_Selection_Genetic_Algorithm.m:
--------------------------------------------------------------------------------
1 | clear all
2 | clc
3 |
4 | freq_range = [24e9 28e9]; % [start_frequency stop_frequency] [Hz]
5 | freq_points = 101; % No. of frequency points
6 | d = 0.005353; % Element spacing [m]
7 | N_elements_per_side = 10;
8 | weights = ones(N_elements_per_side, N_elements_per_side); % Amplitude weights for N elements from 0 to 1
9 |
10 | freq_step = (freq_range(2) - freq_range(1)) / (freq_points - 1);
11 | frequency_vector = freq_range(1):freq_step:freq_range(2);
12 | theta_vector_degrees = -90:1:90;
13 | theta_vector_rads = theta_vector_degrees * (pi / 180);
14 |
15 | phi_val = 0;
16 | for n = 1:1:length(frequency_vector)
17 | frequency = frequency_vector(n);
18 |
19 | % create omnidirectional characteristic
20 | iPattern = zeros(1, length(theta_vector_degrees));
21 |
22 | % Calculate Array Factor
23 | for nn = 1:1:length(theta_vector_rads)
24 | [AF, AF_dB, AV] = Uniform_Planar_Array(phi_val*(pi / 180), theta_vector_rads(nn), frequency, d, weights);
25 | weight_vs_angle{n}{nn} = {theta_vector_rads(nn), AV};
26 | %Combine for full characteristics
27 | F(n, nn) = AF_dB + iPattern(nn);
28 | end
29 | end
30 |
31 | figure(2);
32 | plot(theta_vector_degrees, F(end,:));
33 | hold on
34 |
35 | pel = findpeaks(F(end, :), theta_vector_degrees, 'NPeaks', 2, 'SortStr', 'descend');
36 | sllopt = pel(1) - pel(2);
37 |
38 | % Array Thining using the Natural Selection Genetic Algorithm
39 | % References
40 | % Randy L. Haupt, Thinned Arrays Using Genetic Algorithms,
41 | % IEEE Transactions on Antennas and Propagation, Vol 42, No 7, 1994
42 | % Randy L. Haupt, An Introduction to Genetic Algorithms for Electromagnetics,
43 | % IEEE antennas and Propagation Magazine, Vol 37, No 2, 1995
44 | % Harry L. Van Trees, Optimum Array Processing, Wiley-Interscience, 2002
45 |
46 |
47 | % Set random number generator for repeatibility
48 | rng_state = rng(2013, 'twister');
49 |
50 | % Set active / inactive weight matrix for only 1/4 of the array since it is
51 | % symmetric about both axes using uniform distribution
52 | rows = N_elements_per_side / 2;
53 | columns = N_elements_per_side / 2;
54 | candidates_per_generation = 200;
55 | w0 = double(rand(rows, columns, candidates_per_generation, 'double') > 0.5);
56 | % Set the inner N_elements_per_side / 4 elements to active and the outer
57 | % ones to random activity, this is so that we have a decent generation to
58 | % start with
59 | w0(1:idivide(rows, int32(2)), 1:idivide(columns , int32(2)), :) = 1;
60 |
61 | %Single Iteration Example
62 | % Pick one random candidate, plot the beam pattern, and compute the sidelobe
63 | % level
64 | wtemp = w0(:, :, randi(candidates_per_generation));
65 | weights = [fliplr(flipud(wtemp)) flipud(wtemp); fliplr(wtemp) wtemp];
66 |
67 | for n = 1:1:length(frequency_vector)
68 | frequency = frequency_vector(n);
69 |
70 | % create omnidirectional characteristic
71 | iPattern = zeros(1, length(theta_vector_degrees));
72 |
73 | % Calculate Array Factor
74 | for nn = 1:1:length(theta_vector_rads)
75 | [AF, AF_dB, AV] = Uniform_Planar_Array(phi_val*(pi / 180), theta_vector_rads(nn), frequency, d, weights);
76 | weight_vs_angle{n}{nn} = {theta_vector_rads(nn), AV};
77 | %Combine for full characteristics
78 | F(n, nn) = AF_dB + iPattern(nn);
79 | end
80 | end
81 |
82 | figure(2);
83 | plot(theta_vector_degrees, F(end,:));
84 |
85 | pel = findpeaks(F(end, :), theta_vector_degrees, 'NPeaks', 2, 'SortStr', 'descend');
86 | sllopt = pel(1) - pel(2);
87 |
88 | fillrate = (sum(weights(:)) / power(N_elements_per_side, 2)) * 100; %fill percent
89 |
90 | %Actual implementation use
91 | clear sllopt;
92 | generations = 2;
93 | for iteration = 1:1:generations
94 | %Calculate the sidelobe level for each candidate from the current
95 | %generation
96 | for candidate = 1:1:candidates_per_generation
97 | % Pick one random candidate, plot the beam pattern, and compute the sidelobe
98 | % level
99 | wtemp = w0(:, :, candidate);
100 | weights = [fliplr(flipud(wtemp)) flipud(wtemp); fliplr(wtemp) wtemp];
101 |
102 | for n = 1:1:length(frequency_vector)
103 | frequency = frequency_vector(n);
104 |
105 | % create omnidirectional characteristic
106 | iPattern = zeros(1, length(theta_vector_degrees));
107 |
108 | % Calculate Array Factor
109 | for nn = 1:1:length(theta_vector_rads)
110 | [AF, AF_dB, AV] = Uniform_Planar_Array(phi_val*(pi / 180), theta_vector_rads(nn), frequency, d, weights);
111 | weight_vs_angle{n}{nn} = {theta_vector_rads(nn), AV};
112 | %Combine for full characteristics
113 | F(n, nn) = AF_dB + iPattern(nn);
114 | end
115 | end
116 |
117 | pel = findpeaks(F(end, :), theta_vector_degrees, 'NPeaks', 2, 'SortStr', 'descend');
118 | sllopt(candidate) = pel(1) - pel(2);
119 | end
120 |
121 | %Now sort the performance of all candidates
122 | [~, idx] = sort(sllopt, 'descend');
123 |
124 | %Now remove the half of the current generation that has the worse
125 | %performance.
126 | w0 = w0(:, :, idx(1:1:(candidates_per_generation / 2)));
127 |
128 | %Finally perform random mutation of candidates that performed best and
129 | %add create new generation. All this does is take the best performes
130 | %and perform a random mutation and add those to the new generation.
131 | %First it takes all weights from the row mutation start idx onward and does a
132 | %flipud therby mutating the rows and then takes all rows from the column
133 | %mutation start idx and does a fliplr therby mutating the columns
134 | row_mutation_start_idx = randi(rows);
135 | column_mutation_start_idx = randi(columns);
136 | w0(row_mutation_start_idx:1:end , :, ((candidates_per_generation / 2) + 1):1:candidates_per_generation) ...
137 | = flipud(w0(row_mutation_start_idx:1:end , :, 1:1:(candidates_per_generation / 2)));
138 | w0(column_mutation_start_idx:1:end , :, ((candidates_per_generation / 2) + 1):1:candidates_per_generation) ...
139 | = fliplr(w0(column_mutation_start_idx:1:end , :, 1:1:(candidates_per_generation / 2)));
140 | end
141 |
142 | wtemp = w0(:, :, 1);
143 | optimum_weights = [fliplr(flipud(wtemp)) flipud(wtemp); fliplr(wtemp) wtemp];
144 | fillrate = (sum(optimum_weights(:)) / power(N_elements_per_side, 2)) * 100; %fill percent
145 |
146 | rng(rng_state);
147 |
148 | for n = 1:1:length(frequency_vector)
149 | frequency = frequency_vector(n);
150 |
151 | % create omnidirectional characteristic
152 | iPattern = zeros(1, length(theta_vector_degrees));
153 |
154 | % Calculate Array Factor
155 | for nn = 1:1:length(theta_vector_rads)
156 | [AF, AF_dB, AV] = Uniform_Planar_Array(phi_val*(pi / 180), theta_vector_rads(nn), frequency, d, optimum_weights);
157 | weight_vs_angle{n}{nn} = {theta_vector_rads(nn), AV};
158 | %Combine for full characteristics
159 | F(n, nn) = AF_dB + iPattern(nn);
160 | end
161 | end
162 |
163 | figure(2);
164 | plot(theta_vector_degrees, F(end,:));
165 |
166 | pel = findpeaks(F(end, :), theta_vector_degrees, 'NPeaks', 2, 'SortStr', 'descend');
167 | sllopt = sllopt(idx(1));
168 |
169 | fillrate = (sum(optimum_weights(:)) / power(N_elements_per_side, 2)) * 100; %fill percent
--------------------------------------------------------------------------------
/HFSS_pattern_import.m:
--------------------------------------------------------------------------------
1 | function [pattern_phitheta, phi, theta] = HFSS_pattern_import(relative_filename)
2 |
3 | patternData = csvread(relative_filename); % import csv
4 |
5 | % Extract phi/theta values from custom pattern
6 |
7 | chktheta = (patternData(:,2) == patternData(1,2));
8 | blockLen = length(chktheta(chktheta~=0));
9 | nCols = size(patternData,1)/blockLen;
10 | thetaBlocks = reshape(patternData(:,2),blockLen,nCols);
11 | phiBlocks = reshape(patternData(:,1),blockLen,nCols);
12 |
13 | theta = thetaBlocks(1,:);
14 | phi = phiBlocks(:,1).';
15 |
16 | pattern_phitheta = reshape(patternData(:,3),blockLen,nCols).';
17 |
--------------------------------------------------------------------------------
/Initial_ULA.m:
--------------------------------------------------------------------------------
1 | clear all
2 | clc
3 |
4 | relative_filename = './Radiation_Patterns/DF1_3GHz_Gain_3D_pt.csv';
5 |
6 | %Import the custom pattern (can add phase too if you want eve though it isn't in there now)
7 | %Input columns need to be phi, theta, pattern_dB pattern_phase
8 | [pattern_phitheta, phi, theta] = HFSS_pattern_import(relative_filename);
9 |
10 | %converts the pattern from phi - theta coordinates to az-el coordinates.
11 | [pattern_azel,az,el] = phitheta2azelpat(pattern_phitheta, phi, theta);
12 |
13 |
14 | freqVector = [2.75 3.25].*1e9; % Frequency range for element pattern
15 | antenna = phased.CustomAntennaElement('FrequencyVector', freqVector, ...
16 | 'AzimuthAngles', az, ...
17 | 'ElevationAngles', el, ...
18 | 'MagnitudePattern', pattern_azel, ...
19 | 'PhasePattern', zeros(size(pattern_azel)));
20 |
21 | fmax = freqVector(end);
22 | pattern(antenna,fmax,'Type','powerdb')
23 | view(90,0)
24 |
25 |
26 | c = 299792458;
27 | lambda = c / fmax;
28 | array = phased.UCA('Element',antenna,'NumElements',4,'Radius',lambda)
29 |
30 | pattern(array,fmax,'PropagationSpeed',c,'Type','powerdb',...
31 | 'CoordinateSystem','UV');
32 |
33 | pattern(array,fmax,-1:0.01:1,0,'PropagationSpeed',c,'Type','powerdb', ...
34 | 'CoordinateSystem','UV')
35 | axis([-1 1 -50 0]);
36 |
37 |
38 |
39 | f0 = 3e9;
40 | scanPhi = -30:30;
41 |
42 | steeringvec = phased.SteeringVector('SensorArray',array,...
43 | 'PropagationSpeed',c);
44 |
45 | arrayresp = phased.ArrayResponse('WeightsInputPort',true,...
46 | 'SensorArray',array);
47 |
48 | scanTheta = zeros(1,numel(scanPhi));
49 | scanAngles = [scanPhi;scanTheta];
50 | weights = steeringvec(f0,scanAngles); % Calculate Weights for steering
51 |
52 | az = -180:180;
53 | el = zeros(1,numel(az));
54 | ang_pairs = [az;el];
55 |
56 | arrayresp2d = ArrayResponseDemo2DPolarScope; % Initialize scope
57 |
58 | for t = 1:length(scanTheta) % Calculate response
59 | w = weights(:,t);
60 | temp_out = abs(arrayresp(f0,ang_pairs,w));
61 | temp_out = temp_out/max(temp_out);
62 | arrayresp2d(temp_out); % Display on scope
63 | end
64 |
65 |
66 | % Derive the elevation pattern.
67 | el_ang = -90:90;
68 | arrayresp = phased.ArrayResponse('SensorArray',array, ...
69 | 'PropagationSpeed',c);
70 | el_pat = abs(arrayresp(fmax,el_ang)); % elevation pattern
71 |
72 |
73 | % Plot the radar vertical diagram.
74 | freespace_rng = 100; % in km
75 | ant_height = 20; % in m
76 |
77 | radarvcd(fmax,freespace_rng,ant_height,...
78 | 'HeightUnit','m','RangeUnit','km',...
79 | 'AntennaPattern',el_pat/max(el_pat),'PatternAngles',el_ang.');
80 |
81 |
82 |
83 | subplot(211)
84 | pattern(array,fc,-180:180,0,'CoordinateSystem','rectangular', ...
85 | 'PropagationSpeed',c,'Type','powerdb')
86 | title('Without steering')
87 | subplot(212)
88 | pattern(array,fc,-180:180,0,'CoordinateSystem','rectangular', ...
89 | 'PropagationSpeed',c,'Type','powerdb','Weights',sv)
90 | title('With steering')
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/PSO_on_Linear_Array_For_Null.m:
--------------------------------------------------------------------------------
1 | clear all
2 | clc
3 |
4 | beam_theta = 0;
5 | null_thetas = [35 65];
6 | Goal_Beam_Power = 24;
7 | Goal_SINR_Value = 70;
8 |
9 | freq_range = [24e9 28e9]; % [start_frequency stop_frequency] [Hz]
10 | freq_points = 101; % No. of frequency points
11 | d = 0.005; % Element spacing [m]
12 | weights = ones(1, 16); % Amplitude weights for N elements from 0 to 1
13 |
14 | freq_step = (freq_range(2) - freq_range(1)) / (freq_points - 1);
15 | frequency_vector = freq_range(1):freq_step:freq_range(2);
16 | theta_vector_degrees = -90:1:90;
17 | theta_vector_rads = theta_vector_degrees * (pi / 180);
18 |
19 | for n = 1:1:length(frequency_vector)
20 | frequency = frequency_vector(n);
21 |
22 | % create omnidirectional characteristic
23 | iPattern = zeros(1, length(theta_vector_degrees));
24 |
25 | % Calculate Array Factor
26 | for nn = 1:1:length(theta_vector_rads)
27 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nn), frequency, d, weights);
28 | weight_vs_angle{n}{nn} = {theta_vector_rads(nn), AV};
29 | %Combine for full characteristics
30 | F(n, nn) = AF_dB + iPattern(nn);
31 | end
32 | end
33 |
34 | figure(2);
35 | plot(theta_vector_degrees, F(end,:));
36 |
37 |
38 | %Now do PSO algorithm
39 | particles_per_value = 64;
40 |
41 | % PSO paramters
42 | Max_iteration = 60;
43 | values = size(weights, 1) * size(weights, 2);
44 | magnitude_max = 1;
45 | velocity_max = 0.4;
46 | inertia_max = 0.9;
47 | inertia_min = 0.2;
48 | c1 = 2; c2 = 2;
49 | cg_curve = zeros(1,Max_iteration, values);
50 |
51 | particle_grid_steps = sqrt(particles_per_value);
52 | x = linspace(-1/sqrt(2), 1/sqrt(2), particle_grid_steps);
53 |
54 | % Initializations
55 | for value = 1:1:values
56 | for n = 1:1:particle_grid_steps
57 | for nn = 1:1:particle_grid_steps
58 | particles_value(n, nn, value) = x(n) + j * x(nn);
59 | end
60 | end
61 | end
62 |
63 | particles_velocities = velocity_max * (rand(particle_grid_steps, particle_grid_steps, values) ...
64 | + (j * rand(particle_grid_steps, particle_grid_steps, values)));
65 | particles_value_personal_best = rand(particle_grid_steps, particle_grid_steps, values) ...
66 | + (j * rand(particle_grid_steps, particle_grid_steps, values));
67 | particle_personal_best_objective_function = zeros(particle_grid_steps, particle_grid_steps, values);
68 |
69 | swarm_global_best_value = ones(1, 1, values);
70 | swarm_global_best_objective_function = zeros(1, 1, values);
71 |
72 | for itteration = 1:1:Max_iteration % main loop
73 |
74 | %Calculate objective function for each particle
75 | for value = 1:1:values
76 | for n = 1:1:particle_grid_steps
77 | for nn = 1:1:particle_grid_steps
78 |
79 | %update active weights
80 | weights = permute(swarm_global_best_value, [3 1 2]).';
81 | weights(1, value) = particles_value(n, nn, value);
82 |
83 | %Compute objective function START
84 | frequency = frequency_vector(end);
85 |
86 | % create omnidirectional characteristic
87 | iPattern = zeros(1, length(theta_vector_degrees));
88 |
89 | % Calculate Array Factor
90 | for nnn = 1:1:length(theta_vector_rads)
91 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nnn), frequency, d, weights);
92 | %Combine for full characteristics
93 | F(end, nnn) = AF_dB + iPattern(nnn);
94 | end
95 |
96 |
97 | SINR = sum(F(end, find(theta_vector_degrees == beam_theta)) - F(end, find(ismember(theta_vector_degrees, null_thetas)))) / length(null_thetas);
98 | Beam_Power = F(end, find(theta_vector_degrees == beam_theta));
99 | %Compute objective function END
100 |
101 | objective_function_value = (SINR/Goal_SINR_Value) + (Beam_Power / Goal_Beam_Power);
102 | if objective_function_value > particle_personal_best_objective_function(n, nn, value)
103 | particle_personal_best_objective_function(n, nn, value) = objective_function_value;
104 | particles_value_personal_best(n, nn, value) = particles_value(n, nn, value);
105 | end
106 | if(objective_function_value > swarm_global_best_objective_function(1, 1, value))
107 | swarm_global_best_objective_function(1, 1, value) = objective_function_value;
108 | swarm_global_best_value(1, 1, value) = particles_value(n, nn, value);
109 | end
110 | end
111 | end
112 | end
113 |
114 | %Update the inertia weight
115 | inertial_weight = inertia_max - (itteration * ( (inertia_max - inertia_min) / Max_iteration));
116 |
117 | %Update the Velocity and Position of particles
118 | particles_velocities = inertial_weight * particles_velocities + ... % inertia
119 | c1 * rand(particle_grid_steps, particle_grid_steps, values) .* (particles_value_personal_best - particles_value) + ... % congnitive
120 | c2 * rand(particle_grid_steps, particle_grid_steps, values) .* (swarm_global_best_value - particles_value); % social
121 |
122 | index = find(particles_velocities > velocity_max);
123 | particles_velocities(index) = velocity_max * rand;
124 |
125 | index = find(particles_velocities < -velocity_max);
126 | particles_velocities(index) = -velocity_max * rand;
127 |
128 | particles_value = particles_value + particles_velocities;
129 |
130 | magnitude = sqrt(particles_value .* conj(particles_value));
131 | index = find(magnitude > magnitude_max);
132 | particles_value(index) = particles_value(index) ./ magnitude(index);
133 |
134 | cg_curve(itteration, 1:1:values) = swarm_global_best_objective_function;
135 | swarm_global_best_objective_function
136 | end
137 | figure(1)
138 | hold on
139 | for value = 1:1:values
140 | plot(cg_curve(:,value))
141 | end
142 | xlabel('Iteration')
143 |
144 |
145 | weights = permute(swarm_global_best_value, [3 1 2]).';
146 |
147 | for n = 1:1:length(frequency_vector)
148 | frequency = frequency_vector(n);
149 |
150 | % create omnidirectional characteristic
151 | iPattern = zeros(1, length(theta_vector_degrees));
152 |
153 | % Calculate Array Factor
154 | for nn = 1:1:length(theta_vector_rads)
155 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nn), frequency, d, weights);
156 | %Combine for full characteristics
157 | F(n, nn) = AF_dB + iPattern(nn);
158 | end
159 | end
160 |
161 | figure(2);
162 | hold on
163 | plot(theta_vector_degrees, F(end,:));
--------------------------------------------------------------------------------
/PSO_on_Linear_Array_For_SLL.m:
--------------------------------------------------------------------------------
1 | clear all
2 | clc
3 |
4 | beam_theta = 0;
5 | Goal_Beam_Power = 24;
6 | Goal_SLL_Value = -30;
7 | beam_width_in_Degrees = 20; %Must be even
8 |
9 | freq_range = [24e9 28e9]; % [start_frequency stop_frequency] [Hz]
10 | freq_points = 101; % No. of frequency points
11 | d = 0.005; % Element spacing [m]
12 | weights = ones(1, 16); % Amplitude weights for N elements from 0 to 1
13 |
14 | freq_step = (freq_range(2) - freq_range(1)) / (freq_points - 1);
15 | frequency_vector = freq_range(1):freq_step:freq_range(2);
16 | theta_vector_degrees = -90:1:90;
17 | theta_vector_rads = theta_vector_degrees * (pi / 180);
18 |
19 | for n = 1:1:length(frequency_vector)
20 | frequency = frequency_vector(n);
21 |
22 | % create omnidirectional characteristic
23 | iPattern = zeros(1, length(theta_vector_degrees));
24 |
25 | % Calculate Array Factor
26 | for nn = 1:1:length(theta_vector_rads)
27 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nn), frequency, d, weights);
28 | weight_vs_angle{n}{nn} = {theta_vector_rads(nn), AV};
29 | %Combine for full characteristics
30 | F(n, nn) = AF_dB + iPattern(nn);
31 | end
32 | end
33 |
34 | mask = [(max(F(end,:)) + Goal_SLL_Value)*ones(1, (181 - (beam_width_in_Degrees + 1)) / 2) max(F(end,:))*ones(1, beam_width_in_Degrees + 1) (max(F(end,:)) + Goal_SLL_Value)*ones(1, (181 - (beam_width_in_Degrees + 1)) / 2)];
35 | slmask = ~(mask == max(F(end,:)));
36 |
37 | figure(2);
38 | plot(theta_vector_degrees, F(end,:));
39 | hold on
40 | plot(theta_vector_degrees, mask,'k');
41 |
42 | %Now do PSO algorithm
43 | particles_per_value = 64;
44 |
45 | % PSO paramters
46 | Max_iteration = 60;
47 | values = size(weights, 1) * size(weights, 2);
48 | magnitude_max = 1;
49 | velocity_max = 0.4;
50 | inertia_max = 0.9;
51 | inertia_min = 0.2;
52 | c1 = 2; c2 = 2;
53 | cg_curve = zeros(1,Max_iteration, values);
54 |
55 | particle_grid_steps = sqrt(particles_per_value);
56 | x = linspace(-1/sqrt(2), 1/sqrt(2), particle_grid_steps);
57 |
58 | % Initializations
59 | for value = 1:1:values
60 | for n = 1:1:particle_grid_steps
61 | for nn = 1:1:particle_grid_steps
62 | particles_value(n, nn, value) = x(n) + j * x(nn);
63 | end
64 | end
65 | end
66 |
67 | particles_velocities = velocity_max * (rand(particle_grid_steps, particle_grid_steps, values) ...
68 | + (j * rand(particle_grid_steps, particle_grid_steps, values)));
69 | particles_value_personal_best = rand(particle_grid_steps, particle_grid_steps, values) ...
70 | + (j * rand(particle_grid_steps, particle_grid_steps, values));
71 | particle_personal_best_objective_function = 1e3*ones(particle_grid_steps, particle_grid_steps, values);
72 |
73 | swarm_global_best_value = ones(1, 1, values);
74 | swarm_global_best_objective_function = 1e3*ones(1, 1, values);
75 |
76 | for itteration = 1:1:Max_iteration % main loop
77 |
78 | %Calculate objective function for each particle
79 | for value = 1:1:values
80 | for n = 1:1:particle_grid_steps
81 | for nn = 1:1:particle_grid_steps
82 |
83 | %update active weights
84 | weights = permute(swarm_global_best_value, [3 1 2]).';
85 | weights(1, value) = particles_value(n, nn, value);
86 |
87 | %Compute objective function START
88 | frequency = frequency_vector(end);
89 |
90 | % create omnidirectional characteristic
91 | iPattern = zeros(1, length(theta_vector_degrees));
92 |
93 | % Calculate Array Factor
94 | for nnn = 1:1:length(theta_vector_rads)
95 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nnn), frequency, d, weights);
96 | %Combine for full characteristics
97 | F(end, nnn) = AF_dB + iPattern(nnn);
98 | end
99 |
100 | %Remove -Inf values
101 | temp = F(end, find(F(end, :).*slmask ~= 0)); ind = find(temp == -Inf); temp(ind) = -100;
102 | SLL = sum(temp - Goal_SLL_Value) / sum(slmask);
103 | temp = F(end, find(F(end, :).*(~slmask) ~= 0)); ind = find(temp == -Inf); temp(ind) = -100;
104 | Beam_Power = sum(Goal_Beam_Power - temp) / sum(~slmask);
105 | %Compute objective function END
106 |
107 | objective_function_value = SLL + Beam_Power;
108 | if objective_function_value < particle_personal_best_objective_function(n, nn, value)
109 | particle_personal_best_objective_function(n, nn, value) = objective_function_value;
110 | particles_value_personal_best(n, nn, value) = particles_value(n, nn, value);
111 | end
112 | if(objective_function_value < swarm_global_best_objective_function(1, 1, value))
113 | swarm_global_best_objective_function(1, 1, value) = objective_function_value;
114 | swarm_global_best_value(1, 1, value) = particles_value(n, nn, value);
115 | end
116 | end
117 | end
118 | end
119 |
120 | %Update the inertia weight
121 | inertial_weight = inertia_max - (itteration * ( (inertia_max - inertia_min) / Max_iteration));
122 |
123 | %Update the Velocity and Position of particles
124 | particles_velocities = inertial_weight * particles_velocities + ... % inertia
125 | c1 * rand(particle_grid_steps, particle_grid_steps, values) .* (particles_value_personal_best - particles_value) + ... % congnitive
126 | c2 * rand(particle_grid_steps, particle_grid_steps, values) .* (swarm_global_best_value - particles_value); % social
127 |
128 | index = find(particles_velocities > velocity_max);
129 | particles_velocities(index) = velocity_max * rand;
130 |
131 | index = find(particles_velocities < -velocity_max);
132 | particles_velocities(index) = -velocity_max * rand;
133 |
134 | particles_value = particles_value + particles_velocities;
135 |
136 | magnitude = sqrt(particles_value .* conj(particles_value));
137 | index = find(magnitude > magnitude_max);
138 | particles_value(index) = particles_value(index) ./ magnitude(index);
139 |
140 | cg_curve(itteration, 1:1:values) = swarm_global_best_objective_function;
141 | swarm_global_best_objective_function
142 | end
143 | figure(1)
144 | hold on
145 | for value = 1:1:values
146 | plot(cg_curve(:,value))
147 | end
148 | xlabel('Iteration')
149 |
150 |
151 | weights = permute(swarm_global_best_value, [3 1 2]).';
152 |
153 | for n = 1:1:length(frequency_vector)
154 | frequency = frequency_vector(n);
155 |
156 | % create omnidirectional characteristic
157 | iPattern = zeros(1, length(theta_vector_degrees));
158 |
159 | % Calculate Array Factor
160 | for nn = 1:1:length(theta_vector_rads)
161 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nn), frequency, d, weights);
162 | %Combine for full characteristics
163 | F(n, nn) = AF_dB + iPattern(nn);
164 | end
165 | end
166 |
167 | figure(2);
168 | hold on
169 | plot(theta_vector_degrees, F(end,:));
--------------------------------------------------------------------------------
/Pattern_Visualization.m:
--------------------------------------------------------------------------------
1 | clear all
2 | clc
3 |
4 | frequency = 28e9;
5 | d_a = 0.005;
6 | weights = ones(1, 10);
7 | array_type = 'circular';
8 |
9 | [phi_theta, phi_theta_dB, phi, theta] = generate_phi_theta(frequency, d_a, weights, array_type);
10 |
11 | patternCustom(phi_theta_dB', theta, phi);
12 | patternCustom(phi_theta_dB', theta, phi,'CoordinateSystem','rectangular');
13 | patternCustom(phi_theta_dB', theta, phi,'CoordinateSystem','polar','Slice', ...
14 | 'phi','SliceValue',[45 90 180 359]);
15 | patternCustom(phi_theta_dB', theta, phi,'CoordinateSystem','rectangular', ...
16 | 'Slice','phi','SliceValue',[45 90 180 359]);
17 |
18 | %converts the pattern from phi - theta coordinates to az-el coordinates.
19 | [pattern_azel,az,el] = phitheta2azelpat(phi_theta_dB, phi, theta);
20 |
21 | freqVector = [24 28].*1e9; % Frequency range for element pattern
22 | antenna = phased.CustomAntennaElement('FrequencyVector', freqVector, ...
23 | 'AzimuthAngles', az, ...
24 | 'ElevationAngles', el, ...
25 | 'MagnitudePattern', pattern_azel, ...
26 | 'PhasePattern', zeros(size(pattern_azel)));
27 |
28 | fmax = freqVector(end);
29 | pattern(antenna,fmax,'Type','powerdb')
30 | view(90,0)
31 |
32 | %more here
33 | %https://www.mathworks.com/help/antenna/examples/visualize-custom-radiation-patterns.html
34 | %https://www.mathworks.com/help/phased/examples/antenna-array-analysis-with-custom-radiation-pattern.html
--------------------------------------------------------------------------------
/Plot_Circular_Array_Response.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Plot_Circular_Array_Response.m
--------------------------------------------------------------------------------
/Plot_Circular_Array_With_Element_Response.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Plot_Circular_Array_With_Element_Response.m
--------------------------------------------------------------------------------
/Plot_Linear_Array_Response.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Plot_Linear_Array_Response.m
--------------------------------------------------------------------------------
/Plot_Linear_Array_With_Element_Response.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Plot_Linear_Array_With_Element_Response.m
--------------------------------------------------------------------------------
/Plot_Planar_Array_Response.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Plot_Planar_Array_Response.m
--------------------------------------------------------------------------------
/Plot_Planar_Array_With_Element_Response.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Plot_Planar_Array_With_Element_Response.m
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Phased_Array
2 | Phased array and beamforming library
3 |
--------------------------------------------------------------------------------
/SLC_on_Linear_Array_For_Null.m:
--------------------------------------------------------------------------------
1 | clear all
2 | clc
3 |
4 | beam_thetas = [0 50 70];
5 | null_thetas = [35 60 80 90];
6 |
7 | freq_range = [24e9 28e9]; % [start_frequency stop_frequency] [Hz]
8 | freq_points = 101; % No. of frequency points
9 | d = 0.005; % Element spacing [m]
10 | weights = ones(1, 16); % Amplitude weights for N elements from 0 to 1
11 |
12 | freq_step = (freq_range(2) - freq_range(1)) / (freq_points - 1);
13 | frequency_vector = freq_range(1):freq_step:freq_range(2);
14 | theta_vector_degrees = -90:1:90;
15 | theta_vector_rads = theta_vector_degrees * (pi / 180);
16 |
17 | for n = 1:1:length(frequency_vector)
18 | frequency = frequency_vector(n);
19 |
20 | % create omnidirectional characteristic
21 | iPattern = zeros(1, length(theta_vector_degrees));
22 |
23 | % Calculate Array Factor
24 | for nn = 1:1:length(theta_vector_rads)
25 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nn), frequency, d, weights);
26 | weight_vs_angle{n}{nn} = {theta_vector_rads(nn), AV};
27 | %Combine for full characteristics
28 | F(n, nn) = AF_dB + iPattern(nn);
29 | end
30 | end
31 |
32 | figure(2);
33 | plot(theta_vector_degrees, F(end,:));
34 |
35 | %Calculate weights for sidelobe canceller
36 | for n = 1:1:length(beam_thetas)
37 | weights_desired_direction(:, :, n) = weight_vs_angle{end}{find(theta_vector_degrees == beam_thetas(n))}{2}';
38 | end
39 | %Can just sum desired direction vectors and normalize for total beam response
40 | weights_desired_direction = sum(weights_desired_direction, 3);
41 | weights_desired_direction = weights_desired_direction ./ abs(weights_desired_direction);
42 |
43 | %Need to itteratively subtract out null vectors, cannot do cumulatively
44 | %like desired vectors, however, you can only effectively place one deep null
45 | %with this method which will be the last one that you subtract. The other
46 | %nulls may or may not be there but if they are there they will not be there
47 | %not like that final one you place
48 |
49 | %weights = desired_weights - null_weights * ((null_weights' * desired_weights) / (null_weights' * null_weights));
50 | %What is happening here is from a paper about optimization but it can be
51 | %thought of as the following
52 | %(null_weights' * desired_weights) is the difference vector between null_weights and desired_weights
53 | % i.e. is the angle between the two vectors and also difference in
54 | % magnitude
55 | %(null_weights' * null_weights) is the magnitude of the null_weights
56 | % so null_weights * ((null_weights' * desired_weights) / (null_weights' * null_weights));
57 | % is doing (null_weights / magnitude of null_weights) * difference in
58 | % magnitude and angle between null_weights and desired_weights
59 | % again this is actually derives as the LMS value in the paper
60 | % 5.0 SIDELOBE CANCELLATION
61 | % but this is one way to think of how I have applied it here vs how they
62 | % apply it / derive its application in the paper
63 | weights = weights_desired_direction;
64 | for n = 1:1:length(null_thetas)
65 | null_weights = weight_vs_angle{end}{find(theta_vector_degrees == null_thetas(n))}{2}';
66 | weights = weights - null_weights * ((null_weights' * weights) / (null_weights' * null_weights));
67 | weights_null_direction(:, :, n) = null_weights;
68 | end
69 |
70 | %Apply
71 | for n = 1:1:length(frequency_vector)
72 | frequency = frequency_vector(n);
73 |
74 | % create omnidirectional characteristic
75 | iPattern = zeros(1, length(theta_vector_degrees));
76 |
77 | % Calculate Array Factor
78 | for nn = 1:1:length(theta_vector_rads)
79 | [AF, AF_dB, AV] = Uniform_Linear_Array(theta_vector_rads(nn), frequency, d, weights);
80 | %Combine for full characteristics
81 | F(n, nn) = AF_dB + iPattern(nn);
82 | end
83 | end
84 |
85 | figure(2);
86 | hold on
87 | plot(theta_vector_degrees, F(end,:));
--------------------------------------------------------------------------------
/Test_Array/Far_Field_Data/5ELx2 FarField Tx Only.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Test_Array/Far_Field_Data/5ELx2 FarField Tx Only.mat
--------------------------------------------------------------------------------
/Test_Array/Near_Field_Data/5ELx2 1meter NearField Tx Only.mat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Test_Array/Near_Field_Data/5ELx2 1meter NearField Tx Only.mat
--------------------------------------------------------------------------------
/Test_Array/PSO_Cancellation.m:
--------------------------------------------------------------------------------
1 | clear all
2 | clc
3 |
4 | %In this case we want all tx to rx values to be 0
5 | %Since the tx ports are 1-5 and the rx ports are 6-10
6 | %we want to make sure that S(6,7,8,9,10)1, S(6,7,8,9,10)2, etc....
7 | %are all 0. Since the matrix has input ports vs columns and output ports
8 | %vs rows as below
9 |
10 | %s11 s12 s13 s14 s15 s16 s17 s18 s19 s110
11 | %s21 s22 s23 s24 s25 s26 s27 s28 s29 s210
12 | %s31 s32 s33 s34 s35 s36 s37 s38 s39 s310
13 | %s41 s42 s43 s44 s45 s46 s47 s48 s49 s410
14 | %s51 s52 s53 s54 s55 s56 s57 s58 s59 s510
15 | %s61 s62 s63 s64 s65 s66 s67 s68 s69 s610
16 | %s71 s72 s73 s74 s75 s76 s77 s78 s79 s710
17 | %s81 s82 s83 s84 s85 s86 s87 s88 s89 s810
18 | %s91 s92 s93 s94 s95 s96 s97 s98 s99 s910
19 | %s101 s102 s103 s104 s105 s106 s107 s108 s109 s1010
20 |
21 | %The inputs I have are to the weights on the upper left diagonal only
22 | %So woud defactor set x6-x10 = 0
23 | % x = [x1 x2 x3 x4 x5 0 0 0 0 0].';
24 | %The output vector y results from s * x and since x is tx only that also
25 | %further masks off our s matrix effectively to the following
26 |
27 | %s11 s12 s13 s14 s15 0 0 0 0 0
28 | %s21 s22 s23 s24 s25 0 0 0 0 0
29 | %s31 s32 s33 s34 s35 0 0 0 0 0
30 | %s41 s42 s43 s44 s45 0 0 0 0 0
31 | %s51 s52 s53 s54 s55 0 0 0 0 0
32 | %s61 s62 s63 s64 s65 0 0 0 0 0
33 | %s71 s72 s73 s74 s75 0 0 0 0 0
34 | %s81 s82 s83 s84 s85 0 0 0 0 0
35 | %s91 s92 s93 s94 s95 0 0 0 0 0
36 | %s101 s102 s103 s104 s105 0 0 0 0 0
37 |
38 | %So effectively all we are reallly solving for is the left half of the
39 | %sparameter matrix so we can truncate the square matrix to a rectangular as
40 | %such
41 |
42 | %| s11 s12 s13 s14 s15 | * | x1 | = | y1 |
43 | %| s21 s22 s23 s24 s25 | | x2 | | y2 |
44 | %| s31 s32 s33 s34 s35 | | x3 | | y3 |
45 | %| s41 s42 s43 s44 s45 | | x4 | | y4 |
46 | %| s51 s52 s53 s54 s55 | | x5 | | y5 |
47 | %| s61 s62 s63 s64 s65 | | y6 |
48 | %| s71 s72 s73 s74 s75 | | y7 |
49 | %| s81 s82 s83 s84 s85 | | y8 |
50 | %| s91 s92 s93 s94 s95 | | y9 |
51 | %| s101 s102 s103 s104 s105 | | y10 |
52 |
53 | %The goal is to minize the y6 - y10 terms and we don't care about the
54 | %y1 - y5 terms so again we can effectively reduce the matrix to the
55 | %following
56 |
57 | %| s61 s62 s63 s64 s65 | * | x1 | = | y6 |
58 | %| s71 s72 s73 s74 s75 | | x2 | | y7 |
59 | %| s81 s82 s83 s84 s85 | | x3 | | y8 |
60 | %| s91 s92 s93 s94 s95 | | x4 | | y9 |
61 | %| s101 s102 s103 s104 s105 | | x5 | | y10 |
62 |
63 | %And lastly we can say that we want to just minimize all values equally so
64 | %we will say that min( y*y' ) is the fitness function that we want to
65 | %evaluate/minimize which is just to total power from the tramsmit array
66 | %into the receive array
67 |
68 | %Also note that the manifold file has x different cell for each frequency
69 | %Once in a manifold you have a single element per column and rows are vs
70 | %phi
71 |
72 | [FileName, sp, freq_GHz] = ReadTouchstone();
73 | sparameter_freq_vector = freq_GHz * 1e9;
74 |
75 | Near_Field_Struct = load('./Near_Field_Data/5ELx2 1meter NearField Tx Only.mat');
76 | Far_Field_Struct = load('./Far_Field_Data/5ELx2 FarField Tx Only.mat');
77 |
78 | beam_theta = 90;
79 | null_phis = [0];
80 | transmit_phis = [-180:5:15 15:5:175];
81 | Max_SINR = 70;
82 |
83 | freq_range = [5e8 6e9]; % [start_frequency stop_frequency] [Hz]
84 | freq_step = 50e6; % Frequency Step size [Hz]
85 | weights = ones(1, 5); % Amplitude weights for N elements from 0 to 1
86 |
87 | Starting_Element_Number = 6;
88 | Ending_Element_Number = 10;
89 | S = sp(Starting_Element_Number:1:Ending_Element_Number, 1:1:length(weights), :);
90 |
91 | freq_points = ((freq_range(2) - freq_range(1)) / freq_step) + 1;
92 | frequency_vector = freq_range(1):freq_step:freq_range(2);
93 | phi_vector_degrees = -180:1:179;
94 | phi_vector_rads = phi_vector_degrees * (pi / 180);
95 |
96 | N = zeros(length(frequency_vector), length(phi_vector_degrees));
97 | F = zeros(length(frequency_vector), length(phi_vector_degrees));
98 | for n = 1:1:length(frequency_vector)
99 | frequency = frequency_vector(n);
100 |
101 | near_field_findex = find(Near_Field_Struct.flist_MHz == (frequency/1e6));
102 | near_field_vs_phi = Near_Field_Struct.manifold{near_field_findex};
103 | temp = near_field_vs_phi(ismember(Near_Field_Struct.phi, phi_vector_degrees), :).*weights;
104 | AF = sum(temp, 2);
105 | N(n, :) = 10*log10(AF.*conj(AF));
106 |
107 | far_field_findex = find(Far_Field_Struct.flist_MHz == (frequency/1e6));
108 | far_field_vs_phi = Far_Field_Struct.manifold{far_field_findex};
109 | temp = far_field_vs_phi(ismember(Far_Field_Struct.phi, phi_vector_degrees), :).*weights;
110 | AF = sum(temp, 2);
111 | F(n, :) = 10*log10(AF.*conj(AF));
112 | end
113 |
114 | analysis_and_plot_frequency_index = find(frequency_vector == 1e9);
115 | analysis_and_plot_frequency = frequency_vector(analysis_and_plot_frequency_index);
116 |
117 | figure(2);
118 | plot(phi_vector_degrees, N(analysis_and_plot_frequency_index,:), phi_vector_degrees, F(analysis_and_plot_frequency_index,:));
119 | figure(3)
120 | polarplot(phi_vector_degrees*pi/180, N(analysis_and_plot_frequency_index,:));
121 | figure(4)
122 | polarplot(phi_vector_degrees*pi/180, F(analysis_and_plot_frequency_index,:));
123 |
124 | FF_Max = max(F(analysis_and_plot_frequency_index,:));
125 |
126 |
127 | %Now do PSO algorithm
128 | particles_per_value = 64;
129 |
130 | % PSO paramters
131 | Max_iteration = 200;
132 | values = size(weights, 1) * size(weights, 2);
133 | magnitude_max = 1;
134 | velocity_max = 0.4;
135 | inertia_max = 0.9;
136 | inertia_min = 0.2;
137 | c1 = 2; c2 = 2;
138 | cg_curve = zeros(1,Max_iteration, values);
139 |
140 | particle_grid_steps = sqrt(particles_per_value);
141 | x = linspace(-1/sqrt(2), 1/sqrt(2), particle_grid_steps);
142 |
143 | % Initializations
144 | for value = 1:1:values
145 | for n = 1:1:particle_grid_steps
146 | for nn = 1:1:particle_grid_steps
147 | particles_value(n, nn, value) = x(n) + j * x(nn);
148 | end
149 | end
150 | end
151 |
152 | particles_velocities = velocity_max * (rand(particle_grid_steps, particle_grid_steps, values) ...
153 | + (j * rand(particle_grid_steps, particle_grid_steps, values)));
154 | particles_value_personal_best = rand(particle_grid_steps, particle_grid_steps, values) ...
155 | + (j * rand(particle_grid_steps, particle_grid_steps, values));
156 | particle_personal_best_objective_function = 1e3*ones(particle_grid_steps, particle_grid_steps, values);
157 |
158 | swarm_global_best_value = ones(1, 1, values);
159 | swarm_global_best_objective_function = 1e3*ones(1, 1, values);
160 |
161 | for itteration = 1:1:Max_iteration % main loop
162 |
163 | %Calculate objective function for each particle
164 | for value = 1:1:values
165 | for n = 1:1:particle_grid_steps
166 | for nn = 1:1:particle_grid_steps
167 |
168 | %update active weights
169 | weights = permute(swarm_global_best_value, [3 1 2]).';
170 | weights(1, value) = particles_value(n, nn, value);
171 |
172 | %Compute objective function START
173 | frequency = analysis_and_plot_frequency;
174 |
175 | near_field_findex = find(Near_Field_Struct.flist_MHz == (frequency/1e6));
176 | near_field_vs_phi = Near_Field_Struct.manifold{near_field_findex};
177 | temp = near_field_vs_phi(ismember(Near_Field_Struct.phi, null_phis), :).*weights;
178 | AF = sum(temp, 2);
179 | NF = 10*log10(sum(AF.*conj(AF))/length(null_phis));
180 |
181 | far_field_findex = find(Far_Field_Struct.flist_MHz == (frequency/1e6));
182 | far_field_vs_phi = Far_Field_Struct.manifold{far_field_findex};
183 | temp = far_field_vs_phi(ismember(Far_Field_Struct.phi, transmit_phis), :).*weights;
184 | AF = sum(temp, 2);
185 | FF = 10*log10(sum(AF.*conj(AF))/length(transmit_phis));
186 |
187 | sparameter_frequency_index = find(sparameter_freq_vector == frequency);
188 |
189 | temp = S(:, :, sparameter_frequency_index) * weights.';
190 | MSP = 10*log10((temp'*temp) / length(temp));
191 |
192 | Power_Loss = 10*log10(length(weights) / (weights*weights'));
193 |
194 | % Use Near Fields (Modified for SINR)
195 | % Just need to limit the near field null effect so it doesn't
196 | % dominate the cost function
197 | MNF = ((FF - Max_SINR) * (NF < (FF - Max_SINR))) + (NF * ~(NF < (FF - Max_SINR)));
198 | MPL = (Power_Loss * (3 > Power_Loss)) + (Power_Loss*10 * ~(3 > Power_Loss));
199 | % Dont use Sparameter results, they skew the cost function and
200 | % have no bearing on nulling performance. They do reflect good
201 | % nulling once weights are computed but do not do well to adapt
202 | % for good weights
203 | %objective_function_value = MSP + MNF + MPL + (FF_Max - FF);
204 | objective_function_value = MNF + MPL + (FF_Max - FF);
205 | % Use S parameters and Near Fields
206 | %objective_function_value = MSP + NF + Signal_Power + (FF_Max - FF);
207 | % Use Near Fields only
208 | %objective_function_value = NF + Signal_Power;
209 | % Use Far Fields only (Creats null in far filed but it shifts
210 | % in the near filed and fills in so this will not work)
211 | %objective_function_value = Signal_Power + FF;
212 | % Use S parameters only (Does not create null like we would
213 | % hope so we can ignore these in optimization algorithm)
214 | %objective_function_value = MSP + Signal_Power;
215 |
216 |
217 | if objective_function_value < particle_personal_best_objective_function(n, nn, value)
218 | particle_personal_best_objective_function(n, nn, value) = objective_function_value;
219 | particles_value_personal_best(n, nn, value) = particles_value(n, nn, value);
220 | end
221 | if(objective_function_value < swarm_global_best_objective_function(1, 1, value))
222 | swarm_global_best_objective_function(1, 1, value) = objective_function_value;
223 | swarm_global_best_value(1, 1, value) = particles_value(n, nn, value);
224 | end
225 | end
226 | end
227 | end
228 |
229 | %Update the inertia weight
230 | inertial_weight = inertia_max - (itteration * ( (inertia_max - inertia_min) / Max_iteration));
231 |
232 | %Update the Velocity and Position of particles
233 | particles_velocities = inertial_weight * particles_velocities + ... % inertia
234 | c1 * rand(particle_grid_steps, particle_grid_steps, values) .* (particles_value_personal_best - particles_value) + ... % congnitive
235 | c2 * rand(particle_grid_steps, particle_grid_steps, values) .* (swarm_global_best_value - particles_value); % social
236 |
237 | index = find(particles_velocities > velocity_max);
238 | particles_velocities(index) = velocity_max * rand;
239 |
240 | index = find(particles_velocities < -velocity_max);
241 | particles_velocities(index) = -velocity_max * rand;
242 |
243 | particles_value = particles_value + particles_velocities;
244 |
245 | magnitude = sqrt(particles_value .* conj(particles_value));
246 | index = find(magnitude > magnitude_max);
247 | particles_value(index) = particles_value(index) ./ magnitude(index);
248 |
249 | cg_curve(itteration, 1:1:values) = swarm_global_best_objective_function;
250 | swarm_global_best_objective_function
251 | end
252 | figure(1)
253 | hold on
254 | for value = 1:1:values
255 | plot(cg_curve(:,value))
256 | end
257 | xlabel('Iteration')
258 |
259 | weights = permute(swarm_global_best_value, [3 1 2]).';
260 |
261 | weights.*weights'.' %Magnitudes
262 | angle(weights)*180/pi %Phases
263 | y = S(:, :, sparameter_frequency_index) * weights.';
264 | 10*log10(y.*y'.') %S parameters
265 | 10*log10(weights*weights' / length(weights)) %power loss
266 |
267 | N = zeros(length(frequency_vector), length(phi_vector_degrees));
268 | F = zeros(length(frequency_vector), length(phi_vector_degrees));
269 | for n = 1:1:length(frequency_vector)
270 | frequency = frequency_vector(n);
271 |
272 | near_field_findex = find(Near_Field_Struct.flist_MHz == (frequency/1e6));
273 | near_field_vs_phi = Near_Field_Struct.manifold{near_field_findex};
274 | temp = near_field_vs_phi(ismember(Near_Field_Struct.phi, phi_vector_degrees), :).*weights;
275 | AF = sum(temp, 2);
276 | N(n, :) = 10*log10(AF.*conj(AF));
277 |
278 | far_field_findex = find(Far_Field_Struct.flist_MHz == (frequency/1e6));
279 | far_field_vs_phi = Far_Field_Struct.manifold{far_field_findex};
280 | temp = far_field_vs_phi(ismember(Far_Field_Struct.phi, phi_vector_degrees), :).*weights;
281 | AF = sum(temp, 2);
282 | F(n, :) = 10*log10(AF.*conj(AF));
283 | end
284 |
285 | figure(2);
286 | hold on
287 | plot(phi_vector_degrees, N(analysis_and_plot_frequency_index,:), phi_vector_degrees, F(analysis_and_plot_frequency_index,:));
288 | figure(3)
289 | hold on
290 | polarplot(phi_vector_degrees*pi/180, N(analysis_and_plot_frequency_index,:));
291 | ax = gca;
292 | ax.RLim = [0 FF_Max+2];
293 | figure(4)
294 | hold on
295 | polarplot(phi_vector_degrees*pi/180, F(analysis_and_plot_frequency_index,:));
296 | polarplot(phi_vector_degrees*pi/180, N(analysis_and_plot_frequency_index,:));
297 | ax = gca;
298 | ax.RLim = [0 FF_Max+2];
--------------------------------------------------------------------------------
/Test_Array/Power_Point/2x5 Element Array NF Datas.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsochacki/Phased_Array/6b815612739053dee38c9a8993f47ea73b206f38/Test_Array/Power_Point/2x5 Element Array NF Datas.pptx
--------------------------------------------------------------------------------
/Test_Array/ReadTouchstone.m:
--------------------------------------------------------------------------------
1 | function [FileName, sp, freq_GHz] = ReadTouchstone()
2 | % function [sp,freq]=ReadTouchsone()
3 | % Reads the touchstone .snp file
4 | % Returns S parameters in complex 3D matrix in sp(n,m,freq)
5 | % Returns frequency in freq in [GHz]
6 | % Value of n in .snp must be the number of ports
7 | % Normalization factor is not returned in this script (the number after
8 | % R in the header), adding z0 in the return value should give this back
9 |
10 | % Touchstone format is based on the version 1.1
11 | % http://www.eda.org/pub/ibis/connector/touchstone_spec11.pdf
12 |
13 | % base on the script found on the edaboard.com and also N.K.
14 | % http://www.edaboard.com/ftopic328289.html
15 | % Ryosuke Ito on 12/02/2009
16 |
17 |
18 |
19 | verbose=1 ; % flag for verbose mode, if other than 0, shows the progress
20 |
21 | [FileName,PathName]=uigetfile('*.s*p','Select valid touchstone file');
22 | % if cancel is pressed, returns zeros
23 | if FileName==0
24 | sp=0 ; freq_GHz=0 ;
25 | return
26 | end
27 |
28 | [t,r]=strtok(FileName,'.'); % separating before and after the first '.'
29 | [t,r]=strtok(r,'.'); % extracting the first token after the first '.'
30 | s1=sscanf(t,'%c%d%c'); % extracting the integer in between the characters from extension
31 | port_num=s1(2); % getting the n in 'snp'
32 |
33 | fname=[PathName, FileName];
34 | fid=fopen(fname,'r');
35 |
36 | % line_entries is the number of complex data per line
37 | if(port_num>4)
38 | line_entries=4;
39 | positions_per_last_line=rem(port_num,4);
40 | elseif(port_num==2)
41 | line_entries=4;
42 | else
43 | line_entries=port_num;
44 | end
45 |
46 | %%%%%%%%%%%%%%%%%%%
47 | mode=0; % data format mode 'RI' or 'MA'
48 | unit=1; % frequency unit, 1 for GHz, 1e-3 for MHz
49 | j=sqrt(-1); % defining j
50 |
51 |
52 | %% process the preamble.
53 | buffer='NaN' ;
54 |
55 | while( isnan(str2double(strtok(buffer))) ) % checking if the first token is not a number
56 |
57 | % read one line from the file, change to upper case, and save to buffer
58 | buffer=upper(fgetl(fid));
59 |
60 | % detecting blank line and discard
61 | if(strcmp(strtok(buffer),''))
62 | buffer=fgetl(fid);
63 | continue;
64 | end;
65 |
66 | % if the first non space character is !
67 | if(strncmpi(strjust(buffer,'left'),'!',1) )
68 | continue;
69 | end;
70 |
71 | % if the first non space character is #
72 | if(strncmpi(strjust(buffer,'left'),'#',1) )
73 | [token, buffer]=strtok(buffer); % dropping the # and forward the buffer
74 | [token, buffer]=strtok(buffer); % reading the next token
75 | %
76 | if (strcmp(token, 'HZ'))
77 | unit=1.0E-9;
78 | elseif (strcmp(token, 'MHZ'))
79 | unit=1.0E-3;
80 | elseif (strcmp(token, 'GHZ'))
81 | unit=1.0;
82 | end;
83 | %
84 | [token, buffer]=strtok(buffer); % dropping 'S'
85 | [token, buffer]=strtok(buffer);
86 | %
87 | if (strcmp(token, 'RI'))
88 | mode=1;
89 | elseif (strcmp(token, 'MA'))
90 | mode=0;
91 |
92 | end;
93 | [token, buffer]=strtok(buffer); % dropping 'R'
94 | [token, buffer]=strtok(buffer);
95 | z0=str2num(token) ; % normalization value saved into z0
96 | end
97 |
98 | end
99 |
100 | % for verbose mode
101 | switch verbose
102 | case 0
103 | otherwise
104 | switch mode
105 | case 1
106 | disp('Reading touchstone file in RI mode.') ;
107 | case 0
108 | disp('Reading touchstone file in MA mode.') ;
109 | end
110 |
111 | switch unit
112 | case 1
113 | disp('Frequency unit is GHz.') ;
114 | case 1e-3
115 | disp('Frequency unit is MHz.') ;
116 | case 1e-9
117 | disp('Frequency unit is Hz.') ;
118 | end
119 |
120 | fprintf('Z0 = %f\n\n',z0) ;
121 | end
122 |
123 |
124 | %% Reading the data.
125 | n=1;
126 | while(strcmp(strtok(buffer),''))
127 | buffer=fgetl(fid);
128 | end
129 | while(~feof(fid))
130 | [data,buffer]=strtok(buffer) ;
131 | [data_x, count]=sscanf(data, '%f', 1);
132 | freq_GHz(n,1)=data_x*unit;
133 |
134 | l=1;
135 | while (l f = c / Lambda and c = 1/sqrt(mu_r*mu_0*epsi_r*epsi_0)
21 | % k = 2*pi*(c / lambda)*sqrt(mu_r*mu_0*epsi_r*epsi_0) => k = (2*pi)/lambda
22 |
23 | % Physical constants
24 | c = 299792458;
25 |
26 | % Derived values
27 | N = length(weights);
28 | lambda = c / f;
29 | k = (2 * pi) / lambda;
30 | delta_phi = (2 * pi) / N;
31 |
32 | n = 0:1:N-1;
33 | PHI = k * a * sin(theta);
34 | AV = weights .* exp(j * PHI * cos(phi - (delta_phi * n)));
35 | AF = sum(AV);
36 |
37 | AF_dB = 10*log10(AF*AF');
38 |
39 | end
--------------------------------------------------------------------------------
/Uniform_Linear_Array.m:
--------------------------------------------------------------------------------
1 | function [AF, AF_dB, AV] = Uniform_Linear_Array(theta, f, d, weights)
2 | %Uniform_Linear_Array Calculate array factor of linear antenna array for a given
3 | % theta [rad] based on an array defined by:
4 | % frequency f [Hz],
5 | % element spacing d [m],
6 | % and element complex weight
7 |
8 | % Here a zero value for theta corresponds to the line that the array makes
9 | % i.e. a vector with theta zero points directly in line with the array
10 | % i.e. parallel to the length of the array and
11 | % a theta of 90 degrees if perpendicular to the length of the array
12 |
13 | % Note that this linear array has a reference point that is at the very end
14 | % of the array and not in the center
15 |
16 | % Since k^2 = (2*pi*f)^2*mu*epsi then k = 2*pi*f*sqrt(mu_r*mu_0*epsi_r*epsi_0)
17 | % and c = lambda * f => f = c / Lambda and c = 1/sqrt(mu_r*mu_0*epsi_r*epsi_0)
18 | % k = 2*pi*(c / lambda)*sqrt(mu_r*mu_0*epsi_r*epsi_0) => k = (2*pi)/lambda
19 |
20 | if (size(weights, 2) < size(weights, 1)), weights = weights.';, end;
21 |
22 | % Physical constants
23 | c = 299792458;
24 |
25 | % Derived values
26 | N = length(weights);
27 | lambda = c / f;
28 | k = (2 * pi) / lambda;
29 | PHI = (k * d * cos(theta));
30 |
31 | n = 1:1:N;
32 | AV = weights .* exp(j * PHI * (n-1));
33 | AF = sum(AV);
34 |
35 | AF_dB = 10*log10(AF*AF');
36 |
37 | %For sanity check if you like
38 | %(sin((N/2)*phi)/sin((1/2)*phi))^2 - AF*AF' < 1e-14
39 | %20*log10(sin((N/2)*phi)/sin((1/2)*phi)) - AF_dB < 1e-14
40 |
41 | end
--------------------------------------------------------------------------------
/Uniform_Planar_Array.m:
--------------------------------------------------------------------------------
1 | function [AF, AF_dB, AV] = Uniform_Planar_Array(phi, theta, f, d, weights)
2 | %Uniform_Planar_Array Calculate array factor of linear antenna array for a given
3 | % theta [rad] based on an array defined by:
4 | % frequency f [Hz],
5 | % element spacing d [m],
6 | % and element complex weight
7 |
8 | % Here a zero value for theta corresponds to the normal vector to the plane
9 | % that the array makes
10 | % i.e. a vector with theta zero points directly in perpendicular to the
11 | % array face and a theta of 90 degrees if parallel/in plane to the face of the array
12 |
13 | % Note that this planar array has a reference point that is at the very end
14 | % of the array in the corner and not in the center
15 |
16 | % Also note that this planar array does NOT need to be square
17 | % it is M elements in the x and N elements in the y direction
18 |
19 | % Since k^2 = (2*pi*f)^2*mu*epsi then k = 2*pi*f*sqrt(mu_r*mu_0*epsi_r*epsi_0)
20 | % and c = lambda * f => f = c / Lambda and c = 1/sqrt(mu_r*mu_0*epsi_r*epsi_0)
21 | % k = 2*pi*(c / lambda)*sqrt(mu_r*mu_0*epsi_r*epsi_0) => k = (2*pi)/lambda
22 |
23 | % Physical constants
24 | c = 299792458;
25 |
26 | % Derived values
27 | M = size(weights, 1);
28 | N = size(weights, 2);
29 | lambda = c / f;
30 | k = (2 * pi) / lambda;
31 |
32 | PHI_X = (k * d * sin(theta) * cos(phi));
33 | PHI_Y = (k * d * sin(theta) * sin(phi));
34 |
35 | m = 1:1:M; n = 1:1:N;
36 | M_VECTOR = exp(j * PHI_X * (m-1));
37 | N_VECTOR = exp(j * PHI_Y * (n-1));
38 | AV = weights .* ((M_VECTOR.')*(N_VECTOR));
39 | AF = sum(sum(AV));
40 |
41 | AF_dB = 10*log10(AF*AF');
42 |
43 | end
--------------------------------------------------------------------------------
/generate_HFSS_field_vectors.m:
--------------------------------------------------------------------------------
1 | function [phi_theta_vector, all_theta, all_phi] = generate_HFSS_field_vectors(phi_theta, phi, theta)
2 |
3 | all_theta = repelem(theta, length(phi));
4 | all_phi = repelem(phi, length(theta));
5 | index = 1;
6 | for n = 0:1:(length(theta) - 1)
7 | for nn = 0:1:(length(phi) - 1)
8 | phi_theta_vector(index) = phi_theta(n + 1, nn + 1);
9 | index = index + 1;
10 | end
11 | end
12 |
13 | end
--------------------------------------------------------------------------------
/generate_phi_theta.m:
--------------------------------------------------------------------------------
1 | function [phi_theta, phi_theta_dB, phi, theta] = generate_phi_theta(frequency, d_a, weights, array_type, element_phi_theta)
2 |
3 | phi = 0:1:359;
4 | theta = 0:1:179;
5 | phi_theta = zeros(length(theta), length(phi));
6 |
7 | switch lower(array_type)
8 | case 'linear'
9 | for n = theta
10 | for nn = phi
11 | [phi_theta(n + 1, nn + 1), phi_theta_dB(n + 1, nn + 1), ~] = ...
12 | Uniform_Linear_Array(n * (pi / 180), frequency, d_a, weights);
13 | end
14 | end
15 | case 'planar'
16 | for n = theta
17 | for nn = phi
18 | [phi_theta(n + 1, nn + 1), phi_theta_dB(n + 1, nn + 1), ~] = ...
19 | Uniform_Planar_Array(nn * (pi / 180), n * (pi / 180), frequency, d_a, weights);
20 | end
21 | end
22 | case 'circular'
23 | for n = theta
24 | for nn = phi
25 | [phi_theta(n + 1, nn + 1), phi_theta_dB(n + 1, nn + 1), ~] = ...
26 | Uniform_Circular_Array(nn * (pi / 180), n * (pi / 180), frequency, d_a, weights);
27 | end
28 | end
29 | otherwise
30 | phi_theta=[]; phi=[]; theta=[];
31 | error('The array geometry %s is not currently supported.', array_type);
32 | end
33 |
34 | switch nargin
35 | case 4
36 | case 5
37 | phi_theta = phi_theta .* element_phi_theta;
38 | phi_theta_dB = phi_theta_dB + 10*log10(element_phi_theta .* element_phi_theta'.')
39 | otherwise
40 | phi_theta=[]; phi=[]; theta=[];
41 | error('Not enough input arguements provided');
42 | end
43 |
44 | end
--------------------------------------------------------------------------------