clear;close all;clc;
fc = 77e9;
fs = 1e7;
PRT = 160e-6;
T_sweep = 60e-6;
waveform = phased.LinearFMWaveform('PulseWidth',T_sweep,...
'PRF',1/PRT,'OutputFormat','Pulses','NumPulses',1,'SampleRate',fs);
antenna = phased.IsotropicAntennaElement('FrequencyRange',[1e9 81e9]);
target = phased.RadarTarget('Model','Nonfluctuating','MeanRCS',0.5,...
'PropagationSpeed',physconst('LightSpeed'),'OperatingFrequency',fc);
antennaplatform = phased.Platform('InitialPosition',[0;0;0],'Velocity',[0;0;0]);
targetplatform = phased.Platform('InitialPosition',[7000; 5000; 0],...
'Velocity',[0;0;0]);
[tgtrng,tgtang] = rangeangle(targetplatform.InitialPosition,...
antennaplatform.InitialPosition);
Pd = 0.9;
Pfa = 1e-6;
numpulses = 10;
SNR = albersheim(Pd,Pfa,10);
maxrange = 1.5e4;
lambda = physconst('LightSpeed')/fc;
tau = waveform.PulseWidth;
Pt = radareqpow(lambda,maxrange,SNR,tau,'RCS',0.5,'Gain',20);
transmitter = phased.Transmitter('PeakPower',50e3,'Gain',20,'LossFactor',0,...
'InUseOutputPort',true,'CoherentOnTransmit',true);
radiator = phased.Radiator('Sensor',antenna,...
'PropagationSpeed',physconst('LightSpeed'),'OperatingFrequency',fc);
collector = phased.Collector('Sensor',antenna,...
'PropagationSpeed',physconst('LightSpeed'),'Wavefront','Plane',...
'OperatingFrequency',fc);
receiver = phased.ReceiverPreamp('Gain',20,'NoiseFigure',2,...
'ReferenceTemperature',290,'SampleRate',fs,...
'EnableInputPort',true,'SeedSource','Property','Seed',1e3);
channel = phased.FreeSpace(...
'PropagationSpeed',physconst('LightSpeed'),...
'OperatingFrequency',fc,'TwoWayPropagation',false,...
'SampleRate',fs);
T = 1/waveform.PRF;
txpos = antennaplatform.InitialPosition;
rxsig = zeros(int16(fs*T),numpulses);
for n = 1:numpulses
[tgtpos,tgtvel] = targetplatform(T);
[tgtrng,tgtang] = rangeangle(tgtpos,txpos);
sig = waveform();
[sig,txstatus] = transmitter(sig);
sig = radiator(sig,tgtang);
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);
rxsig(:,n) = receiver(sig,~txstatus);
end
rxsig = pulsint(rxsig,'noncoherent');
t = unigrid(0,1/receiver.SampleRate,T,'[)');
rangegates = (physconst('LightSpeed')*t)/2;
plot(rangegates/1e3,rxsig)
hold on
xlabel('range (km)')
ylabel('Power');
ylim = get(gca,'YLim');
plot([tgtrng/1e3,tgtrng/1e3],[0 ylim(2)],'r')
hold off