如何用matlab畫天線的三維方向圖?
貼兩個畫著玩的:
下面給出振子天線三維方向圖的MATLAB代碼,以供參考。我計算了定向性,並取點源作為基準,繪製的是線性圖,程序還具有類似 Balanis 教材中切去部分方向圖的功能,以便查看。
close all; clear; clc;
Llambda = 0.5;
Lr = 2*pi*Llambda;
F = @(theta, phi) ((cos(Lr/2.*cos(theta)) - cos(Lr/2))./sin(theta)).^2;
Ntheta = 36; Nphi = 72;
theta = linspace(0,pi,Ntheta); phi = linspace(0,2*pi,Nphi);
dtheta = pi/Ntheta; dphi = 2*pi/Nphi;
theta([1 end]) = [eps pi-eps];
[THETA, PHI] = meshgrid(theta, phi);
R = F(THETA, PHI);
Ravg = sum(sum(R.*sin(THETA)*dtheta*dphi/(4*pi)));
R = R/Ravg;
D = max(R(:));
% for visual purposes, specify the segment of the pattern to be cut
phiI1 = 56; phiI2 = 72;
R(phiI1+1:phiI2-1, = NaN;
figure(1), hold on
% isotropic antenna pattern as reference
[x,y,z] = sphere;
p0 = surf(x,y,z,0);
set(p0, "facecolor",[.8 .8 .8],"facealpha",0.2,"edgealpha",0.4)
% antenna pattern
[x,y,z] = sph2cart(PHI, pi/2-THETA, R);
p1 = surf(x,y,z,R/D*2-1);
colormap jet;
set(p1, "facealpha",0.8,"edgealpha",0.5);
% additional cross section
[x,y,z] = sph2cart(PHI([phiI1 phiI2],:), pi/2-THETA([phiI1 phiI2],:), R([phiI1 phiI2],:));
p2 = patch(x",y",z","w");
set(p2, "facealpha",0.6,"edgealpha",0.2)
set(gcf, "render","painter","color","w")
view(45,8), axis image off
set(gca, "position", [-0.0 0.0 1 1])
樓上的畫圖太高端,我Matlab學得不好,只會一些簡單用法。
之前的答案有問題,經過樓上大神的提醒,現在修改一下。
%電基本振子的方向圖
clear;
clc;
theta=meshgrid(eps:pi/180:pi);
phi=meshgrid(eps:2*pi/180:2*pi)";
F=abs(sin(theta));
[x,y,z]=sph2cart(phi,pi/2-theta,F);%之前第二個變數直接寫的是theta,對照說明以後已改正
figure(1);
mesh(x,y,z);
title("電基本振子的立體方向圖");
xlabel("x"),ylabel("y"),zlabel("F( heta,phi)");
theta=linspace(eps,2*pi,100);
F_E=abs(sin(theta));
figure(2);
polar(theta,F_E);
title("E面方向圖");
這裡貼上立體方向圖和E面方向圖:
我還做了一個動態的,但我不知道怎麼弄GIF(尷尬……),就只貼代碼好了。
clear;
clc;
for i=1:30
theta=meshgrid(eps:pi/180:pi);
phi=meshgrid(eps:2*pi/180:2*pi)";
l=i*0.1;
f=abs(cos(2*pi*l*cos(theta))-cos(2*pi*l))./abs(sin(theta)+eps);
fmax=max(max(f));
[x,y,z]=sph2cart(phi,pi/2-theta,f/fmax);%之前第二個變數直接寫的是theta,對照說明以後已改正
mesh(x,y,z);
axis([-1 1 -1 1 0 1]);
title("對稱陣子方向圖隨著振子電長度的變化")
m(:,i)=getframe;
end
movie(m,1,1);
推薦閱讀:
※大家都用matlab做過哪些有趣的事兒?
※如何對四旋翼飛行器進行精確的數學建模?
※MATLAB 能幹嘛?
※怎樣利用MATLAB求一維含時薛定諤方程的數值解?
※數學中求解整數規劃在matlab中怎麼使用呢?
TAG:MATLAB |