function SleepState_aligned = Sleep_Align(foldername,fieldname)

    % Load animal state
    sleepfile = dir(sprintf('%s*SleepState*.mat',strcat(foldername,'/',fieldname)));
    load(strcat(foldername,'/',sleepfile.name))
    % Read OPTOTTL time in sec
    popfile = dir(sprintf('%s*popRate*.mat',strcat(foldername,'/',fieldname)));
    load(strcat(foldername,'/',popfile.name))
    wbnd = ceil(lfp_fbtime(1)/2e4) : floor(lfp_fbtime(2)/2e4);

    SleepState_aligned.idx.states = SleepState.idx.states(wbnd);
    SleepState_aligned.idx.statenames = SleepState.idx.statenames;

    SleepState_aligned.WAKE = find(SleepState_aligned.idx.states==1);
    SleepState_aligned.NREM = find(SleepState_aligned.idx.states==3);
    SleepState_aligned.REM= find(SleepState_aligned.idx.states==5);
end