You are on page 1of 4

Doppler_Delay_Profile_v0d2_36bit_X_VINAG.

m 24/01/2018

% Script aimed @ creating a sinusoidal profile of delay/doppler to be


% used as test for the PSL modulator:
%
% 14-12-2016 Rev 1.1 - 36 bit - for VINAG TRX preliminary checks (see
cwdel_cwdop_testsin400_TNCO36.m 04/07/2016)
%
%%%
% 15-01-2018 Rev 0.0 X VINAG
% changes w.r.t. R1.1 [14-12-2016]:
% - Operative Frequency: 12x MHz instead of 120x
% - doppler / delay sign inverted (as in the TPZ released firmware, i.e.
% the opposite sign of Simulink PSL modulator. To be double checked in
final release (Spectra
% inversion ?)
%
% PARAMETERS:
% 24-01-2018 Rev 0.2
% Building for 8 channels
clc;
help('Doppler_Delay_Profile_v0d2_36bit_X_VINAG');
c=299792458;
F_NCO_Hz = 12276000;
F0_PSL_Hz = 1575420000;
lambda_PSL_ns = (1/F0_PSL_Hz) * 10^9;
T_NCO_ns = (1/F_NCO_Hz) * 10^9;
NCO_STEP = 512*256*4096; % Timing NCO STEP:
MAX_NCO_FREQ = 2^36;
Doppler_Sampling_Rate_Hz = 100;
Counter_Update_ms = 1;
Counter_up_Update_ms = 10;
Counter_active_samples = 12276;
Update_Rate_s = 0.01;
%%%%%
clear doppler_from_OP;
clear curr_ch;
curr_ch = input('Insert Channel number to configure [0..7] (default = 0):
');
if(isempty(curr_ch))
curr_ch = 0;
end

doppler_from_OP = input('Please insert the workspace variable of Orbital


Propagator Doppler profiles \nsampled at 100 Hz. Press Enter to skip and
build a sinusoidal profile: ','s');
if (isempty(doppler_from_OP))
Sim_length = input('Please insert Simulation Length in seconds
(default:20) : ');
if (isempty(Sim_length))
Sim_length = 20;
end

Sin_period = input('Please insert Sinusoidal Period in seconds


[<=Sim_length] (default = Sim_length) : ');
if (isempty(Sin_period))
Sin_period = Sim_length;
end

Sin_max_doppler = input('Please insert Max Doppler [Hz] (default =


1000) : ');
if (isempty(Sin_max_doppler))
Sin_max_doppler = 1000;
end

Sin_freq_offset = input('Please insert Initial Frequency Offset [Hz]


[-5000, 5000] (default = 0) : ');
if (isempty(Sin_freq_offset))
Sin_freq_offset = 0;

1
Doppler_Delay_Profile_v0d2_36bit_X_VINAG.m 24/01/2018

end

Sin_ph_offset = input('Please insert Initial Phase Offset [rad] [-pi,


pi] (default = 0) : ');
if (isempty(Sin_ph_offset))
Sin_ph_offset = 0;
end

Sin_samples_period = Sin_period/Update_Rate_s;

t1= 0:2*pi/Sin_samples_period:2*pi - 2*pi/Sin_samples_period;

y = Sin_freq_offset + Sin_max_doppler*sin(t1+Sin_ph_offset);

nperiods = floor(Sim_length/Sin_period);

ytot = y;
for t=2:nperiods
ytot = [ytot y];
end

Sim_length_samples = Sim_length/Update_Rate_s;

fract_samples = Sim_length_samples-length(ytot);

%fract_period = (Sim_length/Sin_period) - nperiods;


%fract_sample_period = floor(fract_period/Update_Rate_s);

ytot = [ytot y(1:fract_samples)];


else
doppler_Hz_Vect = evalin('base',doppler_from_OP);
doppler_Hz = doppler_Hz_Vect(curr_ch+1,:);
Doppler_Rate = diff(doppler_Hz);

% Nota: questo rate, analogamente al PR RATE, e' a rate del tempo di


campionamento

Doppler_Hz_av = doppler_Hz(1:end-1)+Doppler_Rate/2;
clear doppler_Hz;
ytot = Doppler_Hz_av;
Sim_length = length(ytot)*Update_Rate_s;

end

doppler_Hz = ytot;

l_res_NCO_F_REG_VAL_acc = 0;

NCO_FREQ_d = (doppler_Hz)/(F_NCO_Hz)*MAX_NCO_FREQ;
NCO_FREQ_REG_VALS = floor(NCO_FREQ_d + 0.5);

l_res_NCO_F_REG_VAL = NCO_FREQ_d - NCO_FREQ_REG_VALS;


l_res_NCO_F_REG_VAL_acc = l_res_NCO_F_REG_VAL + l_res_NCO_F_REG_VAL_acc;

if (l_res_NCO_F_REG_VAL_acc > 1)
NCO_FREQ_REG_VALS = NCO_FREQ_REG_VALS + 1;
l_res_NCO_F_REG_VAL_acc = l_res_NCO_F_REG_VAL_acc - 1;
end

if (l_res_NCO_F_REG_VAL_acc < -1)


NCO_FREQ_REG_VALS = NCO_FREQ_REG_VALS - 1;
l_res_NCO_F_REG_VAL_acc = l_res_NCO_F_REG_VAL_acc + 1;
end

%NCO_FREQ_REG_VALS = (dop_Hz)/(F_NCO_Hz)*MAX_NCO_FREQ;

2
Doppler_Delay_Profile_v0d2_36bit_X_VINAG.m 24/01/2018

%delta_del_ns = - doppler_Hz*(1/
Doppler_Sampling_Rate_Hz)*lambda_PSL_ns;
delta_del_ns = + doppler_Hz*(1/
Doppler_Sampling_Rate_Hz)*lambda_PSL_ns; %% inversion 15/01/2018
delta_del_ns_at_up_Update = delta_del_ns*(Doppler_Sampling_Rate_Hz/ (1/
Counter_up_Update_ms*1000));
delta_del_ns_2_NCO = delta_del_ns_at_up_Update/( (Counter_up_Update_ms/
Counter_Update_ms) * Counter_active_samples);
%%% Taking into account the residual part for the next word
l_res_NCO_T_REG_VAL = 0;
l_res_NCO_T_REG_VAL_acc = 0;

for tn=1:length(delta_del_ns_2_NCO)
l_NCO_T_REG_VAL_i = round((delta_del_ns_2_NCO(tn) * NCO_STEP/T_NCO_ns))
;
l_res_NCO_T_REG_VAL = (delta_del_ns_2_NCO(tn) * NCO_STEP/T_NCO_ns) -
l_NCO_T_REG_VAL_i;
l_res_NCO_T_REG_VAL_acc = l_res_NCO_T_REG_VAL +
l_res_NCO_T_REG_VAL_acc;
if (l_res_NCO_T_REG_VAL_acc > 1)
l_NCO_T_REG_VAL_i = l_NCO_T_REG_VAL_i + 1;
l_res_NCO_T_REG_VAL_acc = l_res_NCO_T_REG_VAL_acc - 1;
end
if (l_res_NCO_T_REG_VAL_acc < -1)
l_NCO_T_REG_VAL_i = l_NCO_T_REG_VAL_i - 1;
l_res_NCO_T_REG_VAL_acc = l_res_NCO_T_REG_VAL_acc + 1;
end
l_res_NCO_T_REG_VAL_t(tn) = l_NCO_T_REG_VAL_i;
end
% if no taking into account residuals...
%NCO_TIMING_REG_VALS = round(delta_del_ns_2_NCO * NCO_STEP/T_NCO_ns);
%CW_DELAY =NCO_TIMING_REG_VALS;
%Insert_Zeros = input('Please insert Initial Propagation Offset in ms (will
be rounded by 10 ms step) [default: 1000 ms = 1sec] : ');
%if (isempty(Insert_Zeros))
% Insert_Zeros = 1000;
%end
clear CW_DELAY CW_DOPPLER
CW_DELAY(1:0)=0;
CW_DOPPLER(1:0)=0;

CW_DELAY = [CW_DELAY l_res_NCO_T_REG_VAL_t];


CW_DOPPLER = [CW_DOPPLER NCO_FREQ_REG_VALS];
assignin('base',strcat('CW_DELAY_',num2str(curr_ch)),CW_DELAY);
assignin('base',strcat('CW_DOPPLER_',num2str(curr_ch)),CW_DOPPLER);

cwa=0;
for t2=2:length(delta_del_ns)
cwa(t2)=cwa(t2-1)+delta_del_ns(t2);
end
tp = 0:Update_Rate_s:Sim_length-Update_Rate_s; % to plot seconds on x axis
figure;
subplot(2,1,1)
h1=plot(tp,doppler_Hz,'r');
hold on
grid on
set(gca,'FontSize',18);
set(h1,'LineWidth',2);
title('Doppler Frequency Profile');
ylabel('Frequency [Hz]');
xlabel('Time [s]');
subplot(2,1,2);
%%h1=plot(tp, cwa*c*10^-9,'b');
h1=plot(tp, -cwa*c*10^-9,'b'); % inversion 15/01/2018
grid on
hold on
set(gca,'FontSize',18);
set(h1,'LineWidth',2);

3
Doppler_Delay_Profile_v0d2_36bit_X_VINAG.m 24/01/2018

title('Delay Profile ');


ylabel('Delta Delay [m]');
xlabel('Time [s]');
clear t1 tp ytot y Sim_length_samples fract_samples NCO_TIMING_REG_VALS
NCO_FREQ_REG_VALS nperiods tp
disp(' ');
disp(' ALL PARAMETERS SET FOR THE SIMULATION, please update simulation run
time accordingly ');
disp(' ');

savesimparams = 'n';%input(' Do you want to save simulation parameters and


the fig [y/n] (default:[y] ) ? ','s');

if (isempty(savesimparams))
savesimparams = 'y';
end
if ((savesimparams == 'y') || (savesimparams == 'Y'))
l_Save_Out_s = input('Insert Output mat variable name: ','s');
l_Save_Out_mat_s = strcat(l_Save_Out_s,'.mat');
assignin('base',strcat('CW_DELAY_',l_Save_Out_s),CW_DELAY);
assignin('base',strcat('CW_DOPPLER_',l_Save_Out_s),CW_DOPPLER);
assignin('base',strcat('Sim_length_',l_Save_Out_s),Sim_length);

assignin('base',strcat('Sin_freq_offset_',l_Save_Out_s),Sin_freq_offset
assignin('base',strcat('Sin_period_',l_Save_Out_s),Sin_period);

assignin('base',strcat('Sin_max_doppler_',l_Save_Out_s),Sin_max_doppler
l_save_vars = strcat('*',l_Save_Out_s);
save(l_Save_Out_mat_s,l_save_vars);
h6=gcf;
l_TEST = strcat('TEST-VINAG_MODULATOR_',l_Save_Out_s);
print(h6,'-djpeg', '-noui', l_TEST);
saveas(h6,l_TEST,'fig');
end
%
save(l_Save_Out_mat_s,'CN0_calc_all','DLL_DUT_all','PLL_DUT_all','PI_PLL_
all','PQ_PLL_all','PI_FLL_all','PQ_FLL_all','SState','CN0_calc_SS','DLL_D
UT_SS','PLL_DUT_SS','PI_PLL_SS','PQ_PLL_SS','PI_FLL_SS','PQ_FLL_SS','BW_P
LL','BW_DLL','SigmaPLL_TEO_Meas_Filt','SigmaDLL_TEO_Meas_Filt',...
%
'PLL_Filt_deg','DLL_Filt_meters','PR_BY_DOPPLER','PR_BY_DELAY');
clear l_*

%print(h6,'-djpeg', '-noui', PR_DEL_PR_DOP_FIG_s);


%saveas(h6,PR_DEL_PR_DOP_FIG_s,'fig');
ALL_SET = 1;

You might also like