% =========================================================================
% model of LFM pulse radar
% =========================================================================
clear all;
close all;
T=10e-6; % pulse duration 10us
B=30e6; % pulse bandwidth 30MHz
Rmin=10000;
Rmax=15000; % range of interest
Rwid=Rmax-Rmin;
R=[11000, 14000]; % positions of ideal point targets
C=3e8; % propagation speed
K=B/T; % chirp slope
Twid=2*Rwid/C; % receive window in second
Fs=8*B;
Ts=1/Fs; % 8X sampling frequency
SNR=15; % in dB scale
Nwid=ceil(Twid/Ts); % receive window in sample
% Gnerate the echos
t=linspace(2*Rmin/C,2*Rmax/C,Nwid); % observe window
% start at t=2*Rmin/C
% end at t=2*Rmax/C
M=length(R); % number of targets
td=ones(M,1)*t-2*R'/C*ones(1,Nwid);
Srt=[1 1]*(exp(j*pi*K*td.^2).*(abs(td)<T/2)); % radar echos
% without noise
Nchirp=ceil(T/Ts); % samples in one pulse
Nfft=2^nextpow2(Nwid+Nchirp-1);
Srw=fft(Srt,Nfft);
t0=linspace(-T/2,T/2,Nchirp);
St=exp(j*pi*K*t0.^2);
Sw=fft(St,Nfft);
Sot=fftshift(ifft(Srw.*conj(Sw))); % matched filtering
N0=Nfft/2-Nchirp/2;
Z=abs(Sot(N0:N0+Nwid-1));
Z=Z/max(Z);
Z=20*log10(Z+1e-6);
figure(1);
subplot(211);
plot(t*1e6,real(Srt));
axis tight;
xlabel('Time (us)');
ylabel('Amplitude');
title('Echos without Pulse Compression');
subplot(212);
plot(t*C/2,Z);
axis([10000,15000,-60,0]);
xlabel('Range in meters');
ylabel('Amplitude (dB)');
title('Echos with Pulse Compression');
wid=hamming(Nchirp); % windowing
wSt=wid'.*St;
wSw=fft(wSt,Nfft);
wSot=fftshift(ifft(Srw.*conj(wSw))); % matched filtering
N0=Nfft/2-Nchirp/2;
wZ=abs(wSot(N0:N0+Nwid-1));
wZ=wZ/max(wZ);
wZ=20*log10(wZ+1e-6);
figure(2);
subplot(211);
plot(t*1e6,real(Srt));
axis tight;
xlabel('Time (us)');
ylabel('Amplitude');
title('Echos without Pulse Compression');
subplot(212);
plot(t*C/2,wZ);
axis([10000,15000,-60,0]);
xlabel('Range in meters');
ylabel('Amplitude (dB)');
title('Echos with Pulse Compression');
% with noise
nSrt=Srt+sqrt(0.5*(1/(10^(SNR/10)))).*(randn(1,Nwid)+j*randn(1,Nwid));
nSrw=fft(nSrt,Nfft);
nSot=fftshift(ifft(nSrw.*conj(Sw))); % matched filtering
nZ=abs(nSot(N0:N0+Nwid-1));
nZ=nZ/max(nZ);
nZ=20*log10(nZ+1e-6);
figure(3);
subplot(211);
plot(t*1e6,real(nSrt));
axis tight;
xlabel('Time (us)');
ylabel('Amplitude');
title('Echos without Pulse Compression');
subplot(212);
plot(t*C/2,nZ);
axis([10000,15000,-60,0]);
xlabel('Range in meters');
ylabel('Amplitude (dB)');
title('Echos with Pulse Compression');
wnSot=fftshift(ifft(nSrw.*conj(wSw))); % matched filtering
wnZ=abs(wnSot(N0:N0+Nwid-1));
wnZ=wnZ/max(wnZ);
wnZ=20*log10(wnZ+1e-6);
figure(4);
subplot(211);
plot(t*1e6,real(nSrt));
axis tight;
xlabel('Time (us)');
ylabel('Amplitude');
title('Echos without Pulse Compression');
subplot(212);
plot(t*C/2,wnZ);
axis([10000,15000,-60,0]);
xlabel('Range in meters');
ylabel('Amplitude (dB)');
title('Echos with Pulse Compression');