clear all;

%plot Halfway Bus
titleStr = 'Halfway Bush Wideband 7-8 Sep 2017';
filename1 = 'HalfwayBush-UWB20170907.mat';
filename2 = 'HalfwayBush-UWB20170908.mat';

%or plot Swampy data
% titleStr = 'Swampy Wideband 7-8 Sep 2017';
% filename1 = 'SwampySummit-UWBNS20170907.mat';
% filename2 = 'SwampySummit-UWBNS20170908.mat';

%load data files and select time intervals to plot

%load data from 2017-09-07

load(filename1);
%UTC timestamps
posixTimeStamps=V(:,2);
%plot data between these UT hours
tStart = posixTimeStamps(1)+ 22*3600;
tEnd = posixTimeStamps(1)+ 24*3600;
tSelection = posixTimeStamps >= tStart & posixTimeStamps < tEnd;
V1=V(tSelection,:);
clear V;

%load data from 2017-09-08

load(filename2);
%UTC timestamps
posixTimeStamps=V(:,2);
%plot data between these UT hours
tStart = posixTimeStamps(1)+ 0*3600;
tEnd = posixTimeStamps(1)+ 3.5*3600;
tSelection = posixTimeStamps >= tStart & posixTimeStamps <= tEnd;
V2=V(tSelection,:);
clear V;

%combine into one matrix of data to plot
V=[V1;V2];

Fs=mean(V(:,3)) * 0.001;  %sampling frequency in kHz.
posixTimeStamps=V(:,2); %UTC timestamps


fstep = 1; %kHz
Fupper = 5; %kHz

count=mean(V(:,4));
N=1024; % fixed in recording software
dcBinIdx=5; 
FUpperIdx = ceil(Fupper*N/Fs);
f=Fs*(0:FUpperIdx)/N;

%select frequency bins data to display
V=V(:,dcBinIdx:dcBinIdx+FUpperIdx)';
t1 = datenum(datetime(posixTimeStamps,'ConvertFrom','posixtime'));

clf
figure(1)
imagesc(t1,f,V)
set(gca,'YDir','normal')
datetick('x','HHMM')
set(gca,'ytick',[0:fstep:max(f)])

tix=get(gca,'ytick')';
set(gca,'yticklabel',num2str(tix,'%.0f'))

axis tight

colormap('jet')
title(titleStr)
ylabel('Frequency [kHz]')
xlabel('Time [UT]')
hcb = colorbar;
caxis([-90 -10])
hcb.Label.String = 'Magnetic Field [dBFs]';


