clear; clc
hsensor = phased.IsotropicAntennaElement(...
'FrequencyRange',[5e9 15e9]);
htx = phased.Transmitter('Gain',20,'InUseOutputPort',true);
fc = 10e9;
htgt = phased.RadarTarget('Model','Nonfluctuating',...
'MeanRCS',1,'OperatingFrequency',fc);
txloc = [0;0;0];
tgtloc = [5000;5000;10];
htxloc = phased.Platform('InitialPosition',txloc);
htgtloc = phased.Platform('InitialPosition',tgtloc);
[tgtrng,tgtang] = rangeangle(htgtloc.InitialPosition,...
htxloc.InitialPosition);
hwav = phased.RectangularWaveform('PulseWidth',25e-6,...
'OutputFormat','Pulses','PRF',1e4,'NumPulses',1);
c = physconst('LightSpeed');
maxrange = c/(2*hwav.PRF);
SNR = npwgnthresh(1e-6,1,'noncoherent');
Pt = radareqpow(c/fc,maxrange,SNR,...
hwav.PulseWidth,'RCS',htgt.MeanRCS,'Gain',htx.Gain);
htx.PeakPower = Pt;
hrad = phased.Radiator('PropagationSpeed',c,...
'OperatingFrequency',fc,'Sensor',hsensor);
hspace = phased.FreeSpace('PropagationSpeed',c,...
'OperatingFrequency',fc,'TwoWayPropagation',false);
hcol = phased.Collector('PropagationSpeed',c,...
'OperatingFrequency',fc,'Sensor',hsensor);
hrec = phased.ReceiverPreamp('NoiseFigure',0,...
'EnableInputPort',true,'SeedSource','Property','Seed',2e3);
hmf = phased.MatchedFilter(...
'Coefficients',getMatchedFilter(hwav),...
'GainOutputPort',true);
wf = step(hwav);
[wf,txstatus] = step(htx,wf);
wf = step(hrad,wf,tgtang);
wf = step(hspace,wf,txloc,tgtloc,[0;0;0],[0;0;0]);
wf = step(htgt,wf);
wf = step(hspace,wf,tgtloc,txloc,[0;0;0],[0;0;0]);
wf = step(hcol,wf,tgtang);
rx_puls = step(hrec,wf,~txstatus);
[mf_puls,mfgain] = step(hmf,rx_puls);
Gd = length(hmf.Coefficients)-1;
mf_puls=[mf_puls(Gd+1:end); mf_puls(1:Gd)];
subplot(2,1,1);
t = unigrid(0,1e-6,1e-4,'[)');
rangegates = c.*t;
rangegates = rangegates/2;
plot(rangegates,abs(rx_puls)); title('Received Pulse');
ylabel('Amplitude'); hold on;
plot([tgtrng, tgtrng], [0 max(abs(rx_puls))],'r');
subplot(2,1,2)
plot(rangegates,abs(mf_puls)); title('With Matched Filtering');
xlabel('Meters'); ylabel('Amplitude'); hold on;
plot([tgtrng, tgtrng], [0 max(abs(mf_puls))],'r');