clc
clear all;
close all;
T=10e-6; %脉冲时宽 10微秒
B=40e6; % 带宽40MHz
K=B/T; %线性调频信号的常数K
Fs=2*B; %采样频率
Ts=1/Fs; %采样时间间隔
N=T/Ts; %采样点数
t=linspace(-T/2,T/2,N); %对应的采样点数的时间t
St=rectpuls(t,T).*exp(j*pi*K*t.^2);
% % subplot(211);
% % plot(t*1e6,St);
% % xlabel('t/s');
% % title('线性调频信号');
% % grid on;
% % axis tight;
% subplot(212);
figure(1);
freq=linspace(-Fs/2,Fs/2,N);
plot(freq*1e-6,fftshift(abs(fft(St))));
xlabel('f/MHz');
title('线性调频信号的幅频特性');
grid on;
axis tight;
Rmin=8000;Rmax=11000;
R=[10000,10150];
Rcs=[1 1];
C=3e8;
K=B/T;
Rwid=Rmax-Rmin;
Twid=2*Rwid/C;
Fs=5*B;Ts=1/Fs;
Nwid=ceil(Twid/Ts);
t=linspace(2*Rmin/C,2*Rmax/C,Nwid);
M=length(R);
td=ones(M,1)*t-2*R'/C*ones(1,Nwid);
Srt1=Rcs*(exp(1i*pi*K*td.^2).*(abs(td)<T/2));
Srt=Srt1;
Nchirp=ceil(T/Ts);
Nfft=2^nextpow2(Nwid+Nwid-1);
Srw=fft(Srt,Nfft);
Srw1=fft(Srt1,Nfft);
t0=linspace(-T/2,T/2,Nchirp);
St=exp(1i*pi*K*t0.^2);
Sw=fft(St,Nfft);
Sot=fftshift(ifft(Srw.*conj(Sw)));
Sot1=fftshift(ifft(Srw1.*conj(Sw)));
N0=Nfft/2-Nchirp/2;
Z=abs(Sot(N0:N0+Nwid-1));
% figure
% subplot(211)
% plot(t*1e6,real(Srt));
% axis tight;
% xlabel('us');ylabel('幅度')
% title(['线性调频信号压缩前']);
% subplot(212)
figure(2);
plot(t*C/2,Z)
xlabel('Range in meters');ylabel('幅度 ')
grid on;
title(['线性调频信号压缩后']);