%%%%%%%%%%%%%%%%%%%%%%%%窄带加窗处理%%%%%%%%%%%%%%%%%%%%%%%%
%% 清除
clc;clear;close all;
%% 基本参数
f0=10e9;%载频
B=10e6;%信号带宽
tp=10e-6;%脉冲宽度
fs=100e6;%采样频率
k=B/tp;%LFM系数,线性调频率
R0=3000;%初始距离
c=3e8;%光速
R=6000;% 最大距离
tau=2*R0/c;% 时延
N=round(2*R/c*fs);% 点数
fft_N=2^nextpow2(N);% 点数
t=(0:fft_N-1)/fs;% 时间
%% 信号
s=rectpuls(t-tp/2,tp).*exp(1j*pi*k*(t-tp/2).^2);%%参考信号
spectrum_s=fft(s,fft_N);%参考信号频谱
spectrum_s=fftshift(spectrum_s);
sb=rectpuls(t-tp/2-tau,tp).*exp(1j*pi*k*(t-tp/2-tau).^2).*exp(-2j*pi*f0*tau);%%回波信号
%%时域加窗
sm=hamming(round(tp*fs))'.*s(1:round(tp*fs));%参考信号加窗
%%频域加窗
%找频谱的-4dB压缩点,窗函数严格与该压缩点之间的频谱对应
hamming1=[zeros(1855,1)',hamming(387)',zeros(1854,1)'];
spectrum_sm=hamming1.*spectrum_s;
%%脉压
fft_ssb=ifft(fft(sb).*conj(fft(s)));
fft_smsb=ifft(fft(sb).*conj(fft(sm,length(sb))));
fft_spsb=ifft(fft(sb).*conj(fftshift(spectrum_sm)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%去斜加窗处理%%%%%%%%%%%%%%%%%%%%%%%%%%%%
B=10e6;%带宽10MHz
tp=10e-6;%脉宽10us
u=B/tp;%LFM系数
fs=50e6;%fs>=2*B/tp*tauR0=3000;
R=4500;%初始距离距离波门
c=3e8;f0=60e6;%载频
N=round(2*R/c*fs);fft_N=2^nextpow2(N);t=linspace(0,2*R/c,N);
f=fs*(0:fft_N-1)/fft_N-fs/2;%从-fs/2到fs/2
%%%%%%%%%%%%%%%%%%%%%%%%%%参考信号%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sref=exp(1i*pi*u*t.^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%回波信号%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sb=rectpuls(t-2*R0/c,tp).*exp(1j*pi*u*(t-2*R0/c).^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%混频信号%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ssb=Sref.*conj(Sb);
%%加窗
%w=hamming(502)';
%hamming=[zeros(749,1)',w-min(w),zeros(249,1)'];
%hamming=abs(hamming)/max(hamming);
hamming=[zeros(749,1)',hamming(502)',zeros(249,1)'];
ssb0=hamming.*ssb;
spectrum_ssb0=fft(ssb0,fft_N);%一维距离像
spectrum_ssb=fft(ssb,fft_N);
f=f*c*tp/2/B;%瞬时频率对应的距离
figure;%%图6
plot(f,db(abs(fftshift(spectrum_ssb))/max(fftshift(spectrum_ssb))))
hold on
plot(f,db(abs(fftshift(spectrum_ssb0))/max(fftshift(spectrum_ssb0))),'r')
legend('未加窗',...
'加窗',...
'Times New Roman','FontSize',9,'location','southeast');
grid on;% 打开网格线
set(gca,'gridlinestyle','--','GridColor','k','Gridalpha',0.2,'LineWidth',1); % 设置网格线的类型,颜色,透明度以及线宽
hold off