function [cycles, numCycles] = getCyclesFromPressure(data, dataIndex)

clear cycleData
clear thisCycleData
pressure = data{dataIndex}.pressureDBar;

% derivFilter = designfilt('differentiator', FilterOrder=10, PassbandFrequency = 0.02, StopbandFrequency=0.025);
% pDeriv=filter(derivFilter, pressure);

cycleNum = 1;

lowPHold = true;
pIncreasing = false;
highPHold = false;
pDecreasing = false;

lowPThresh = 30;
pIncrThresh = 2050;
highPHoldThresh = 2000;
pDecrThresh = 30;

cycleIndex = 1;
cycleName = "lowPHold";

for i=1:length(pressure)
    if(lowPHold)
        if(pressure(i) > lowPThresh)
            cycleNum = cycleNum + 1;
            cycleIndex = 1;
            lowPHold = false;
            pIncreasing = true;
            cycleName = "pIncr";
        end
    elseif(pIncreasing)
        if(pressure(i) > pIncrThresh)
            cycleNum = cycleNum + 1;
            cycleIndex = 1;
            pIncreasing = false;
            highPHold = true;
            cycleName = "highPHold";
        end
    elseif(highPHold)
        if(pressure(i) < highPHoldThresh)
            cycleNum = cycleNum + 1;
            cycleIndex = 1;
            highPHold = false;
            pDecreasing = true;
            cycleName = "pDecr";
        end
    elseif(pDecreasing)
        if(pressure(i) < pDecrThresh)
            cycleNum = cycleNum + 1;
            cycleIndex = 1;
            pDecreasing = false;
            lowPHold = true;
            cycleName = "lowPHold";
        end
    end

    cycles(cycleNum).dt(cycleIndex) = data{dataIndex}.dtLV(i);
    cycles(cycleNum).pressureDBar(cycleIndex) = data{dataIndex}.pressureDBar(i);
    cycles(cycleNum).vrsVolts(cycleIndex) = data{dataIndex}.vrsVolts(i);
    cycles(cycleNum).vrsStdDev(cycleIndex) = data{dataIndex}.vrsStdDev(i);
    cycles(cycleNum).thermTemp(cycleIndex) = data{dataIndex}.thermTemp(i);
    cycles(cycleNum).vkVolts(cycleIndex) = data{dataIndex}.vkVolts(i);
    cycles(cycleNum).vkStdDev(cycleIndex) = data{dataIndex}.vkStdDev(i);
    cycles(cycleNum).ikAmps(cycleIndex) = data{dataIndex}.ikAmps(i);
    cycles(cycleNum).ibAmps(cycleIndex) = data{dataIndex}.ibAmps(i);
    cycles(cycleNum).cycleNum(cycleIndex) = cycleNum;
    cycles(cycleNum).cycleName(cycleIndex,:) = cycleName(:);
    cycles(cycleNum).dataIndex(cycleIndex) = i;

    % thisCycleData(cycleIndex) = dataTable{1}.vrsVolts(i);
    cycleIndex = cycleIndex + 1;
end

numCycles = length(cycles);

end
