%% Create Custom PCB Antenna and Analyze Impedance
% Create a custom PCB antenna and analyze the impedance.
% Create a circle with a radius of 0.075 m.

c1 = antenna.Circle( 'Center' ,[0,0], 'Radius' ,0.075);

%
% Create a rectangle with a length of 0.05 m and width of 0.01 m.

r1 = antenna.Rectangle('Center',[0,0],'Length',0.05,'Width',0.01, ...
    'NumPoints',20);

%
% Create a patch-like radiator and view the structure.

p = c1-r1;
figure
show(p)

%
% Create a ground plane with a length of 0.2 m and a width of 0.2 m.

Lgp = 0.2;
Wgp = 0.2;
g1 = antenna.Rectangle('Center',[0,0],'Length',Lgp,'Width',Wgp);

%
% Use pcbStack to create a PCB antenna. Thickness of PCB antenna is 0.003 m.

patchModel = pcbStack;

%
% Make a board shape like the groundplane.

patchModel.BoardShape = g1;

%
% The PCB antenna has a thickness of 0.003 m. Assign this thickness to the PCB board.

h = 3e-3;
patchModel.BoardThickness = h;

%
% Assign metal layers to the PCB antenna starting with the top most layer.

patchModel.Layers = {p,g1};

%
% Assign the feed location in the syntax format [x,y,layer1,layer2]. Indicate the coordinate location and the connection between the two layers.

patchModel.FeedLocations = [0 0.025 1 2];

%
% Assign the diameter of the probe feed to 0.001 m. The probe feed connects layer 1 and layer 2.

patchModel.FeedDiameter = 1.0e-3;

%
% Use Air as the dielectric between the two layers.

patchModel.Substrate = dielectric('Air');

%
% View the custom PCB antenna.

figure
show(patchModel)

%
% Analyze the impedance over a frequency range of 950 MHz to 1.1 GHz.

figure
impedance(patchModel,[linspace(950e6,1.1e9,30)])