I tried this code but it gives me an error
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sadiq Akbar
el 30 de Abr. de 2024
Comentada: Voss
el 30 de Abr. de 2024
There are 8 antennas placed in a circle and there are two sources in the far field from which rays are coming and are incident on these antennas. The mathematical formula for array factor "AF" is given in the attachment. This derivation of this formula is also attached. Now if the angles of those two sources are 30 and 70 respectively which I assign to a vector u. Then I want to put these angles one by one while spanning all the 8 antennas. I mean when I put angle 30 in the formula, then the AF should be calculated over all the 8 antennas. Likewise then put the 2nd angle 70 in the formula and calculate the AF over all the 8 antennas. So when I check the AF, it should be an 8 x 2 matrix where 8 are antennas and 2 are angles. I have tried for its code as below but it gives me an error:
clear;clc
f=1e9;% frequency
c=3e8;% speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
u=[30 70];% The two Angles
M=length(u);% Number of angles
d_circular=l/2;% spacing b/w elements
circumference = N*d_circular;
a = circumference/2*pi; % Radius
for sourceNo=1:M
for m=0:N-1
% AF = sgma from n=0 to N-1 (exp(-1j*k*a*cos(phi-phin))
AF(m)=sum(exp(-1i*k*a*(cos(u(sourceNo)-phi_n))));
end
end
AF
0 comentarios
Respuesta aceptada
Voss
el 30 de Abr. de 2024
u appears to be in degrees, but phi_n appears to be in radians. You need to convert one or the other, and then use the appropriate cosine function (cos or cosd). I'll convert u to radians and use cos.
If you want AF to be 8x2, you'll need two indices in the expression for AF, i.e., use m+1 as the row index (or change m to be 1:N and use m as the index) and use sourceNo as the column index.
Also, based on the comment "AF = sgma from n=0 to N-1 (exp(-1j*k*a*cos(phi-phin))", you should only use one element from phi_n in the calculation of each element of AF. If you sum at that point, the result is the same for each m (i.e., each row of AF). You can sum afterward if that's what you need to do.
f=1e9;% frequency
c=3e8;% speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
u=[30 70];% The two Angles
u = deg2rad(u);
M=length(u);% Number of angles
d_circular=l/2;% spacing b/w elements
circumference = N*d_circular;
a = circumference/2*pi; % Radius
for sourceNo=1:M
for m=0:N-1
% AF = sgma from n=0 to N-1 (exp(-1j*k*a*cos(phi-phin))
AF(m+1,sourceNo)=exp(-1i*k*a*cos(u(sourceNo)-phi_n(m+1)));
end
end
size(AF)
AF
sum(AF,1)
Alternate expression (simpler, with no loops or indexing):
AF = exp(-1i*k*a*cos(u-phi_n.'))
sum(AF,1)
4 comentarios
Más respuestas (1)
Walter Roberson
el 30 de Abr. de 2024
u=[30 70];% The two Angles
Those look like degrees
AF(m)=sum(exp(-1i*k*a*(cos(u(sourceNo)-phi_n))));
But there you are treating them as radians.
You need cosd
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!