How to modify the 2nd code like the 1st one?

I have two codes. I want to modify the 2nd code given below like that of the 1st code given below:
CODE1:
u=[30 40 50 80]; %i.e. u=[theta1 theta2 phi1 phi2]% Desired vector
[~,C]=size(u);
P=C/2;% No. of signal sources
M=C;% No. of antennas
% calculate observed vectors
xo=zeros(1,M);% received observed signal on antennas placed on x-axis
yo=zeros(1,M);% received observed signal on antennas placed on y-axis
zo=zeros(1,M);% received observed signal on antennas placed on z-axis
for k=1:M
for i=1:P
xo(1,k)=xo(1,k)+exp(-1i*(k-1)*pi*cosd(u(i))); %--------------------------(1)
yo(1,k)=yo(1,k)+exp(-1i*(k-1)*pi*sind(u(i))*cosd(u(P+i))); %-------------(2)
zo(1,k)=zo(1,k)+exp(-1i*(k-1)*pi*sind(u(i))*sind(u(P+i))); %-------------(3)
end
end
If you look at CODE1, we have put the values of vector u in the cosd and sind of equations (1), (2) and (3). Now we want to do the same logic with the equations (1), (2), (3) and (4) of CODE2. I have done a little bit but got confused.
CODE2:
u=[30 40 50 80]; %i.e. u=[theta1 theta2 phi1 phi2]% Desired vector
[~,C]=size(u);
P1=C/2;% No. of signal sources
M1=C;% No. of antennas
% f=1e9;
% c=3e8;
% l=c/f;
% k=(2*pi)/l;
N=8;% No. of antennas. This will become as M1 from above in this code
n=0:N-1;
phi_n=2*pi*n/N;
phi=-pi:pi/18:pi;
theta=0:pi/18:pi/2;
M=length(theta);
P=length(phi);
% d_circular=l/2;
% a=(N*d_circular)/(2*pi);% Radius of circle
for p=1:P
for m=1:M
% AF(m,p)=sum(exp(-i*k*a*sin(theta(m))*(cos(phi(p)-phi_n))));
AF(m,p)=sum(exp(-1i*(N/2)*sin(theta(m))*(cos(phi(p)-phi_n))));%----------------------------------(1)
x(m,p)=abs(AF(m,p))*sin(theta(m))*cos(phi(p));% received observed signal on x-axis %-------------(2)
y(m,p)=abs(AF(m,p))*sin(theta(m))*sin(phi(p));% received observed signal on y-axis %-------------(3)
z(m,p)=abs(AF(m,p))*cos(theta(m));% received observed signal on z-axis %-------------------------(4)
end
end

Answers (1)

@Sadiq Akbar,

[edit: I submitted the answer prematurely.]
Code 2 runs without error. Why do you think code 2 needs fixing?
%% code 2 by Sadiq Akbar
u=[30 40 50 80]; %i.e. u=[theta1 theta2 phi1 phi2]% Desired vector
[~,C]=size(u);
P1=C/2;% No. of signal sources
M1=C;% No. of antennas
% f=1e9;
% c=3e8;
% l=c/f;
% k=(2*pi)/l;
N=8;% No. of antennas. This will become as M1 from above in this code
n=0:N-1;
phi_n=2*pi*n/N;
phi=-pi:pi/18:pi;
theta=0:pi/18:pi/2;
M=length(theta);
P=length(phi);
% d_circular=l/2;
% a=(N*d_circular)/(2*pi);% Radius of circle
for p=1:P
for m=1:M
% AF(m,p)=sum(exp(-i*k*a*sin(theta(m))*(cos(phi(p)-phi_n))));
AF(m,p)=sum(exp(-1i*(N/2)*sin(theta(m))*(cos(phi(p)-phi_n))));%----------------------------------(1)
x(m,p)=abs(AF(m,p))*sin(theta(m))*cos(phi(p));% received observed signal on x-axis %-------------(2)
y(m,p)=abs(AF(m,p))*sin(theta(m))*sin(phi(p));% received observed signal on y-axis %-------------(3)
z(m,p)=abs(AF(m,p))*cos(theta(m));% received observed signal on z-axis %-------------------------(4)
end
end
fprintf('M=%d, P=%d.\n',M,P);
M=10, P=37.
figure; mesh(1:P,1:M,x);
xlabel('p'); ylabel('m'); zlabel('x'); grid on
figure; surf(x,y,z);
xlabel('x'); ylabel('y'); zlabel('z');
title('abs(AF)'); axis equal; grid on
You can delete P1 and M1, since they are not used. The rest of the code works. If you are unhappy with the output of code 2, please explain why.
In code 1, x0 is a row vector with M=4 columns. Each element of x0 is computed by adding up P=2 complex components. y0 and z0 are similar.
In code 2, AF(m,p) is a 10x37 complex array. The values of AF() span a hemisphere, at 10 degree increments, from -180 to +180 in azimuth, and from 0 to 90 in elevation. Arrays x,y,z are the x,y,z, components of abs(AF), by a standard spherical-to-Cartesian coordinate transformation, assuming points along the z-axis, and points along the x-y plane. I have added a plot of x(m,p) and a plot of the abs(AF) surface.

20 Comments

Thanks a lot for your prompt response. In code1, I have taken my own desired values of theta and Phi's as you can see inside vector u and that works ok. But in code2, both the angles theta and Phi's are taken as:
phi=-pi:pi/18:pi;
theta=0:pi/18:pi/2;
I don't want to take these values but rather I want to take my own desired values of theta and Phi in vector u like in the CODE1 above.
@Sadiq Akbar, I'm sorry that I made a major edit to my answer, and that you responded in the intervening time. I hit "Submit" when I meant to press the green button to run the code.
Is phi is an azimuth angle? Is theta is an elevation angle?
Line 1 of code 1 and line 1 of code 2 is
u=[30 40 50 80]; %i.e. u=[theta1 theta2 phi1 phi2]% Desired vector
Do you want to compute AF and x,y,z at and at ?
If the answer is yes, then you can simply extract the appropriate elemnts from aray AF and from arrays x, y, and z, after you have computed the AF and x, y, z at all angles on the hemisphere.
Thanks a lot for your prompt response. Yes theta ia elevation angle and phi is azimuth angle. I want two things namely:
1- I want to compute all AF , x, y and z on the angles given in the veetor u i.e., u=[30 40 50 80] in which 1st two are thetas and the last two are phi's.
2-I want to compute only AF at all angles on the hemisphere but x,y and z at angles of vector u and then see the effect.
Since u represents two direction vectors, I recommend that u() be a 2x2 array instead of a 1x4 vector. Let . I have put theta before phi in the matrix, to match the ordering of the indices used for AF and x, y, z.
To compute AF and x,y,z at the two specified directions:
% In this script, AF and x,y,z are computed at C specified directions.
u=[50,30; 80,40]; % directions: u=[theta1 phi1; theta2 phi2] (degrees)
[C,~]=size(u); % number of directions
x=zeros(C,1); y=x; z=x; AF=x; % allocate arrays
N=8; % number of antennas
n=0:N-1;
phi_n=360*n/N; % antenna directions (degrees)
for i=1:C
AF(i)=sum(exp(-1i*(N/2)*sind(u(i,1))*(cosd(u(i,2)-phi_n))));
x(i)=abs(AF(i))*sind(u(i,1))*cosd(u(i,2)); % x component of signal
y(i)=abs(AF(i))*sind(u(i,1))*sind(u(i,2)); % y component of signal
z(i)=abs(AF(i))*cosd(u(i,1)); % z component of signal
end
%% Display results on console
for i=1:C
fprintf('Direction %d: theta=%d, phi=%d, |AF|=%.3f, AFx=%.3f, AFy=%.3f, AFz=%.3f\n',...
i,u(i,1),u(i,2),abs(AF(i)),x(i),y(i),z(i));
end
Direction 1: theta=50, phi=30, |AF|=2.253, AFx=1.495, AFy=0.863, AFz=1.448 Direction 2: theta=80, phi=40, |AF|=3.159, AFx=2.383, AFy=2.000, AFz=0.549
OK
To compute AF at all angles on the hemisphere, and x,y,z at C specified directions:
% In this script, AF is computed at all directions on the hemisphere.
% x,y,z are computed at C specified directions.
u=[50,30; 80,40]; % directions: u=[theta1 phi1; theta2 phi2] (degrees)
[C,~]=size(u); % number of directions
x=zeros(C,1); y=x; z=x; % allocate x, y, z arrays
theta=0:10:90;
phi=-180:10:+180;
M=length(theta);
P=length(phi);
AF=zeros(M,P); % allocate AF array
N=8; % number of antennas
n=0:N-1;
phi_n=360*n/N; % antenna directions (degrees)
%% Compute AF at all directions on the hemisphere
for m=1:M
for p=1:P
AF(m,p)=sum(exp(-1i*(N/2)*sind(theta(m))*(cosd(phi(p)-phi_n))));
end
end
%% Compute x,y,z at specific directions
for i=1:C
m=find(theta==u(i,1)); % index of specified theta
p=find(phi==u(i,2)); % index of specified phi
AF0=abs(AF(m,p)); % |AF| in specified direction
x(i)=AF0*sind(u(i,1))*cosd(u(i,2)); % x component of signal
y(i)=AF0*sind(u(i,1))*sind(u(i,2)); % y component of signal
z(i)=AF0*cosd(u(i,1)); % z component of signal
end
%% Display results on console
for i=1:C
fprintf('Direction %d: theta=%d, phi=%d, AFx=%.3f, AFy=%.3f, AFz=%.3f\n',...
i,u(i,1),u(i,2),x(i),y(i),z(i));
end
Direction 1: theta=50, phi=30, AFx=1.495, AFy=0.863, AFz=1.448 Direction 2: theta=80, phi=40, AFx=2.383, AFy=2.000, AFz=0.549
The values for AFx, AFy, AFz in this script match the values from the previous script.
Thanks a lot dear @William Rose for your kind help. As I told you I want to find x,y,z and AF both at specified angles and at all angles. You did it. But this is half of the work. Now the final work is that I want to take another vector b of same dimension as is u and put that in place of u in the given formulas and then call those x,y and z as xe,ye and then find the absolute error between each dimension for all the 8 antennas. I have tried below but antennas are 8 and the index of x,y and z are only 2. I don't know why?
% To compute AF at all angles on the hemisphere, and x,y,z at C specified directions:
function e%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;clc
u=[50,30; 80,40]; % directions: u=[theta1 phi1; theta2 phi2] (degrees)
b=u;
[C,~]=size(u); % number of directions
xo=zeros(C,1); yo=xo; zo=xo; % allocate x, y, z arrays
xe=zeros(C,1); ye=xe; ze=xe; % allocate x, y, z arrays
theta=0:10:90;
phi=-180:10:+180;
M=length(theta);
P=length(phi);
AF=zeros(M,P); % allocate AF array
N=8; % number of antennas
n=0:N-1;
phi_n=360*n/N; % antenna directions (degrees)
%% Compute AF at all directions on the hemisphere
for m=1:M
for p=1:P
AF(m,p)=sum(exp(-1i*(N/2)*sind(theta(m))*(cosd(phi(p)-phi_n))));
end
end
%% Compute xo,yo,zo at specific directions
for i=1:C
m=find(theta==u(i,1)); % index of specified theta
p=find(phi==u(i,2)); % index of specified phi
AF0=abs(AF(m,p)); % |AF| in specified direction
xo(i)=AF0*sind(u(i,1))*cosd(u(i,2)); % x component of signal
yo(i)=AF0*sind(u(i,1))*sind(u(i,2)); % y component of signal
zo(i)=AF0*cosd(u(i,1)); % z component of signal
end
%% Compute xe,ye,ze at specific directions
for i=1:C
m=find(theta==b(i,1)); % index of specified theta
p=find(phi==b(i,2)); % index of specified phi
AF0=abs(AF(m,p)); % |AF| in specified direction
xe(i)=AF0*sind(b(i,1))*cosd(b(i,2)); % x component of signal
ye(i)=AF0*sind(b(i,1))*sind(b(i,2)); % y component of signal
ze(i)=AF0*cosd(b(i,1)); % z component of signal
end
% MSE
abc=0.0;
abcd=0.0;
abcde=0.0;
for m1=1:N
abc=abc+(abs(xo(1,m1)-xe(1,m1))).^2;
abcd=abcd+(abs(yo(1,m1)-ye(1,m1))).^2;
abcde=abcde+(abs(zo(1,m1)-ze(1,m1))).^2;
end
err=abc+abcd+abcde;
err=err/(3*N);
Let me share another code which does somewhat like the work I want. The code of that is below:
clear;clc
u=[30 40 50 80];b=u; %[theta1 theta2 phi1 phi2]
[~,C]=size(b);
P=C/2;
M=C;% Antennas
% calculate observed vector
xo=zeros(1,M);
yo=zeros(1,M);
zo=zeros(1,M);
for k=1:M
for i=1:P
xo(1,k)=xo(1,k)+exp(-1i*(k-1)*pi*cos(u(i)));
yo(1,k)=yo(1,k)+exp(-1i*(k-1)*pi*sin(u(i))*cos(u(P+i)));
zo(1,k)=zo(1,k)+exp(-1i*(k-1)*pi*sin(u(i))*sin(u(P+i)));
end
end
xe=zeros(1,M);
ye=zeros(1,M);
ze=zeros(1,M);
for k=1:M
for i=1:P
xe(1,k)=xe(1,k)+exp(-1i*(k-1)*pi*cos(b(i)));
ye(1,k)=ye(1,k)+exp(-1i*(k-1)*pi*sin(b(i))*cos(b(P+i)));
ze(1,k)=ze(1,k)+exp(-1i*(k-1)*pi*sin(b(i))*sin(b(P+i)));
end
end
abc=0.0;
abcd=0.0;
abcde=0.0;
for m1=1:M
abc=abc+(abs(xo(1,m1)-xe(1,m1))).^2;
abcd=abcd+(abs(yo(1,m1)-ye(1,m1))).^2;
abcde=abcde+(abs(zo(1,m1)-ze(1,m1))).^2;
end
err=abc+abcd+abcde;
e=err/(3*M)
The formulas in both these codes are different because the formula in the 1st code is for circular array and the formula in this for double L array.
I tried to do the same logic with the 1st code you did for me as I have shared also but that gives me the error of indexing.
@Sadiq Akbar, Please explain your new goal. I know you have already explained it, but I do not understand.
Perhaps I will understand your new goal if you answer some questions I havee about what we have already done.
Question 1. Is the description below correct?
Eight antennae (N=8) are evenly spaced around a circle in the X-Y plane. The circle is centered at the origin. AF(phi,theta) is the length of a resultant field vector, due to all N antennae, at the origin, pointing in direction , where theta=elevation and phi=azimuth. Your initial goal was to know the x,y,z components of AF, in 2 specific directions (C=2).
Question 2. Please explain the formula for AF. The formula for AF in the code is
AF(m,p)=sum(exp(-1i*(N/2)*sind(theta(m))*(cosd(phi(p)-phi_n))));
which is equal to
where N is the number of antennae (N=8) and is the angle from the origin to antenna j. I do not understand the physics underlying the formula above. Why is N/2 there? The term gives the projection of a unit vector that points in the X-Y plane toward antenna j onto a vector that points in direction . Why is this term present inside the exponential?
Now let us consider your new goal. You write "I want to take another vector b of same dimension as is u and put that in place of u in the given formulas and then call those x,y and z as xe,ye and then find the absolute error between each dimension for all the 8 antennas. I have tried below but antennas are 8 and the index of x,y and z are only 2. I don't know why?"
Array u is C-by-2 array which specifies C directions of interest ( for each direction).
You wish to do calculations like the calculations with u, but using a new array b, which has the same dimensions as u.
Question 3. Is it true that b represents C directions, which are different than the C directions specified in u? If that is true, then why is b identical to u, in your code above? I would expect the values in b and u to differ.
You wrote "the index of x,y and z are only 2. I don't know why?" X, y, and z are vectors of length C=2 because array u has 2 rows. If you want to know x,y, and z in more directions, then increase the number of rows in u.
We will use the notation xo,yo,zo for the x,y,z components associated with the directions in u. We will use the notation xe,ye,ze for the x,y,z components associated with the directions in b.
Question 4. Is it true that you want to compute the mean squared error between (xo,yo,zo) and (xe,ye,ze), as shown in the formula below?
Thanks a lot for your kind response. Actually I find the angles of different signals incident on an antenna array. For this I make fitness functions. The formula inside the fitness function is dereived on the basis of the structure of the antenna array which shows the received signal on these antennas making the array.Then I assume my desired angles in a vector u and put those angles inside that formula.Then I use an algorithm like Genetic Algorithm which invokes my fitness function and which puts a vector of its own population of the same size as u in the same formula. When the two vectors(i.e., u and b) become equal, then my fitness function gives 0 value which means that the two vectors are equal. In other words, the algorithm estimates my desired result.
In this regard, I have given you the formula for an antenna array whose structure is like a double L. I am already using this. But some time ago, I saw a site given below which has given a formula and a code for a circular array which is new for me. I tried to make a fitness function from that formula but I couldn't. So I asked it on this forum 1st to understand it what is it doing? So you told me about that. Now my next target is to make a fitness function from it so that I can use an algorithm on it and I am able to estimate my desried result with a circular array which I get via a double array. This is all what I want.
With this I will be able to decide which array gives me the best result so that I can use it in my future work.
Now coming your questions:
"Eight antennae (N=8) are evenly spaced around a circle in the X-Y plane. The circle is centered at the origin. AF(phi,theta) is the length of a resultant field vector, due to all N antennae, ............"
Yes eight antenna i.e., N=8 are uniformly distributed on a circle in the xy-plane and the circle is centered at the origin. AF is the "Array Factor" which means that it is the response of a single antenna for all the signals incident on it. So what will be the response of all those antennas placed uniformly on the circle? To find this , we use the x-component and the y-component in which the array lies. If the array lies in the yz-plane then we will find he y and the z-components. Further, yes theta is the elevation angle and phi is the azimuth angle.
Question 2. Please explain the formula for AF. The formula is:
In this Nis the number of antenna, phi is the azimuth angle and yes phiaj is the angle from te origin to the antenna in the array. I think you will understand the complete physics if you visit the URL given above.
"Question 3. Is it true that b represents C directions, which are different than the C directions specified in u? If that is true, then why is b identical to u, in your code above? I would expect the values in b and u to differ."
No. "b" is a random vector generated inside the algorithm which is having the same size as u. Actually the algorithm generated the no. of such vectors which you have told the algorithm to generate. Then the algorithm sends one by one vector to the fitness function and checks the fitness in the form of MSE. when the MSE is zero, it means that the sent vector "b" is exactly same as u. and if the fitness is not zero but some low value then it means that the vector "b" is nearly the same as u.
I think i have fully explained my work. But still if you have some confusion, then do let me know. Regards,
I went to the web link you provided, but I did not find it helpful. It was a lot of code and no pictures. Perhaps I need a good picture. The site you provided did include a link to an image, which showed an array of 4 antennae in a line.
Is it true that you want to estimate the sensitivity of a circular antenna array, in the X-Y plane, to a source that is located at a large distance, in the direction =inclination,azimuth? If so, then we need to esitmate the phase differences at the different antennae. For this we must know the ratio of the wavelength to the circle radius. Do you assume that the resultant signal, AF, is the simple sum of the signals from N antennae?
If I am understanding correctly, then there will be no phase differences for a source at the zenith (), and the sensitivity AF is maximal in this case. If there are just 2 antennae, at and , and if the radius is a quarter wavelength, and the source is in the X-Y plane, aligned with the antennas (i.e. ), then there is a path length difference of half a wavelength, i.e. the two antennae are exactly out of phase, and the sensitivity AF=0.
Am I understanding correctly, now?
I think the site is very helpful but I don't know why didn't you find it helpful. May be you have not browsed it correctly.
No no the source is in a plane which is perpendicular to the plane of xy in which the array is there. Imagine this like this that the array is lying on the earth and the signals are coming from the area just above the earth. Now what are the angles of elevation and azimuth of those signals? We have to estimate them.
[Edit: I asked a quesiton that you had already answered before. Sorry about that. I was a passenger in a car and was having trouble browsing our previous discussion.]
@Sadiq Akbar, I am glad you found that site helpful. You said “ the source is in a plane which is perpendicular to the plane of xy in which the array is there”.
No matter where in the sky the source is, there will be an infinite number of planes perpendicular to the XY plane which also pass through the source.
Does the diagram below represent your problem? It shows N=8 antennae in a circular array in the X-Y plane, and a source (green) with zenith angle theta and azimuth phi.
Let AF be the sum of the signals from the N antennae. It seems to me that AF varies as a function of theta and phi, as shown below:
where is the vector from the circle center to antenna k, and is a unit vector pointing from the circle center toward the source, and λ is the wavelength. This post is getting long so I will stop here, for your comments.
If my diagram above is not a correct representation of your problem, then perhaps you can post a better picture. Or you can rely on others on this site who, no doubt, understand your problem better than me.
My formula for AF is
This is different from the formula in your original post. The figure below shows the results when I use the formula above.
Example: Let N=4, and let the circle radius=. Then we expect AF=4 when the source is at the zenith (i.e. ), since all four antennae will be in phase. We expect AF=0 when the source is on the horizon , with azimuth=45, 135, 225, or 315, because at these azimuths, two antenna are exact one half wavelength out of phase with the other two, so they cancel out. The script produces the expected results. See plot below.
Thanks a lot dear @William Rose for your response. 1st of all soryy for being too late as I was out of the station and the system was at home.
Regarding your above reply, yes my source is as you have shown but its position can be varied if we take different angle. But I don't understand your forumla. How did you take this formula? Can you guide me further?
Regards,
[Edit: Correct typo in the last equation in this comment: I forot to include "/".]
I derived the formula for AF by looking at the image below (which I also posted above):
I assume that the source (green) is a large distance from the antenna array, and therefore the amplitude is the same at all antennas in the array. I assume the amplitude equals one. These assumptions simplify the calculations. We need the phase differences of the antenna from some rference phase. I choose the reference phase to be the center of the array. Then I need to know the phase of each antenna, relative to the center of the array.
The phase difference, in radians, is
where the negative sign is because a larger distance causes a phase lag, and where
The difference in the distance difference of antenna k to the source, compared to the distance of the center to the source, is
where is the vector from the circle center to antenna k, and is a unit vector pointing from the circle center toward the source. You can confirm that by analyzing the geometry of the figure above.
Put it all together:
Thanks a lot dear @William Rose for your kind response. Interesting. I liked your way of derivation. But the confusion is that how did you use it in coding? Further, what did you do with the unit vector n hat and how did you handle it in the coding? In addition to this, can you do all this step-by-step? i.e. 1st derive the formula, then estimate the angles of the sources using your derived formula with coding? I mean if we take 2 or 3 sources at desired angles in degrees like say for example [theta1 Theta2 Theta3 Phi1 Phi2 Phi3]=[30 50 70 35 45 85] and then you estimate these desired angles with your formula via coding? I will be very thankful to you for that.
Regards,
Angles are in radians. theta is the zenith angle of the source: theta=0 for a source at the zenith. phi is the source azimuth, increasing CCW from tyhe +x axis. Then
% nhat=[sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta)];
The code for AF, for a single source location, is
N=8; % number of antennae
Ar=0.50; % antenna circle radius, in wavelengths
theta=pi/3; % source zenith angle
phi=pi/4; % source azimuth
% compute values
alpha=2*pi/N; % angle between adjacent antennae
r=Ar*[cos((1:N)'*alpha),sin((1:N)'*alpha),zeros(N,1)]; % radial vectors to antennae
% Compute AF
AF=0;
nhat=[sin(theta)*cos(phi),sin(theta)*sin(phi),cos(theta)];
for k=1:N
AF=AF+exp(2*pi*1i*dot(r(k,:),nhat));
end
AF=abs(AF);
fprintf('AF(phi=%.1f,theta=%.1f)=%.3f.\n',[phi,theta]*180/pi,AF)
AF(phi=45.0,theta=60.0)=1.208.
If you want multiple values for theta and phi, then make phi and theta vectors, and make AF a 2D array, instead of scalars. Make outer loops to compute AF(i,j) for different values of theta and phi.
Thanks a lot dear @William Rose for your prompt response.
Actually, as I told you, I want to estimate both the angles (i.e., Theta abd Phi) for 2, 3 and four sources. I don't understand the 0th zenith angle. But usually I assume both the angles for 2, 3 and 4 sources and then make a fitness function based on MSE using the formula of the circular array and then I invoke my fitness function through the metaheuristic algorithm to estimate those asuumed angles. Let me tell you in simple words.
If I have circular array, then I put the asume angles in the formula and get the received signals like x0, x1, x2,....x7 where xi is the received signal by each antenna i.e., I write the formula and equate it to xi, then I run a loop over all the 8 antennas to get the received signal by each of the antenna i.e., x0, x1,....x7. Then I make all these signals as observed signal and call that as xo. Likewise I write the same formula for xe i.e., estimated signal but the difference is that all the angle values come from the desired angles in vecor u for xo and all the angle values come from a vector b for xe and that vector b is of the same size as u and is generated by the algorithm randomly. Then I find the error between the xo and xe and find the mean sqaure error over the antennas. I run the algorithm 50 times and get 50 results. Then I choose the minumum fitness value that correspond to the best vector b which is nearly the same as my desired vector u. Thus I estimate those angles with that algorithm.
I hope you understood my problem compeletely. So how will I do that using your above formula?
Regards,
Now you are asking an entirely new quesiton: how to do estimation. Please post this as a new question on Matlab answers.
Thanks a lot fpor your prompt response. Yes, you are right but I thought I have told you already. However it's my mistake. You are right because I went through the above discussion but I didn't find what I asked for now.
However, one question still remains that you have given the code upto:
AF=abs(AF);
fprintf('AF(phi=%.1f,theta=%.1f)=%.3f.\n',[phi,theta]*180/pi,AF)
you have not given the code how did you have got the plots? Also how did you take the radius as lambda/(2*(2)^0.2)?
Further, if we want to do the same process for 2 sources, then how will we get the plots?
Regards,
I did not provide the code for the plots because you will learn more about Matlab and about coding by doing some of this work yourself. To make the plots, you need to compute AF for a range of theta values and for a range of phi values. I gave you instructions on how to do that. Specifically, I said "If you want multiple values for theta and phi, then make phi and theta vectors, and make AF a 2D array, instead of scalars. Make outer loops to compute AF(i,j) for different values of theta and phi."
I will give you some additional suggestions:
  • If you want 4 values of theta (=zenith angle), and 12 values of phi (=azimuth), then let AF be 4 by 12.
  • Once you have computed array AF(), using the outer for loops as I suggested, plot it with surf(phi,theta,AF)
  • Read the help for surf(). Read the help for colorbar(), if you want a color bar.
  • Multiply phi and theta by 180/pi, for plotting purposes, if you want the ploot to have angles in degrees, since both are in radians in my formulas above.
I could have chosen any value for the circle radius, r. I chose because I knew that with 4 antennas, this r value would put adjacent antenna pairs exactly a half-wavelength apart when phi=45, 135, etc. I knew this by thinking about the geometry of the right triangles formed between the center and adjacent antenna pairs. This results in complete signal cancellation (i.e. AF=0) at phi=45, 135, etc., which is an interesting special case.

Sign in to comment.

Categories

Find more on Phased Array Design and Analysis in Help Center and File Exchange

Asked:

on 8 Jan 2024

Commented:

on 16 Feb 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!