# Basic Radar Using Phase-Coded Waveform

Instead of the rectangular waveform used in the Signal Simulation example, you can use a phase-coded waveform. To do so, replace the phased.RectangularWaveform System object™ with phased.PhaseCodedWaveform.

waveform = phased.PhaseCodedWaveform('Code','Frank','NumChips',4,...
'ChipWidth',1e-6,'PRF',5e3,'OutputFormat','Pulses',...
'NumPulses',1);

Then, redefine the pulse width, tau , using the properties of the new waveform.

tau = waveform.ChipWidth*waveform.NumChips;

The remainder of the code is almost identical to the code in the original examples and is presented here without comments. For a detailed explanation of how the code works, see the original Signal Simulation example.

antenna = phased.IsotropicAntennaElement('FrequencyRange',[1e9 10e9]);
'MeanRCS',0.5,'PropagationSpeed',physconst('LightSpeed'),...
'OperatingFrequency',4e9);
transmitterplatform = phased.Platform('InitialPosition',[0;0;0],...
'Velocity',[0;0;0]);
targetplatform = phased.Platform('InitialPosition',[7000; 5000; 0],...
'Velocity',[-15;-10;0]);
[tgtrng,tgtang] = rangeangle(targetplatform.InitialPosition,...
transmitterplatform.InitialPosition);

% Use the radar equation to compute the transmitted power needed for a given Pd and Pfa.
numpulses = 10;
Pd = 0.9;
Pfa = 1e-6;
maxrange = 1.5e4;
lambda = physconst('LightSpeed')/target.OperatingFrequency;
RCS = 0.5;
Ts = 290;
SNR = albersheim(Pd,Pfa,10);
Gain = 20;
dbterms = db2pow(SNR - 2*Gain);
Pt = (4*pi)^3*physconst('Boltzmann')*Ts/tau/RCS/(lambda^2)*maxrange^4*dbterms;

transmitter = phased.Transmitter('PeakPower',50e3,'Gain',20,...
'LossFactor',0,'InUseOutputPort',true,...
'CoherentOnTransmit',true);
'PropagationSpeed',physconst('LightSpeed'),...
'OperatingFrequency',4e9);
collector = phased.Collector('Sensor',antenna,...
'PropagationSpeed',physconst('LightSpeed'),...
'Wavefront','Plane','OperatingFrequency',4e9);
'ReferenceTemperature',290,'SampleRate',1e6,...
'EnableInputPort',true,'SeedSource','Property','Seed',1e3);
channel = phased.FreeSpace(...
'PropagationSpeed',physconst('LightSpeed'),...
'OperatingFrequency',4e9,'TwoWayPropagation',false,...
'SampleRate',1e6);
T = 1/waveform.PRF;
txpos = transmitterplatform.InitialPosition;
rxsig = zeros(waveform.SampleRate*T,numpulses);
for n = 1:numpulses
[tgtpos,tgtvel] = targetplatform(T);
[tgtrng,tgtang] = rangeangle(tgtpos,txpos);
sig = waveform();
[sig,txstatus] = transmitter(sig);
sig = channel(sig,txpos,tgtpos,[0;0;0],tgtvel);
sig = target(sig);
sig = channel(sig,tgtpos,txpos,tgtvel,[0;0;0]);
sig = collector(sig,tgtang);