%% clear workspace
clear all;
close all;
clc;

%% load data
data = load('Scenarios_Load.mat');
hungaroring = data.Hungaroring;
current = timeseries2timetable(hungaroring{1});
voltage = timeseries2timetable(hungaroring{2});

%% remove duplicate data (every second number trashed)
current = current(1:2:end, :);
voltage = voltage(1:2:end, :);

current_cut = current.Current(500:3999);
time_cut = (0:0.2:699.8)';

current_steady = current.Current(4110:4169);
time_steady = 0:0.2:11.8;

% figure(10);
% plot(time_steady, current_steady);

%% fft
Y = fft(current.Current);
L = length(current.Current);
Fs = 5;

P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);

% figure(3);
% f = Fs*(0:(L/2))/L;
% plot(f, P1)

%% plot data
figure(1);
plot(current.Time, current.Current);
grid on;
title('Batery current during Hungarorings endurance');
xlabel('time [s]');
ylabel('Battery current [A]');

figure(2);
plot(voltage.Time, voltage.Voltage);
grid on;
title('Batery voltage during Hungarorings endurance');
xlabel('time [s]');
ylabel('Battery voltage [V]');

% figure(5);
% plot(time_cut, current_cut);

%% generate signal
% t = 0:0.2:1660;
% curr = (37/2*sin(2*pi*0.115*t) - 37/2) + (38/2*sin(2*pi*0.16*t) - 38/2)  - 0.5;
% 
% figure(4);
% plot(t, curr);
% grid on;