%***基带信号先内插再上变频。使用低通滤波器构造多相滤波器组
%***先内插时会出现I-1个0,上变频时相乘结果仍为0,。此处将本振信号按上变频后数据个数采样,然后每隔I个取一个有效结果,测试输出是否达到要求
clc;
clear all;
close all;
j=sqrt(-1);
MHz=1e+6;
us=1e-6;
B=50*MHz; %带宽
T=10*us; %时宽
fs=1000*MHz; %中频采样频率
f0=100*MHz; %中频频率
ts=1/fs;
K=B/T;
%% *******************基带LFM信号************************%
fs1=100*MHz; %基带采样率
ts1=1/fs1;
tsam_a=ts1:ts1:T;
tsam2_a=tsam_a .^2;
lfm=exp(j*2*pi*(0-B/2)*tsam_a+j*pi*K*tsam2_a);
lfm_val=round((2^12)*lfm);
lfm_I=real(lfm_val);
lfm_Q=imag(lfm_val);
% lfm_val=lfm/max(abs(lfm));
%*****************时域波形******************************%
tt1=(1:length(lfm))*ts1/us;
figure;
subplot(1,2,1);
plot(tt1,real(lfm_val));
ylabel('Real Amplitude');
xlabel('Time(us)');title('时域波形(实部) ');
axis([0 max(tt1) -1.1 1.1]);grid on;
subplot(1,2,2);plot(tt1,imag(lfm_val));
ylabel('Imag Amplitude');
xlabel('Time(us)');
title('时域波形 (虚部)');
axis([0 max(tt1) -1.1 1.1]);
grid on;zoom xon;
%********************基带信号频谱******************************%
fout1=abs(fftshift(fft((lfm_val))));
fftout1=20*log10(fout1/max(fout1));
ff1=-fs1/2+fs1/length(fout1):fs1/length(fout1):fs1/2;
figure;
plot(ff1/MHz,fftout1,'k');
title('基带信号频谱') %,'FontName','楷体_GB2312', 'FontSize',18);
xlabel('频率(MHz)','FontName','楷体_GB2312', 'FontSize',14);
ylabel('归一化幅度(dB)','FontName','楷体_GB2312', 'FontSize',14);
axis([-max(ff1/MHz) max(ff1/MHz) -60 3]);
grid on;zoom xon;
%% *******************滤波**********************%
%%纹波系数为0.01dB order 99 fs=1000MHz fpass=25MHz fstop=66MHz
load('FIR.mat'); %%纹波系数为0.1dB order 168
h=FIR;
coeff=h;
coeff=round((2^16)*coeff);
wave_IQ0=floor((filter(coeff(1:10:length(coeff)),1,lfm_val)));%disp(wave_IQ0(1:10));
wave_IQ1=floor((filter(coeff(2:10:length(coeff)),1,lfm_val)));
wave_IQ2=floor((filter(coeff(3:10:length(coeff)),1,lfm_val)));
wave_IQ3=floor((filter(coeff(4:10:length(coeff)),1,lfm_val)));
wave_IQ4=floor((filter(coeff(5:10:length(coeff)),1,lfm_val)));
wave_IQ5=floor((filter(coeff(6:10:length(coeff)),1,lfm_val)));
wave_IQ6=floor((filter(coeff(7:10:length(coeff)),1,lfm_val)));
wave_IQ7=floor((filter(coeff(8:10:length(coeff)),1,lfm_val)));
wave_IQ8=floor((filter(coeff(9:10:length(coeff)),1,lfm_val)));
wave_IQ9=floor((filter(coeff(10:10:length(coeff)),1,lfm_val)));
% tt2=(1:length(wave_IQ))*ts1/us;
% figure(3);
% plot(tt2,real(wave_IQ));title('内插滤波后时域波形(实部) ');
%
% fout2=abs(fftshift(fft((wave_IQ))));
% fftout2=20*log10(fout2/max(fout2));
% ff2=-fs1/2+fs1/length(fout2):fs1/length(fout2):fs1/2;
%
% figure(4);
% plot(ff2/MHz,fftout2);title('内插滤波后频谱 ');
%% *******************数字正交调制**********************%
LEN=10*length(wave_IQ0);
tsam=(1:LEN)*ts;
LO=exp(j*2*pi*f0*tsam); %disp(LO(1:10));
LO=round((2^12)*LO);
LO_I=real(LO);
LO_Q=imag(LO);
% figure;plot(tsam,real(LO));axis([0 max(tsam) -1.1 1.1]);
% title('本振信号 ');
%
% fft_LO=abs(fftshift(fft(LO)));
% ffft_LO=20*log10(fft_LO/max(fft_LO));
% f=-fs/2+fs/LEN:fs/LEN:fs/2;
% figure;plot(f/MHz,ffft_LO);title('本振频谱 ');
LO0=LO(1:10:LEN);LO1=LO(2:10:LEN);LO2=LO(3:10:LEN);LO3=LO(4:10:LEN);LO4=LO(5:10:LEN);
LO5=LO(6:10:LEN);LO6=LO(7:10:LEN);LO7=LO(8:10:LEN);LO8=LO(9:10:LEN);LO9=LO(10:10:LEN);
wave0= real(wave_IQ0).*imag(LO0)+imag(wave_IQ0).*real(LO0);%disp(wave0(1));
wave1= real(wave_IQ1).*imag(LO1)+imag(wave_IQ1).*real(LO1);%disp(wave1(1));
wave2= real(wave_IQ2).*imag(LO2)+imag(wave_IQ2).*real(LO2);%disp(wave2(1));
wave3= real(wave_IQ3).*imag(LO3)+imag(wave_IQ3).*real(LO3);%disp(wave3(1));
wave4= real(wave_IQ4).*imag(LO4)+imag(wave_IQ4).*real(LO4);%disp(wave4(1));
wave5= real(wave_IQ5).*imag(LO5)+imag(wave_IQ5).*real(LO5);%disp(wave5(1));
wave6= real(wave_IQ6).*imag(LO6)+imag(wave_IQ6).*real(LO6);%disp(wave6(1));
wave7= real(wave_IQ7).*imag(LO7)+imag(wave_IQ7).*real(LO7);%disp(wave7(1));
wave8= real(wave_IQ8).*imag(LO8)+imag(wave_IQ8).*real(LO8);%disp(wave8(1));
wave9= real(wave_IQ9).*imag(LO9)+imag(wave_IQ9).*real(LO9);%disp(wave9(1));
wave10=imag(wave_IQ0).*real(LO0);
% wave=wave0+wave1+wave2+wave3+wave4+wave5+wave6+wave7+wave8+wave9;
% wave=wave/max(abs(wave));
%
% figure;
% tt=(1:length(wave))*ts1/us;
% plot(tt,wave0,'k');
% title('内插后中频信号波形');
% xlabel('时间(us)','FontName','楷体_GB2312', 'FontSize',14);
% ylabel('归一化幅度','FontName','楷体_GB2312', 'FontSize',14);
% axis([0 max(tt) -1.1 1.1]);
% grid on;zoom xon;
%
% fout=abs(fftshift(fft(wave0)));
% fftout=20*log10(fout/max(fout));
% ff=-fs1/2+fs1/length(fout):fs1/length(fout):fs1/2;
%
% figure;
% plot(ff/MHz,fftout,'k');
% title('内插后中频信号频谱');
% xlabel('频率(MHz)','FontName','楷体_GB2312', 'FontSize',14);
% ylabel('归一化幅度(dB)','FontName','楷体_GB2312', 'FontSize',14);
% axis([-max(ff/MHz) max(ff/MHz) -60 3]);
% grid on;zoom xon;
%% ******************插值******************************%
N=length(wave0);
y0=zeros(1,10*N);y1=zeros(1,10*N);y2=zeros(1,10*N);y3=zeros(1,10*N);y4=zeros(1,10*N);
y5=zeros(1,10*N);y6=zeros(1,10*N);y7=zeros(1,10*N);y8=zeros(1,10*N);y9=zeros(1,10*N);
y0(1:10:10*N)=wave0;y1(2:10:10*N)=wave1;y2(3:10:10*N)=wave2;y3(4:10:10*N)=wave3;y4(5:10:10*N)=wave4;
y5(6:10:10*N)=wave5;y6(7:10:10*N)=wave6;y7(8:10:10*N)=wave7;y8(9:10:10*N)=wave8;y9(10:10:10*N)=wave9;
% y0(1:10:10*N)=wave_IQ0;y1(2:10:10*N)=wave_IQ1;y2(3:10:10*N)=wave_IQ2;y3(4:10:10*N)=wave_IQ3;y4(5:10:10*N)=wave_IQ4;
% y5(6:10:10*N)=wave_IQ5;y6(7:10:10*N)=wave_IQ6;y7(8:10:10*N)=wave_IQ7;y8(9:10:10*N)=wave_IQ8;y9(10:10:10*N)=wave_IQ9;
% y0(1:10:10*N)=wave9;y1(2:10:10*N)=wave8;y2(3:10:10*N)=wave7;y3(4:10:10*N)=wave6;y4(5:10:10*N)=wave5;
% y5(6:10:10*N)=wave4;y6(7:10:10*N)=wave3;y7(8:10:10*N)=wave2;y8(9:10:10*N)=wave1;y9(10:10:10*N)=wave0;
% y0=y0/max(abs(y0)); y1=y1/max(abs(y1)); y2=y2/max(abs(y2)); y3=y3/max(abs(y3)); y4=y4/max(abs(y4));
% y5=y5/max(abs(y5)); y6=y6/max(abs(y6)); y7=y7/max(abs(y7)); y8=y8/max(abs(y8)); y9=y9/max(abs(y9));
y=y0+y1+y2+y3+y4+y5+y6+y7+y8+y9; %disp(y(1:10));
% y=y/max(abs(y));
tt3=(1:length(y))*ts/us;
figure;
plot(tt3,y);title('内插后中频信号波形 ');
xlabel('时间(us)','FontName','楷体_GB2312', 'FontSize',14);
ylabel('归一化幅度','FontName','楷体_GB2312', 'FontSize',14);
axis([0 max(tt3) -1.1 1.1]);
grid on;zoom xon;
fout3=abs(fftshift(fft((y))));
fftout3=20*log10(fout3/max(fout3));
ff3=-fs/2+fs/length(fout3):fs/length(fout3):fs/2;
figure;
plot(ff3/MHz,fftout3);title('内插后中频信号频谱 ');
xlabel('频率(MHz)','FontName','楷体_GB2312', 'FontSize',14);
ylabel('归一化幅度(dB)','FontName','楷体_GB2312', 'FontSize',14);
axis([0 max(ff3/MHz) -60 3]);
grid on;zoom xon;