Algoritmo binomial para arrays unidimensionales
Esta función usa un algoritmo binomial para obtener los pesos y fases de cada elemento de un array lineal. Los resultados de la función definen el apuntamiento del array en la dirección dada.
import Jama.Matrix;
Cmplx[] binomial(double d, double theta, double phi, int Num, int axis) { //d:element spacing in units of lambda
//theta:beam angle (in degrees)
//phi:azimut angle (in degrees)
//N:number of array elements
//axix:indicates which axis is used-->1 for x axis
// -->2 for y axis
//This function uses a binomial algorithm to calculate the weights and phases in an unidirectional array of antennas
double N=Num;
int N1=N-1;
int a=1;
double []v= new double[]{1.0, 1.0}; //define the vector we are going to use in the convolution
double[] P=new double[N]; //define the vector we are going to obtain as a result of the convolution
Cmplx[] z=new Cmplx[N];
Cmplx[] f=new Cmplx[N]; //vectors of N elements Cmplx type
double k;
if (axis==1){
k=(Math.sin(Math.toRadians(theta))*Math.cos(Math.toRadians(phi)));
}
if (axis==2){
k=(Math.sin(Math.toRadians(theta))*Math.sin(Math.toRadians(phi)));
}
double ang=Math.acos(k); //ang=arccos(sen(theta)*cos(phi))
double cose=Math.cos(ang);//cose=cos(ang)
double ps0=(2*Math.PI*d*cose); //find the phase that we are going to use to direct the array in the desired direction
double[] y=new double[N];
double[] fase=new double[N]; //vectors of N elements double type
if (N1>=1){
P=convolution(v, P, N1); //call to the convolucion.java function. In this case, it convolves the vector v with a vector of a dimension u = 1
//We pass the vector v, the vector P and N1 (number of antennas in the array minus one)
} //It returns the vector P with the result of the convolution, this vector P contains the weights of the array, since we are in a binomial algorithm
if (N1==0){
for (i=0; i<=N1; i++){
P[i]=1.0;
}
}
for (int n=0; n<N; n++){
f[n]=new Cmplx(0,-((n-(N-1)/2)*ps0)); //create a complex vector, with 0 as the real part, where the imaginary part are the
//successive phases that we are going to multiply to the weights
z[n]=P[n]*(Cmplx.exp(f[n])); //find the final result in the form of a complex number by multiplying the weights by the progressive phases,
//thus directing the array towards the direction indicated by theta and phi
y[n]=Cmplx.abs(z[n]); //find the absolute of the complexes, that is, the weights
fase[n]=(Math.atan2(z[n].imag, z[n].real)); //find the phase in radians
if (fase[n]<0){ // if the phase is less than 0
fase[n]=2*Math.PI+fase[n]; //add 2*pi
}
fase[n]=Math.toDegrees(fase[n]); //find the phase in degrees
}
writeFile("./mydatafiles/binomial.txt", y, fase);//write the weigths and phases in a text file
return z; //return the complex vector z, which contains the results of the algorithm
}