
clear

path_name = 'C:\DATA\T04_Files\delete_me\RX1-951';

load(fullfile(path_name,'single_diff_cno'), 't', 's', 'tlims');

figure(31);
clf(31);
% box('on');
% grid('on');
hold('on');
plot(t,s,'b','LineWidth',2);
xlabel('Time [sec]','FontSize',12);
ylabel('Drop in C/N0 [dB]','FontSize',12);
xlim([0 max(t)]);
ylim([-28 5]);

f = NaN(1,size(tlims,1));
f_t = NaN(size(t));

random_seed = 221;
start_freq_Hz = 1535.0e6;
stop_freq_Hz = 1635.0e6;
% Create a uniform probability distribution object
pd = makedist('Uniform', ...
              'Lower',start_freq_Hz, ...
              'Upper',stop_freq_Hz);
% Initialize the random number generator
rng(random_seed);
for ii = 1:size(tlims,1)
    % Return a uniformly-distributed
    % random floating point number
    freq_Hz = random(pd);
    f(ii) = freq_Hz;
    idx = (t >= tlims(ii,1) & t <= tlims(ii,2));
    f_t(idx) = freq_Hz;
end

figure(32);
clf(32);
box('on');
grid('on');
hold('on');
plot(t,f_t/1e6,'bo');
xlabel('Time [sec]','FontSize',12);
ylabel('Jamming Freq [MHz]','FontSize',12);
xlim([0 max(t)]);
ylim([start_freq_Hz stop_freq_Hz]/1e6);

x = NaN(size(f));
for ii = 1:length(x)
    idx = (t >= tlims(ii,1) & t <= tlims(ii,2));
    x(ii) = mean(s(idx));
    % x(ii) = median(s(idx));
end

% [f,idx] = sort(f);
% x = x(idx);

[f,idx] = sort(f_t);
x = s(idx);

figure(33);
clf(33);
box('on');
grid('on');
hold('on');
plot(f/1e6,x,'bo');
xlabel('Jamming Freq [MHz]','FontSize',12);
xlim([start_freq_Hz stop_freq_Hz]/1e6);
