function [pltData] = sortdata(data,start,stop)
    date = dateshift(data.Time(1),'start','day');
    time_hms = data.Time-date;
    time_s = seconds(time_hms);
    time_s = time_s - time_s(1);    % set beginning of session to 0

    % x-Axis:
    pltData.Time = data.Time(start:stop);
    pltData.time_s = time_s(start:stop)-time_s(start);
    pltData.time_hms = time_hms(start:stop);

    % distance calculation
    speed_mps = movmean(data.ABX_Driver_ABX_Speed(start:stop),50); % TODO: test different speed filters for distance calculation
    pltData.distance(1) = 0;
    for i = 2:length(speed_mps)
        pltData.distance(i) = speed_mps(i)*(pltData.time_s(i)-pltData.time_s(i-1)) + pltData.distance(i-1);
    end
    pltData.xAxis = pltData.time_s;     % set time as default x-Axis for plotting

    %% Misc
    pltData.app_percent = data.ABX_Driver_ABX_APPS_percent(start:stop);
    pltData.speed_kph = 3.6*movmean(data.ABX_Driver_ABX_Speed(start:stop),50);  % same filter as for distance calculation ???
    pltData.steering_deg = data.ABX_Driver_ABX_Steering_Angle(start:stop);

    %% AMS:
    pltData.ams_soc = data.AMS_Status_SOC(start:stop);
    pltData.ams_tmax = data.AMS_Status_Max_cell_temp(start:stop);
    pltData.ams_utot = data.Shunt_Voltage1_Shunt_Voltage1(start:stop);
    pltData.ams_itot = data.Shunt_Current_Shunt_Current(start:stop);
    % calculations:
    pltData.ams_ptot = pltData.ams_utot.*pltData.ams_itot/1000;

    %% Brakes
    % brake pressure
    pltData.brakePFront_bar = data.ABX_Driver_ABX_BrakeP_F(start:stop);
    pltData.brakePRear_bar = data.ABX_Driver_ABX_BrakeP_R(start:stop);
    % brake disc temperatures
    pltData.brakeTFrontLeft_degC = data.ABX_BrakeT_ABX_BrakeT_FL(start:stop);
    pltData.brakeTFrontRight_degC = data.ABX_BrakeT_ABX_BrakeT_FR(start:stop);
    pltData.brakeTRearLeft_degC = data.ABX_BrakeT_ABX_BrakeT_RL(start:stop);
    pltData.brakeTRearRight_degC = data.ABX_BrakeT_ABX_BrakeT_RR(start:stop);
    % calculate brake bias [%]
    minBrakeP = 5;  % minimum brake pressure to avoid artifacts due to sensor noise near 0 bar
    brakePFront = pltData.brakePFront_bar;
    brakePFront(brakePFront < minBrakeP) = minBrakeP;
    brakePRear = pltData.brakePRear_bar;
    brakePRear(brakePRear < minBrakeP) = minBrakeP;
    pltData.brakeBias_perc = 100*brakePFront./brakePRear;  % check calculation!

    %% Cooling system

    %% Dampers
    % damper positions
    pltData.damper_FL_mm = data.ABX_Dampers_ABX_Damper_FL(start:stop); %Heave_F
    pltData.damper_FR_mm = data.ABX_Dampers_ABX_Damper_FR(start:stop); %Roll_F
    pltData.damper_RL_mm = data.ABX_Dampers_ABX_Damper_RL(start:stop); %Heave_R
    pltData.damper_RR_mm = data.ABX_Dampers_ABX_Damper_RR(start:stop); %Roll_R
    % calculate damper velocities
    pltData.velocity_FL_mmps(1) = 0;
    pltData.velocity_FR_mmps(1) = 0;
    pltData.velocity_RL_mmps(1) = 0;
    pltData.velocity_RR_mmps(1) = 0;
    for i = 2:length(pltData.time_s)
        timestep = pltData.time_s(i)-pltData.time_s(i-1);
        pltData.velocity_FL_mmps(i) = pltData.damper_FL_mm(i)-pltData.damper_FL_mm(i-1)/timestep;
        pltData.velocity_FR_mmps(i) = pltData.damper_FR_mm(i)-pltData.damper_FR_mm(i-1)/timestep;
        pltData.velocity_RL_mmps(i) = pltData.damper_RL_mm(i)-pltData.damper_RL_mm(i-1)/timestep;
        pltData.velocity_RR_mmps(i) = pltData.damper_RR_mm(i)-pltData.damper_RR_mm(i-1)/timestep;
    end
    % filter damper velocities ??? bessere Berechnung über mittelwert aus mehreren werten? Vorfilterung?
    pltData.velocity_FL_mmps = movmean(pltData.velocity_FL_mmps,100);
    pltData.velocity_FR_mmps = movmean(pltData.velocity_FR_mmps,100);
    pltData.velocity_RL_mmps = movmean(pltData.velocity_RL_mmps,100);
    pltData.velocity_RR_mmps = movmean(pltData.velocity_RR_mmps,100);

    %% IMU
    % Acceleration
    pltData.acc_long_g = movmean(data.XSens_Acceleration_XSens_accX(start:stop),100)/9.81;
    pltData.acc_lat_g = movmean(data.XSens_Acceleration_XSens_accY(start:stop),100)/9.81;
    % Rate of turn
    pltData.rot_roll_degps = movmean(data.XSens_RateOfTurn_XSens_gyrX(start:stop),100);
    pltData.rot_pitch_degps = movmean(data.XSens_RateOfTurn_XSens_gyrY(start:stop),100);
    pltData.rot_yaw_degps = movmean(data.XSens_RateOfTurn_XSens_gyrZ(start:stop),100);

    %% Inverters
    % inverter temperatures
    pltData.invL_temp = data.INV_L_TxPDO_1_T_Inv_L(start:stop);
    pltData.invR_temp = data.INV_R_TxPDO_1_T_Inv_R(start:stop);
    % motor temperatures
    pltData.motL_temp = data.INV_L_TxPDO_1_T_Mot_L(start:stop);
    pltData.motR_temp = data.INV_R_TxPDO_1_T_Mot_R(start:stop);
    % motor velocities
    pltData.motL_vel_rpm = 60*data.INV_L_TxPDO_4_Velocity_L(start:stop);
    pltData.motR_vel_rpm = 60*data.INV_R_TxPDO_4_Velocity_R(start:stop);
    % inverter torque demand
    pltData.invL_torqueDemand = data.INV_L_TxPDO_3_DemandedTorque_L(start:stop)/10; % /10 to match autobox torque
    pltData.invR_torqueDemand = data.INV_R_TxPDO_3_DemandedTorque_R(start:stop)/10;
    % inverter actual torque
    pltData.invL_torqueActual = data.INV_L_TxPDO_3_ActualTorque_L(start:stop)/10;
    pltData.invR_torqueActual = data.INV_R_TxPDO_3_ActualTorque_R(start:stop)/10;

    %% Wheelspeed


    

    %% Statistics:
    power_regen_kw = pltData.ams_ptot;
    power_regen_kw(power_regen_kw > 0) = 0;
    power_used_kw = pltData.ams_ptot;
    power_used_kw(power_used_kw < 0) = 0;
    pltData.energy_kwh = trapz(pltData.time_s, pltData.ams_ptot)/3600;
    pltData.energy_regen_kwh = trapz(pltData.time_s, power_regen_kw)/3600;
    pltData.energy_used_kwh = trapz(pltData.time_s, power_used_kw)/3600;
    pltData.distanceTotal_km = trapz(pltData.time_s, pltData.speed_kph./3.6)/1000; % 1/3.6 for km/h to m/s and /1000 for km output
    pltData.peakPower_kw = max(pltData.ams_ptot);
    pltData.peakPowerMean_kw = max(movmean(pltData.ams_ptot,500));

    pltData.maxSpeed_kph = max(pltData.speed_kph);
    pltData.startTime = time_hms(start);
    pltData.stopTime = time_hms(stop);
end

