%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UWB Car Occupancy Detection Dataset Example Plots
% Author: Jakob Möderl
% Date: 03.11.2023
% Description:
%   This short script loads the dataset and plots randomly drawn examples
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;
% close all;
clc;


% fix random seed
rng(2);

% Color ranges for plots (in dB)
color_lims = [[25, 55]; [25, 55]; [25, 55]; [-5, 25]];



class_names_active = {'breathing', 'talking', 'moving', 'empty'};
% filename prefix
dataset_filename = 'UWBCarGraz_6.5GHz-0.5GHz';


% iterate over all subclasses (breathing, talking, moving, empty)
for idx_class=1:numel(class_names_active)
    % load data
    datafile_name = sprintf("%s_%s.mat", dataset_filename, class_names_active{idx_class});
    fprintf("loading data %s\n", datafile_name);
    load(datafile_name);
    
    % total number of CIRs in this datafile
    numSamples = size(cir, 3);
    % show two examples of each subclass, except for empty
    if idx_class<=3
        random_indices = randi(numSamples, 2,1);
    else
        random_indices = randi(numSamples, 1,1);
    end
    % iterate over randomly drawn sample indices
    for ii=1:numel(random_indices)
        idx_sample = random_indices(ii);
        
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % get cir_tilde and transform data to dB scale
        cir_plot = squeeze(getCIRTilde(cir(:, :, idx_sample)));
        cir_plot = 20*log10(abs(cir_plot));
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        % Plot data
        fig_data = figure();
        imagesc(t(idx_sample), tau*1e9, cir_plot, color_lims(idx_class, :));
%         imagesc(t(idx_sample), tau*1e9, cir_plot, [max(cir_plot, [], 'all')-30, max(cir_plot, [], 'all')]);
        colormap(flipud(virdis_white));
        title(class_names_active{idx_class})
        xlabel('t in s');
        ylabel('$\tau$ in ns');
        cb = colorbar;
        ylabel(cb, ['$$|\tilde{\textbf{R}}|$$ in dB'], 'Interpreter', 'LaTeX');
    end
end