關于MATLAB的問題
文章來源: 互聯(lián)網(wǎng) 錄入: mweda.com
我最近在看《通信天線建模與MATLAB仿真分析》這本書,第7章有個多帶天線Sierpinski蝴蝶結天線的仿真,可是我用書中配套的MATLAB程序仿真出的天線模型卻與書上不一樣(莫名其妙少了2個小三角),看了半天也看不出程序哪里出了問題,希望有人能幫幫我,提前謝謝了!
clear all
%Geometry data
S=2; %Stage of fractal growth
SM=5; %Stage of mesh growth
h=0.1; %Half-height of bowtie
flareangle=(0.5)*pi; %Bowtie flare angle
TAN=tan(flareangle/2);
%Identify vertex points
Count=1;
for s=1:SM^2
StepY=h/(SM^2-1);
y=(s-1)*StepY;
fuzzy=1-0.0001*s;
for ss=1:s
StepX=2*StepY*TAN;
x=-y*TAN+StepX*(ss-1);
X(Count)=x*fuzzy;
Y(Count)=y;
Count=Count+1;
end
end
%Create mesh triangles
p=[X; Y; zeros(1,length(X))];
TRI = delaunay(X,Y);
t=TRI';
TrianglesTotal=length(t);
for m=1:length(t)
n1=t(1,m); n2=t(2,m); n3=t(3,m);
Center(:,m)=1/3*(p(:,n1)+p(:,n2)+p(:,n3));
end
%Create fractal triangles
%Initial triangle
ArrayOfTrianglesX(:,1)=[-h*TAN 0 h*TAN]';
ArrayOfTrianglesY(:,1)=[h 0 h]';
CatPolygonX=[];
CatPolygonY=[];
for s=1:S
Length=length(ArrayOfTrianglesX(1,:));
ArrayOfTrianglesX1=[];
ArrayOfTrianglesY1=[];
for i=1:Length
InpX=ArrayOfTrianglesX(:,i);
InpY=ArrayOfTrianglesY(:,i);
[CatX, CatY, T1X, T1Y, T2X, T2Y, T3X, T3Y]=divider(InpX, InpY, TAN);
CatPolygonX=[CatPolygonX CatX];
CatPolygonY=[CatPolygonY CatY];
ArrayOfTrianglesX1=[ArrayOfTrianglesX1 T1X T2X T3X];
ArrayOfTrianglesY1=[ArrayOfTrianglesY1 T1Y T2Y T3Y];
end
ArrayOfTrianglesX=ArrayOfTrianglesX1;
ArrayOfTrianglesY=ArrayOfTrianglesY1;
end
Length=length(CatPolygonX(1,:));
ING=zeros(1,length(t));
for i=1:Length
ING = ING+inpolygon(Center(1,:), Center(2,:), CatPolygonX(:,i),CatPolygonY(:,i));
end
%Triangles to remove
for i=1:Length
IN =inpolygon(Center(1,:), Center(2,:), CatPolygonX(:,i),CatPolygonY(:,i));
Index =find(IN==1);
Array =sqrt((Center(1,Index)-CatPolygonX(1,i)).^2+(Center(2,Index)-CatPolygonY(1,i)).^2);
[Y,I]=min(Array);
ING(Index(I))=0;
Array =sqrt((Center(1,Index)-CatPolygonX(2,i)).^2+(Center(2,Index)-CatPolygonY(2,i)).^2);
[Y,I]=min(Array);
ING(Index(I))=0;
Array =sqrt((Center(1,Index)-CatPolygonX(3,i)).^2+(Center(2,Index)-CatPolygonY(3,i)).^2);
[Y,I]=min(Array);
ING(Index(I))=0;
end
%Remove unnecessary triangles
TrianglesTotal=length(t);
Triangle=[];
for m=1:TrianglesTotal
if(ING(m)==0)
Triangle=[Triangle t(:,m)];
end
end
clear t;
t=Triangle(:,2:length(Triangle)); %first triangle is removed
TrianglesTotal=length(t);
t(4,:)=1;
%Add mirror image to structure
p(2,:)=p(2,:)-StepY;
pbase=-p; tbase=t;
t=[tbase t+length(pbase)]; t(4,:)=1;
p=[pbase p];
%Eliminate equal points
length(p)
P(1:3,1)=p(1:3,1);
for L=2:length(p)
[M,N]=size(P);
Point=p(1:3,L);
Index=find(abs(sum(abs(P-repmat(Point,1,N))))<1.e-9);
if (isempty(Index))
P=[P Point];
end
end
length(P)
%Re-enumerate triangle points
[M,N]=size(P);
for L=1:length(t);
n=t(:,L);
for i=1:3
Index=find(abs(sum(abs(P-repmat(p(1:3,n(i)),1,N))))<1.e-9);
if(~isempty(Index))
t(i,L)=Index;
end
end
t(4,L)=1;
end
clear p; p=P;
%Save result
save fractal p t;
viewer fractal
view(0,90)
上面的程序調用下面的函數(shù)
function [CatX, CatY, T1X, T1Y, T2X, T2Y, T3X, T3Y]=divider(InpX, InpY, TAN);
h=max(InpY)-min(InpY);
CenterX=0.5*(min(InpX)+max(InpX));
CenterY=0.5*(min(InpY)+max(InpY));
CatX=[-h/2*TAN 0 h/2*TAN]'+CenterX;
CatY=[ 0 h/2 0]'+CenterY;
T1X=[-h*TAN -h/2*TAN 0]'+CenterX;
T1Y=[h/2 0 h/2]'+CenterY;
T2X=[0 h/2*TAN h*TAN]'+CenterX;
T2Y=[h/2 0 h/2]'+CenterY;
T3X=[-h/2*TAN 0 h/2*TAN]'+CenterX;
T3Y=[0 -h/2 0]'+CenterY;
網(wǎng)友回復:
此貼已結。問題已經(jīng)解決了,三角確錯了位置。
申明:網(wǎng)友回復良莠不齊,僅供參考。如需專業(yè)解答,請咨詢本站專家,或者學習本站天線設計視頻培訓課程。
-
5門天線設計視頻課程和一本圖書,將天線設計理論和實踐相結合,幫助您全面、系統(tǒng)、深入地學習天線設計,讓天線設計不再難...【詳細介紹】