📄 adapt_ieee.m
字号:
clear;
S21String = 'S21_bb_ch1.mat';
S21 = importdata(S21String);
% Set the carrier frequency to be the middle of band 2, 3960 MHz.
Fc=3960e6;
Ls=length(S21);
% Define the sampling time
Ts = 3.125e-7/990;
% frequency points
step= 5e6;
fs = 1e9:step:13e9;
% Netto frequency band [3.170 : 4.755] GHz
f_0=1e9; %simulation start frequency
f_l = 2.375e9+0.530e9; f_h = 5.545e9-0.530e9; % %Brutto frequency Band width lowest and highst f
f_bp= [f_l:step:f_h];
U_f= [((f_l -f_0)/step)+1:((f_h -f_0)/step)+1];
L_f=length(U_f);
H_bpBr = S21(U_f);
Wd = zeros(1,L_f);
W = tukeywin(L_f, 0.5);
H_bpNetto= W'.*H_bpBr ;
M = length(H_bpNetto); N= 4*M; % 4*M is the best resample rate nearly Ts
df = 5e6; R = df*N; dt = 1/R; T = N*dt;
f = df*(0:N-1); t = dt*(0:N-1);
tt = (0:dt:300e-9);
it = 1+round(mod(tt,T)/dt);
h_bp = ifft(H_bpNetto,N);
%--------------------------------------------
%--------------------------------------------
tt_co =tt(1: length(h_bp));
tt_sa = [0:500]*Ts;
h_sa =interp1(tt_co,h_bp,tt_sa, 'linear');
%--------------------------------------------
% Translate the data from passband to baseband.
%--------------------------------------------
h_tp = h_sa.*exp(j*2*pi*Fc*[1:size(tt_sa)]*Ts);
%--------------------------------------------
% Truncate the start of the response to remove any delay introduced in the
% reinterpolation process.
%--------------------------------------------
Len = 500; %IEEE channel length
h_tp_my =zeros(Len,1);
gd_start = find(abs(h_tp)==max(abs(h_tp)));
h_tp_shift = [h_tp(gd_start:end)'; zeros(gd_start-1,1)]; %remove any delay
% remove values smaller than 10^-5 of the maximum
gd_end = min(find(abs(h_tp_shift )<1e-4*max(abs(h_tp_shift))));
I=(1:gd_end);
h_tp_my (I) = real(h_tp_shift(I));
%-------------------------------------------
%The energy of the realization have to be normalized to unity
%-------------------------------------------
E= sum(abs(h_tp_my).^2); %the Energie of the time discret signal h_tp_my
h_tp_my =h_tp_my/sqrt(E);
%-------------------------------------------
%%% save continuous-time (time,value) pairs to files
%-------------------------------------------
SaveStr=sprintf('%s','h_bb_ch1');
% A complete self-contained file for Matlab users
save ([SaveStr '.mat'], 'h_tp_my') ;
%-------------------------------------------
%%% plots
%-------------------------------------------
figure(1) %S21(f) magnitude
xaxis=' f_{} [GHz]'; yaxis='|S_{21}| [dB]';
hold on;
owntitle=('20log_{10}(S_{21} (f))');
xmin=2.8; xmax = 5.2; xstep = 0.2; ymin= -110; ymax= -30; ystep = 10;
hold on;
plot(f_bp/1e9, 20*log10(abs(H_bpNetto)),'--b','LineWidth',2);
plot(f_bp/1e9,-40+20*log10(abs(W)),'--r', [Fc Fc]*1e-9,[ymin ymax], '-.k','LineWidth',2); hold off;
title(owntitle,'fontsize',12); xlabel(xaxis,'fontsize',12);
set(gca,'XTick',xmin:xstep:xmax); ylabel(yaxis,'fontsize',12); set(gca,'YTick',ymin:ystep:ymax);
xlim([xmin xmax]); ylim([ymin ymax]);
legend ('transfer function', 'used window (normalized)')
hold off; grid on
%-------------------------------------------
% %% time continius impulse response
%-------------------------------------------
figure(2)
xaxis=' t_{} [ns]'; yaxis='|h_{21}(t)| [dB]';
xmin=5; xmax=80; xstep=5; ymin=-130; ymax= -60; ystep =10;
hold on; plot(tt*1e9,20*log10(abs(h_bp(it))),'b-','LineWidth',1);...
plot(tt_sa*1e9,20*log10(abs(h_sa)),'r-','LineWidth',1); hold off;
xlabel(xaxis,'fontsize',12);set(gca,'XTick',xmin:xstep:xmax);
ylabel(yaxis,'fontsize',12); set(gca,'YTick',ymin:ystep:ymax);
xlim([xmin xmax]);ylim([ymin ymax]);
grid on;
shg
%-------------------------------------------
%-------------------------------------------
figure(3)
xaxis=' t_{} [ns]'; yaxis='|h_{tp}(t)| [dB]';
xmin=-5; xmax=60; xstep=5; ymin=-1; ymax= 1; ystep =0.1;
plot(tt_sa(1:500)*1e9, h_tp_my(1:500),[gd_end gd_end]*Ts/1e-9,[-0.5 0.5],'r--','LineWidth',1.5);
xlabel(xaxis,'fontsize',12);set(gca,'XTick',xmin:xstep:xmax);
ylabel(yaxis,'fontsize',12); set(gca,'YTick',ymin:ystep:ymax);
xlim([xmin xmax]);ylim([ymin ymax]);
grid on;
%--------------------------------------------
%--------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -