function [quietwin, IARwins, lwinsvec, midwinpoints] = IAR_quiet_wins(Brmsquietloc,IARwin,maxpoints,npt)
% Calculate quiet and IAR windows
global overlap fs

lwinsvec = 1:IARwin(3)*3600*fs:maxpoints;
IARwins = lwinsvec((1/IARwin(3)*IARwin(1)+1):(1/IARwin(3)*IARwin(2)+1));

if Brmsquietloc*(npt-overlap) > (IARwin(3)*3600*fs)/2 + 1 && Brmsquietloc*(npt-overlap) < maxpoints - (IARwin(3)*3600*fs)/2 - 1 
    quietwin = [Brmsquietloc*(npt-overlap)-(IARwin(3)*3600*fs)/2 Brmsquietloc*(npt-overlap)+(IARwin(3)*3600*fs)/2 - 1];
elseif Brmsquietloc*(npt-overlap) < (IARwin(3)*3600*fs) + 1
    quietwin = [Brmsquietloc*(npt-overlap) Brmsquietloc*(npt-overlap) + IARwin(3)*3600*fs - 1];
elseif Brmsquietloc*(npt-overlap) > maxpoints - (IARwin(3)*3600*fs) - 1
    quietwin = [Brmsquietloc*(npt-overlap) - IARwin(3)*3600*fs + 1 Brmsquietloc*(npt-overlap)];
end

midwinpoints = lwinsvec(1:end-1) + IARwin(3)*3600*fs/2; 
end