image thumbnail
from Cylindrical Near Field To Far Field Transform by Arinjay Vivek
Developing a GUI in MATLAB for cylindrical Near Field To Far Field Transform

main.m
%   Near Field To Far field Calculator and plotter
%%%%%%%%%%%%%%%%%%%%%%%%%%  Initialization section.
clc % clears the command window
clear % clears variable
%%%%%%%%%%%%%%%%%%
load('fd1')
load('ff1')
r1=(size(fd1));
r2=(size(ff1));
disp 'The Size of of Ez samples Matrix'
(size(fd1))
disp 'The Size of of Ephi samples Matrix'
(size(ff1))
M=r1(1,1);
N=r1(1,2);
O=r2(1,1);
P=r2(1,2);
for p=1:M
    REx(p,1)=fd1(p,4);
    IEx(p,1)=fd1(p,7);
    REz(p,1)=fd1(p,6);
    IEz(p,1)=fd1(p,9);
end
Ephi=REx+i*IEx;
Ez=REz+i*IEz;
disp 'The Size of of Ephi samples Matrix'
(size(Ephi))
disp 'The Size of of Ez samples Matrix'
(size(Ez))
%%%%%%%%%%%%%%% loading crimp

%if Frequency isempty(reply)
%   reply = 'pls enter radius of scan';
%%%%%%%%%%%%%%%%%%%%%%%%   N=No. of samples in phi direction around cylinder axsis
% samples more than 100 X 100 take computation time and memory hang
% To implement%warning:The min no.of M = 
%To implement %%warning:The min no. N =
%N=ceil( (4*pi*a)/Lamda);
%%%%%%%%%%%%%%%%%%%%%%%%   M=No. of samples in Z direction parallel cylinder axsis
%M=ceil( (2*L)/Lamda);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp 'To load Load Data File: Press Enter'
input(':') 
%%%%%%%%%%%%%%%%%%%%%%creating Temp M X N Matrix%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%of Ez and E phi because of symmetry in phi
for p=1:M
    for q=1:180
        DEz(p,q)=Ez(p,1);
        DEphi(p,q)=Ephi(p,1);
    end
end
%save('DEz')
%save('DEphi')
%%%%%%%%%%Giving back values to  
%%%%%%%%%%%%M X N Matrix of Ez because of symmetry in phi
for p=1:M
    for q=1:180
        Ez(p,q)=DEz(p,q);
        Ephi(p,q)=DEphi(p,q);
    end
end

%%%%%%% auto size readind%%%
disp 'The Size of of New Ez samples Matrix'
(size(Ez))
disp 'The Size of of New Ephi samples Matrix'
(size(Ephi))
r1=(size(Ez));
r2=(size(Ephi));
M=r1(1,1);
N=r1(1,2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%optional crimping %%%%%crimping data of Ez in half
   R=M-1;
    M=ceil(R/2)
    N=N
for r=1:M
    for s=1:N
        DEphi(r,s)=Ephi(r*2,s);
        DEz(r,s)=Ez(r*2,s);
    end
end


%amend
%r=0;
%s=0;
%for p=1:ceil(M/2)
%r=r+1
%    for q=1:ceil(N/2)
%s=s+1
%        DEz(r,s)=Ez(p*2,q*2);
%        DEphi(r,s)=Ephi(p*2,q*2);
%    end
%end
%%%% giving back crimped vales to Ez and Ephi 
%M=ceil(M/2);
%N=ceil(N/2);
%Ez=zeros(M,N);
%Ephi=zeros(M,N);
%for p=1:M
%    for q=1:N
%        Ez(p,q)=DEz(p,q);
%        Ephi(p,q)=DEphi(p,q);
%    end
%end
%%%%%
%%%%%%%%%optional crimping %%%%%crimping data of Ez by half
%for p=1:ceil(M/2)
%   for q=1:ceil(N)
%        DEz(p,q)=Ez(p*2,q);
%        DEphi(p,q)=Ez(p*2,q);
%    end
%end
%%%% giving back crimped vales to Ez 
%M=ceil(M/2);
%N=ceil(N);
%Ez=zeros(M,N);
%Ephi=zeros(M,N);
%for p=1:M
%    for q=1:N
%        Ez(p,q)=DEz(p,q);
%        Ephi(p,q)=DEphi(p,q);
%    end
%end
%%%%%%%%%optional crimping %%%%%crimping data of Ephi by half
%for p=1:ceil(M)
%   for q=1:ceil(N/2)
%        DEz(p,q)=Ez(p*2,q);
%        DEphi(p,q)=Ez(p*2,q);
%    end
%end
%%%% giving back crimped vales to Ephi 
%M=ceil(M);
%N=ceil(N/2);
%Ez=zeros(M,N);
%Ephi=zeros(M,N);
%for p=1:M
%    for q=1:N
%        Ez(p,q)=DEz(p,q);
%        Ephi(p,q)=DEphi(p,q);
%    end
%end
%%%%%%%%%%%%% delta phi , delta z,
%dphi=(2*pi/N);
%dz=L/(M-1);
%phi=linspace(0,360,N)*pi/180;
%z=linspace(-L/2,L/2,M);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% Input parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('DEphi')
load('DEz')
Ez=DEz;
Ephi=DEphi;
r1=(size(Ephi));
r2=(size(Ez));
disp 'The Size of of Ephi samples Matrix'
(size(Ephi))
disp 'The Size of of Ez samples Matrix'
(size(Ez))
M=r1(1,1);
N=r1(1,2);
disp 'Enter the frequency of Excitation in Ghz'
Frequency = input(':') 
%if Frequency isempty(reply)
%   reply = 'pls enter frequency';
Lamda = (3*10^(-1))/Frequency;
disp 'Wavelength in metres';
Lamda
disp 'Enter the radius of scan in metres'
rho = input(':'); 
%if Frequency isempty(reply)
%   reply = 'pls enter radius of scan';
disp 'Enter the Total Cylinder Length scanned in metres'
L = input(':') 


%%%%%%%%%%%%%%%% wave no.
k=2*pi/Lamda
%%%%%%%%%theta , h=kcos(theta), distance r, eeta=n2 and Hankel function
%%%%%%%% delta =angle  subtended by Half cylinder at antenna mid point
angle=L*0.5/rho; % in radians
Deg=ceil(atand(angle)); %%%%%%% angle in degrees
Theta=90-Deg;% % sherical co ord theta in degree
dtheta=linspace(Theta,180-Theta,M)*pi/180;
%%%%%%%%% temp theta matrix
temp=dtheta';
%%%%%%%%%%Giving back values to  M X N Matrix of theta because of symmetry
%%%%%%%%%%in phi
for p=1:M
    for q=1:N
        theta(p,q)=temp(p,1);
    end
end
%%%%%%% h=k*cos M X N matrix
for p=1:M
    for q=1:N
        h(p,q)=k*cos(theta(p,q));
    end
end
%%%%%%% r psition vector M X N matrix
for p=1:M
    for q=1:N
        r(p,q)=rho/cos(theta(p,q));
    end
end
save('r','h','theta')
%%%%%%%%%% n (neeta) square=k^2-h(p,q)^2
for p=1:M
    for q=1:N
        neeta2(p,q)=(k^2-h(p,q)^2);
    end
end
save('neeta2')
%%%%%%%%%%%% product of n and r =xeta
for p=1:M
    for q=1:N
        xeta(p,q)=(sqrt(neeta2(p,q)))*r(p,q);
    end
end
%%%%%%%%%% Hankel co efficients (Hankel function of second order)
for p=1:M
    for q=1:N
        H(p,q) = besselh(0,2,xeta(p,q));
    end
end
%%%%%%%%%% alpha n  along with co efficent using FFT2 on Ez
for p=1:M
    for q=1:N
        an(p,q)=[k/((4*pi^2)*neeta2(p,q)*H(p,q))]*fft2(Ez(p,q));
    end
end
%%%%%%%%%%%% Hankel derivative wrt propagation direction
format long e
for p=1:M
    for q=1:N
        H(p,q) = besselh(0,2,xeta(p,q));
    end
end
J=real(H);
Y=-1*imag(H);
for q=1:N
j(1,q)=1;
y(1,q)=-1;
end
%%temp routine
for p=1:M
    for q=1:N
        j(p+2,q) = J(p,1);
        y(p+2,q) = Y(p,1);
    end
end
%%%%%%%% computing Hankel prime
for p=1:M
    for q=1:N
        Jp(p,q) = 0.5*(j(p,1)-J(p,1));
        Yp(p,q) = 0.5*(y(p,1)-Y(p,1));
        Hp(p,q) = (Jp(p,q)-i*Yp(p,q));
    end
end
%%%%%%%%%% FFT2 of Ez term required for bn
for p=1:M
    for q=1:N
        fftEz(p,q)=fft2((h(p,q)*461/r(p,q))*Ez(p,q));
    end
end
%%%%%%%%%%% FFT2 of Ephi term required for bn
for p=1:M
    for q=1:N
        fftEphi(p,q)=fft2((neeta2(p,q))*Ephi(p,q));
    end
end
%%%%%%%%%%%%%%%%%%% beta n
for p=1:M
    for q=1:N
        bn(p,q)=(1/(4*pi^2)*neeta2(p,q)*Hp(p,q))*(fftEz(p,q)-fftEphi(p,q));
    end
end
%%%To amend %%%%%%%%%%%% Far Field Etheta and Ephi
%
for m=1:M
    for n=1:N
        Tan(m,n)=((i^n))*sin(theta(m,n))*an(m,n);
    end
end  
for m=1:M
    for n=1:N
        Tbn(m,n)=i*(i^n)*sin(theta(m,n))*bn(m,n);
    end
end   
    anFft=fft(Tan);
    bnFft=fft(Tbn);
for r=1:M
    for s=1:N
        ethee(r,s)=i*sin(theta(r,s))*bnFft(r,s);
    end
end

for p=1:M
    for q=1:N
        ephii(p,q)=sin(theta(p,q))*bnFft(p,q);
    end
end
save('ethee')
save('ephii')
%%%%%%%%%%%%%%old code for reference Far Field Etheta and Ephi
% to mend M,N
E1=ethee;
E2=ephii;
%%%%%%%%% random data check
%M=50;
%N=3;
%E1=rand(M,N);
%E2=rand(M,N);
%%%%%%%%%%%%For 3D plot in Db
Temp1=abs(E1).^2+abs(E2).^2;
for p=1:M
    for q=1:N
        amp(p,q)=10*log10(Temp1(p,q));
    end
end
d1theta=linspace(90,-90,M)*pi/180;
d1phi=linspace(-180,180,N)*pi/180;
for j=1:M
for k=1:N
theta1(j,k)=d1theta(1,j);
phi1(j,k)=d1phi(1,k);
end
end
for j=1:M
for k=1:N
X(j,k)= cos(phi1(j,k))*cos(theta1(j,k))*amp(j,k);
Y(j,k)= cos(theta1(j,k))*sin(phi1(j,k))*amp(j,k);
%X(j,k)= phi1(j,k);
%Y(j,k)=theta1(j,k);
end
end
T=length(d1theta)-ceil(M/2);
for j=1:T
for k=1:N
Z (j,k)=sin(theta1(j,k))*amp(j,k);
end
end
for j=T+1:M
for k=1:N
Z (j,k)=sin(theta1(j,k))*amp(j,k);
end
end
%colormap([0 0 0;1 1 1])
figure
surf(X,Y,Z)
hold
title('3D plot of far field');
legend('far Field (Db)');
%colormap hot
axis square
%%%%%%%%for polar plot at phi=0 cut
% degrees and plot on the same graph with autoscaling.
alpha=d1theta'; 
for j=1:length(alpha)
D1(j,1)=amp(j,1);
end
figure
polar(alpha,D1,'b');
hold
title('polar plot at phi=0 cut');
legend('far Field (Db)');
save


%axis square;

%view([.1 .1 .1])

%text(0.8978, 1.398, 0.408,'\ity','Fontsize',16);
set(gca,'CameraTarget',[0 0 0]);
set(gca,'CameraPosition',[1 1 .5]);
set(gca,'CameraViewAngle',80);
%set(gca,'CameraUpVector',[0. 0. 1.]);
set(gca,'DataAspectRatio', [1 1 1]);

axis off
hold off

Contact us at files@mathworks.com