Filter löschen
Filter löschen

I tried this code but it gives me an error

7 Ansichten (letzte 30 Tage)
Sadiq Akbar
Sadiq Akbar am 30 Apr. 2024
Kommentiert: Voss am 30 Apr. 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

Akzeptierte Antwort

Voss
Voss am 30 Apr. 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)
ans = 1x2
8 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
AF
AF =
-0.9330 - 0.3599i 0.5930 - 0.8052i 0.9072 - 0.4206i -0.3417 + 0.9398i 0.6297 - 0.7769i 0.8245 + 0.5659i -0.7017 - 0.7125i -0.5601 + 0.8285i -0.9330 + 0.3599i 0.5930 + 0.8052i 0.9072 + 0.4206i -0.3417 - 0.9398i 0.6297 + 0.7769i 0.8245 - 0.5659i -0.7017 + 0.7125i -0.5601 - 0.8285i
sum(AF,1)
ans =
-0.1955 - 0.0000i 1.0314 + 0.0000i
Alternate expression (simpler, with no loops or indexing):
AF = exp(-1i*k*a*cos(u-phi_n.'))
AF =
-0.9330 - 0.3599i 0.5930 - 0.8052i 0.9072 - 0.4206i -0.3417 + 0.9398i 0.6297 - 0.7769i 0.8245 + 0.5659i -0.7017 - 0.7125i -0.5601 + 0.8285i -0.9330 + 0.3599i 0.5930 + 0.8052i 0.9072 + 0.4206i -0.3417 - 0.9398i 0.6297 + 0.7769i 0.8245 - 0.5659i -0.7017 + 0.7125i -0.5601 - 0.8285i
sum(AF,1)
ans =
-0.1955 - 0.0000i 1.0314 + 0.0000i
  4 Kommentare
Sadiq Akbar
Sadiq Akbar am 30 Apr. 2024
Thanks a lot for your kind response. Yes, its ok now. Thanks once again.
Voss
Voss am 30 Apr. 2024
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 30 Apr. 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
  1 Kommentar
Sadiq Akbar
Sadiq Akbar am 30 Apr. 2024
Thanks a lot for your kind response. i replaced that by cosd but still it gives an error.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Antennas, Microphones, and Sonar Transducers finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by