%% parameters.
fc = 77e9;
c = 3e8;
lambda = c/fc;
%%
% The sweep time can be computed based on the time needed for the signal to
% travel the unambiguous maximum range. In general, for an FMCW radar
% system, the sweep time should be at least 5 to 6 times the round trip
% time. This example uses a factor of 5.5.
range_max = 200;
tm = 5.5*range2time(range_max,c);
%%
% The sweep bandwidth can be determined according to the range resolution
% and the sweep slope is calculated using both sweep bandwidth and sweep
% time.
range_res = 1;
bw = range2bw(range_res,c);
sweep_slope = bw/tm;
%%
% Because an FMCW signal often occupies a huge bandwidth, setting the
% sample rate blindly to twice the bandwidth often stresses the capability
% of A/D converter hardware. To address this issue, one can often choose a
% lower sample rate. Two things can be considered here:
%
% # For a complex sampled signal, the sample rate can be set to the same as
% the bandwidth.
% # FMCW radars estimate the target range using the beat frequency embedded
% in the dechirped signal. The maximum beat frequency the radar needs to
% detect is the sum of the beat frequency corresponding to the maximum
% range and the maximum Doppler frequency. Hence, the sample rate only
% needs to be twice the maximum beat frequency.
%
% In this example, the beat frequency corresponding to the maximum range is
% given by
fr_max = range2beat(range_max,sweep_slope,c);
%%
% In addition, the maximum speed of a traveling car is about 230 km/h.
% Hence the maximum Doppler shift and the maximum beat frequency can be
% computed as
v_max = 230*1000/3600;
fd_max = speed2dop(2*v_max,lambda);
fb_max = fr_max+fd_max;
%%
% This example adopts a sample rate of the larger of twice the maximum beat
% frequency and the bandwidth.
fs = max(2*fb_max,bw);
%%
% The following table summarizes the radar parameters.
%
% System parameters Value
% ----------------------------------
% Operating frequency (GHz) 77
% Maximum target range (m) 200
% Range resolution (m) 1
% Maximum target speed (km/h) 230
% Sweep time (microseconds) 7.33
% Sweep bandwidth (MHz) 150
% Maximum beat frequency (MHz) 27.30
% Sample rate (MHz) 150
%%
% With all the information above, one can set up the FMCW waveform used
% in the radar system.
waveform = phased.FMCWWaveform('SweepTime',tm,'SweepBandwidth',bw,...
'SampleRate',fs);
%%
% This is a up-sweep linear FMCW signal, often referred to as sawtooth
% shape. One can examine the time-frequency plot of the generated signal.
sig = waveform();
figure(1)
plot(0:1/fs:tm-1/fs,real(sig));
xlabel('Time (s)'); ylabel('Amplitude (v)');
title('FMCW signal'); axis tight;
%% Target Model
car_dist = 10;
car_speed = 40*1000/3600;
car_rcs = db2pow(min(10*log10(car_dist)+5,20));
cartarget = phased.RadarTarget('MeanRCS',car_rcs,'PropagationSpeed',c,...
'OperatingFrequency',fc);
carmotion = phased.Platform('InitialPosition',[car_dist;0;0.5],...
'Velocity',[car_speed;0;0]);
cartarget2 = phased.RadarTarget('MeanRCS',car_rcs,'PropagationSpeed',c,...
'OperatingFrequency',fc);
carmotion2 = phased.Platform('InitialPosition',[20;0;0.5],...
'Velocity',[car_speed;0;0]);
%%
% The propagation model is assumed to be free space.
channel = phased.FreeSpace('PropagationSpeed',c,...
'OperatingFrequency',fc,'SampleRate',fs,'TwoWayPropagation',true);
%% Radar System Setup
ant_aperture = 6.06e-4; % in square meter
ant_gain = aperture2gain(ant_aperture,lambda); % in dB
tx_ppower = db2pow(5)*1e-3; % in watts
tx_gain = 9+ant_gain; % in dB
rx_gain = 15+ant_gain; % in dB
rx_nf = 4.5; % in dB
transmitter = phased.Transmitter('PeakPower',tx_ppower,'Gain',tx_gain);
receiver = phased.ReceiverPreamp('Gain',rx_gain,'NoiseFigure',rx_nf,...
'SampleRate',fs);
%%
% Automotive radars are generally mounted on vehicles, so they are often in
% motion. This example assumes the radar is traveling at a speed of 100
% km/h along x-axis. So the target car is approaching the radar at a
% relative speed of 4 km/h.
radar_speed = 100*1000/3600;
radarmotion = phased.Platform('InitialPosition',[0;0;0.5],...
'Velocity',[radar_speed;0;0]);
%% Radar Signal Simulation
% As briefly mentioned in earlier sections, an FMCW radar measures the
% range by examining the beat frequency in the dechirped signal. To extract
% this frequency, a dechirp operation is performed by mixing the received
% signal with the transmitted signal. After the mixing, the dechirped
% signal contains only individual frequency components that correspond to
% the target range.
%
% In addition, even though it is possible to extract the Doppler
% information from a single sweep, the Doppler shift is often extracted
% among several sweeps because within one pulse, the Doppler frequency is
% indistinguishable from the beat frequency. To measure the range and
% Doppler, an FMCW radar typically performs the following operations:
%
% # The waveform generator generates the FMCW signal.
% # The transmitter and the antenna amplify the signal and radiate the
% signal into space.
% # The signal propagates to the target, gets reflected by the target, and
% travels back to the radar.
% # The receiving antenna collects the signal.
% # The received signal is dechirped and saved in a buffer.
% # Once a certain number of sweeps fill the buffer, the Fourier transform
% is performed in both range and Doppler to extract the beat frequency as
% well as the Doppler shift. One can then estimate the range and speed of
% the target using these results. Range and Doppler can also be shown as an
% image and give an intuitive indication of where the target is in the
% range and speed domain.
%
% The next section simulates the process outlined above. A total of 64
% sweeps are simulated and a range Doppler response is generated at the
% end.
%
% During the simulation, a spectrum analyzer is used to show the spectrum
% of each received sweep as well as its dechirped counterpart.
specanalyzer = dsp.SpectrumAnalyzer('SampleRate',fs,...
'PlotAsTwoSidedSpectrum',true,...
'Title','Spectrum for received and dechirped signal',...
'ShowLegend',true);
%%
% Next, run the simulation loop.
rng(2012);
Nsweep = 64;
xr = complex(zeros(waveform.SampleRate*waveform.SweepTime,Nsweep));
%for m = 1:Nsweep
while 1
% Update radar and target positions
[radar_pos,radar_vel] = radarmotion(waveform.SweepTime);
[tgt_pos,tgt_vel] = carmotion(waveform.SweepTime);
[tgt_pos2,tgt_vel2] = carmotion2(waveform.SweepTime);
% Transmit FMCW waveform
sig = waveform();
txsig = transmitter(sig);
% Propagate the signal and reflect off the target
txsig2 = channel(txsig,radar_pos,tgt_pos2,radar_vel,tgt_vel2);
txsig = channel(txsig,radar_pos,tgt_pos,radar_vel,tgt_vel);
txsig2 = cartarget2(txsig2);
txsig = cartarget(txsig);
% Dechirp the received radar return
txsig2 = receiver(txsig2);
txsig = receiver(txsig);
dechirpsig = dechirp(txsig,sig);
dechirpsig2 = dechirp(txsig2,sig);
figure(2)
subplot(211)
plot(real(dechirpsig))
subplot(212)
plot(real(dechirpsig))
% Visualize the spectrum
specanalyzer([dechirpsig dechirpsig2 ]);
pause(1)
end