hello i am trying to run the following attached matlab code on arduino nano. i don't own the board yet but i plan to purchase it. thanks very much for your help.
%% filename: PolarizationExample
%% Modeling and Analyzing Polarization
% This example introduces the basic concept of polarization. It shows how
% to analyze the polarized field and model the signal transmission between
% polarized antennas and targets using Phased Array System Toolbox(TM).
% Copyright 2012-2016 The MathWorks, Inc.
%% Polarization of an Electromagnetic Field
% The electromagnetic field generated by an antenna is orthogonal to the
% propagation direction in the far field. The field can be pointing to any
% direction in this plane, and therefore can be decomposed into two
% orthogonal components. Theoretically, there are an infinite number of
% ways to define these two components, but most often, one uses either
% (H,V) set or (L,R) set. (H,V) stands for horizontal and vertical, which
% can be easily pictured as x and y component; while (L,R) stands for left
% and right circular. It may be difficult to imagine that a vector in space
% can have a circular component in it, the secret lies in the fact that
% each component can be a complex number, which greatly increases the
% complexity of the trace of such a vector.
%
% Let's look at several simple examples. The time varying field can be
% written as
%
% $$ E = \bf{u}_h|E_h|{\rm cos}(\omega t-kz+\phi_h) +
% \bf{u}_v|E_v|{\rm cos}(\omega t-kz+\phi_v) $$
%
% where
%
% $$ E_h = |E_h|e^{j\phi_h}, E_v = |E_v|e^{j\phi_v} $$
%
% are the two components in phasor representation. $\bf{u}_h$ and
% $\bf{u}_v$ are the unit vector of h and v axes, respectively.
%
% The simplest case is probably a linear polarization, which happens when
% the two components are always in phase. Assume
%
% $$ |E_h|=|E_v|=1, \phi_h=\phi_v=0 $$,
%
% the field can be represented by a vector of [1;1]. The polarization for
% such a field looks like
fv = [1;1];
helperPolarizationView(fv)
%%
% From the figure, it is clear that the combined polarization is along the
% 45 degrees diagonal.
%
% The plot in the upper right portion of the figure is often referred to as
% the polarization ellipse. It is the projection of the combined field
% trace on the H-V plane. The polarization ellipse is often characterized
% by two angles, the tilt angle (also known as orientation angle) $\tau$
% and the ellipticity angle $\epsilon$. In this case, the tilt angle is 45
% degrees and the ellipticity angle is 0. The dot on the ellipse shows how
% the combined field moves along the trace on the H-V plane while time
% passes.
%
% A polarized field can also be represented by Stokes vector, which is a
% length-4 vector. The corresponding Stokes vector of the linear
% polarization, [1;1], is given by
s = stokes(fv)
%%
% Note that all 4 entries in the vector are real numbers. In fact, all
% these entries are measurable. In addition, it can be shown that the four
% quantities always satisfy the following equation
%
% $$ s(1)^2 = s(2)^2 + s(3)^2 + s(4)^2 $$.
%
% Therefore, each set of Stokes can be considered as a point on a sphere.
% Such a sphere is referred to as a Poincare sphere. The Poincare sphere
% for the above field is shown in the bottom right portion of the figure.
%
% Next is a circular polarized field, where
%
% $$ |E_h|=|E_v|=1, \phi_h=0, \phi_v=\pi/2. $$
%
fv = [1;1i];
helperPolarizationView(fv)
%%
% The figure shows that the trace of the combined field is a circle. Both
% the polarization ellipse and the Poincare sphere shows that the field is
% left circularly polarized.
%
% In general, the trace of a field is an ellipse, as shown below
fv = [2+1i;1-1i];
helperPolarizationView(fv)
%% Polarization of an Antenna
% The polarization of an antenna is defined as the polarization of the
% field transmitted by the antenna regardless whether it's in the
% transmitting or receiving mode. However, as mentioned earlier, the
% polarization is defined in the plane that is orthogonal to the
% propagation direction. Therefore, it is defined in the local coordinate
% system of each propagation direction, as shown in the following diagram.
%
% <<../PolarizationExample_localhv.png>>
%%
% Some antennas have a structure that determines its polarization, such as
% a dipole. The dipole antenna has a polarization that is parallel to its
% orientation. Assuming the frequency is 300 MHz, for a vertical short
% dipole, the polarization response at boresight, i.e., 0 degrees azimuth
% and 0 degrees elevation, is given by
antenna = phased.ShortDipoleAntennaElement('AxisDirection','Z');
fc = 3e8;
resp = antenna(fc,[0;0])
%%
% Note that the horizontal component is 0. If we change the orientation of
% the dipole antenna to horizontal, the vertical component becomes 0.
antenna = phased.ShortDipoleAntennaElement('AxisDirection','Y');
resp = antenna(fc,[0;0])
%% Polarization Loss
% When two antennas form a transmit/receive pair, their polarizations could
% affect the received signal power. Therefore, to collect a signal with
% maximum power possible, the receive antenna's polarization has to match
% the transmit antenna's polarization. The polarization matching factor can
% be measured as
%
% $$ \rho = |p_t^Tp_r|^2 $$
%
% where $p_t$ and $p_r$ represent the normalized polarization states of the
% transmit and receive antenna, respectively.
%
% Assume both transmit and receive antennas are short dipoles. The transmit
% antenna sits at the origin and the receive antenna at location (100,0,0).
% First, consider the case where both antennas are along Y axis and face
% each other. This is the scenario where the two antennas are matched in
% polarization.
pos_r = [100;0;0];
lclaxes_t = azelaxes(0,0); % transmitter coordinate system
lclaxes_r = azelaxes(180,0); % receiver faces transmitter
ang_t = [0;0]; % receiver at transmitter's boresight
ang_r = [0;0]; % transmitter at receiver's boresight
txAntenna = phased.ShortDipoleAntennaElement('AxisDirection','Z');
resp_t = txAntenna(fc,ang_t);
rxAntenna = phased.ShortDipoleAntennaElement('AxisDirection','Z');
resp_r = rxAntenna(fc,ang_r);
ploss = polloss([resp_t.H;resp_t.V],[resp_r.H;resp_r.V],pos_r,lclaxes_r)
%%
% The loss is 0 dB, indicating that there is no loss due to polarization
% mismatch. The section below shows the effect with a simulated signal.
% Signal simulation
[x,t] = helperPolarizationSignal;
% Create radiator and collector
radiator = phased.Radiator('Sensor',txAntenna,'Polarization','Combined',...
'OperatingFrequency',fc,'PropagationSpeed',3e8);
collector = ...
phased.Collector('Sensor',rxAntenna,'Polarization','Combined',...
'OperatingFrequency',fc,'PropagationSpeed',3e8);
% Signal transmission and reception
xt = radiator(x,ang_t,lclaxes_t);
y = collector(xt,ang_r,lclaxes_r);
helperPolarizationSignalPlot(t,x,y,'vertically')
%%
% The figure shows that the signal is received with no loss. Each short
% dipole antenna provides a gain of 1.76 dB, so the received signal is
% 1.5 times stronger than the transmitted signal.
%
% If instead a horizontally polarized antenna is used to receive the
% signal, the two antennas are now orthogonal in polarization and as a
% result, no power will be delivered to the received antenna. The
% polarization loss can be found by
rxAntenna = phased.ShortDipoleAntennaElement('AxisDirection','Y');
resp_r = rxAntenna(fc,ang_r);
ploss = polloss([resp_t.H;resp_t.V],[resp_r.H;resp_r.V],pos_r,lclaxes_r)
%%
% This process can be better understood using the following diagram.
%
% <<../PolarizationExample_txrxpol.png>>
%
% As the diagram shows, the polarization of an antenna can be seen as a
% filter blocking out any polarized wave that is orthogonal to the
% antenna's own polarization state.
%
% As expected, the signal simulation shows that the received signal is 0.
collector = ...
phased.Collector('Sensor',rxAntenna,'Polarization','Combined',...
'OperatingFrequency',fc,'PropagationSpeed',3e8);
% Signal transmission and reception
xt = radiator(x,ang_t,lclaxes_t);
y = collector(xt,ang_r,lclaxes_r);
helperPolarizationSignalPlot(t,x,y,'horizontally')
%%
% One can rotate the receive antenna to get a partial match in
% polarization. For instance, assume the receiving antenna in the previous
% example is rotated 45 degrees around x axis, then the received signal is
% no longer 0, although not as strong as when the polarizations are
% matched.
% Rotate axes
lclaxes_r = rotx(45)*azelaxes(180,0);
% Signal transmission and reception
xt = radiator(x,ang_t,lclaxes_t);
y = collector(xt,ang_r,lclaxes_r);
helperPolarizationSignalPlot(t,x,y,'45 degree')
%%
% The corresponding polarization loss is
ploss = polloss([resp_t.H;resp_t.V],[resp_r.H;resp_r.V],pos_r,lclaxes_r)
% measured in dB.
%% Target Polarization Signature
% When an electromagnetic wave hits the target, the wave will be scattered
% off the target and some energy will be transferred between two orthogonal
% polarization components. Therefore, the target scattering mechanism is
% often modeled by a 2x2 radar cross section (RCS) matrix (also known as
% scattering matrix), whose diagonal terms specify how the target scatters
% the energy into the original H and V polarization component and off
% diagonal terms specify how the target scatters the energy into the
% opposite polarization component.
%
% Because the transmit and receive antennas can have any combination of
% polarizations, it is often of interest to look at the polarization
% signature for a target for different polarization configurations. The
% signature plots the received power under different polarizations as a
% function of the tilt angle and the ellipticity angle of the transmit
% polarization ellipse. This can also be seen as a measure of the effective
% RCS. Two most widely used polarization signatures (also known as
% polarization responses), are co-polarization (co-pol) response and cross
% polarization (cross-pol) response. Co-pol response uses the same
% polarization for both transmit and receive while the cross-pol response
% uses the orthogonal polarization to receive.
%
% The simplest target is a sphere, whose RCS matrix is given by [1 0;0 1],
% meaning that the reflected polarization is the same as the incident
% polarization. The polarization signature for a sphere is given by
s = eye(2);
subplot(211); polsignature(s,'c');
subplot(212); polsignature(s,'x');
%%
% From the plot, it can be seen that for such a target, a linear
% polarization, where the ellipticity angle is 0, generates the maximum
% return in a co-pol setting while a circular polarization, where the
% ellipticity angle is either 45 or -45 degrees, generates the maximum
% return in a cross-pol configuration.
%
% A more complicated target is a dihedral, which is essentially a corner
% that reflects the wave twice, as shown in left side of the following
% sketch:
%
% <<../PolarizationExample_dihedral.png>>
%
% The right side of the above figure shows how the polarization field
% changes along the two reflections. After the two reflections, the
% horizontal polarization component remains the same while the vertical
% polarization component is reversed. Hence, its cross section matrix and
% polarization signature are give by
s = [1 0;0 -1];
subplot(211); polsignature(s,'c')
subplot(212); polsignature(s,'x')
%%
% The signature shows that the circular polarization works best in a co-pol
% setting while 45-degree linear polarization works best in a cross-pol
% situation.
%% Simulation of Polarized Signal Propagation Using Antenna and Target
% Putting everything together, the polarized signal is first transmitted by
% an antenna, then bounces off a target, and finally gets received at the
% receive antenna. Next is a simulation for this signal flow.
%
% The simulation assumes a vertical dipole as the transmit antenna, a
% horizontal dipole as the receive antenna, and a target whose RCS matrix
% is [0 1;1 0], which flips the signal's polarization. For the illustration
% purpose, the propagation in free space is ignored because it does not
% affect the polarization. It is also assumed that the transmit antenna,
% the target, and the receive antenna are on a line along the transmit
% antenna's boresight. The local coordinate system is the same for the
% transmit antenna and the target. The receive antenna is facing the
% transmit antenna.
% Define transmit and antenna
txAntenna = phased.ShortDipoleAntennaElement('AxisDirection','Z');
rxAntenna = phased.ShortDipoleAntennaElement('AxisDirection','Y');
radiator = phased.Radiator('Sensor',txAntenna,'Polarization','Combined');
collector = phased.Collector('Sensor',rxAntenna,'Polarization','Combined');
% Simulate signal
[x,t] = helperPolarizationSignal;
% Incident and arriving angles
ang_tx = [0;0];
ang_tgt_in = [180;0];
ang_tgt_out = [0;0];
ang_rx = [0;0];
% Local coordinate system
lclaxes_tx = azelaxes(0,0);
lclaxes_tgt = lclaxes_tx;
lclaxes_rx = azelaxes(180,0);
% Define target
target = phased.RadarTarget('EnablePolarization',true,...
'Mode','Bistatic','ScatteringMatrix',[0 1;1 0]);
% Simulate received signal
xt = radiator(x,ang_tx,lclaxes_tx); % radiate
xr = target(xt,ang_tgt_in,ang_tgt_out,lclaxes_tgt); % reflect
y = collector(xr,ang_rx,lclaxes_rx); % collect
helperPolarizationSignalPlot(t,x,y,'horizontally');
%%
% Note that because the target flips the polarization components, the
% horizontally polarized antenna is able to receive the signal sent with a
% vertically polarized antenna.
%% Summary
% This example reviews the basic concepts of polarization and introduces
% how to analyze and model polarized antennas and targets using Phased
% Array System Toolbox.
%%filename: helperPolarizationSignalPlot
function helperPolarizationSignalPlot(t,x,y,rxpol)
% This function helperPolarizationSignalPlot is only in support of
% PolarizationExample.
subplot(211);
plot(t,x,'Tag','TxSignal');
xlabel('Time (s)');
ylabel('Amplitude (V)');
axis([0 1 -1.5 1.5]);
title('Transmitted signal with vertically polarized dipole');
subplot(212);
yr = real(y);
plot(t,yr,'Tag','RxSignal');
xlabel('Time (s)');
ylabel('Amplitude (V)');
ybound = max(1.5, max(abs(yr)));
axis([0 1 -ybound ybound]);
title(sprintf('Received signal with %s polarized dipole',rxpol));
%%filename:helperPolarizationView
function helperPolarizationView(Ein)
% This function helperPolarizationView is only in support of
% PolarizationExample.
% Copyright 2012-2014 The MathWorks, Inc.
Ein = Ein/norm(Ein);
fs = 50;
t = 0:1/fs:1;
fc = 3e8;
c = 3e8;
lambda = c/fc;
k = 2*pi/lambda;
omega = 2*pi/0.5; % 2 rotation per second
dx = 0.01;
x = 0:dx:2;
npts = numel(x);
s_z = real(exp(1i*(omega*t(1)-k*x))*Ein(2));
s_y = real(exp(1i*(omega*t(1)-k*x))*Ein(1));
clf;
set(gcf,'Color','white')
subplot(2,3,6);
stokes(Ein);
set(gca,'CameraViewAngle',4.8)
title('')
text(1,0,1.9,'Poincare Sphere','FontWeight','bold')
%%
subplot(2,3,[1 2 4 5]);
haxis_y = line([0 0],[-1.2 2.3],[0 0],'Color','k');
hasbehavior(haxis_y,'Legend',false);
text(0,2.4,0,'H','Color','k','FontWeight','bold');
haxis_z = line([0 0],[0 0],[-1.2 1.2],'Color','r');
hasbehavior(haxis_z,'Legend',false);
text(0,0,1.3,'V','Color','r','FontWeight','bold');
haxis_x = line([-0.2 3.2],[0 0],[0 0],'Color','b');
hasbehavior(haxis_x,'Legend',false);
text(3.3,0,0,'r','Color','b','FontWeight','bold');
axis([-0.5 3.5 -1.5 2.5 -1.5 1.5]);
hline_y = line(x,s_y,zeros(1,npts),'LineWidth',2,'LineStyle','none','Marker','.','Color','k');
hline_z = line(x,zeros(1,npts),s_z,'LineWidth',2,'LineStyle','none','Marker','.','Color','r');
hline_p = line(x,s_y,s_z,'LineWidth',2,'LineStyle','-','Color','b');
hvec = line([0 0],[0 s_y(1)],[0 s_y(2)],'LineStyle','-','Color','b','LineWidth',3);
hdot = line(0,s_y(1),s_y(2),'Marker','.','Color','b','MarkerSize',30);
text(0,0,1.8,'H, V and Combined Fields','FontWeight','bold')
view(45,30);
axis off;
set(gca,'CameraPosition',[17.1879 -15.6238 13.0003],'CameraTarget',[1.27803 0.286092 0.00987012], 'CameraViewAngle', [6.94742])% CameraPosition = [17.1879 -15.6238 13.0003]
subplot(2,3,3);
polellip(Ein);
hellip_ax = gca;
set(get(hellip_ax,'Title'),'FontWeight','bold','FontSize',get(0,'DefaultTextFontSize'))
set(hellip_ax,'XLimMode','manual','YLimMode','manual','Xlim',[-1 1],'YLim',[-1 1])
htrace = line(s_y(1),s_z(1),'Parent',hellip_ax,'Marker','.','Color','b','MarkerSize',30);
%%
for m = 2:numel(t)
s_z = real(exp(1i*(omega*t(m)-k*x))*Ein(2));
s_y = real(exp(1i*(omega*t(m)-k*x))*Ein(1));
set(hline_z,'ZData',s_z);
set(hline_y,'YData',s_y);
set(hline_p,'YData',s_y,'ZData',s_z);
set(hvec,'YData',[0 s_y(1)],'ZData',[0 s_z(1)]);
set(hdot,'YData',s_y(1),'ZData',s_z(1));
set(htrace,'XData',s_y(1),'YData',s_z(1));
drawnow;
pause(0.1);
end
% [EOF]
%%filename: helperPolarizationSignal
function [x,t] = helperPolarizationSignal
% This function helperPolarizationSignal is only in support of
% PolarizationExample.
fs = 100;
f = 5;
t = (0:1/fs:1-1/fs).';
x = sin(2*pi*f*t);