ss = 40;

lpfPressureSeconds = lpfPressureDate * 24.0 *3600.0;
pressureSeconds = pressureDate * 24.0 *3600.0;

for i=ss:length(lpfPressure)
sx = 0.0;
    sy = 0.0;
    for j=0:ss-1
        sx = sx + lpfPressureSeconds(i - j);
        sy = sy + lpfPressure(i - j);
    end
    
    sxoss = sx / ss;
    st2 = 0;
    b1 = 0;
    
    for j = 0:ss-1
        t = lpfPressureSeconds(i-j) - sxoss;
        st2 = st2 + t * t;
        b1 = b1 + t * lpfPressure(i-j);
    end
    lpfB(i-ss+1) = -b1 / st2;
end

for i=ss:length(pressure)
sx = 0.0;
    sy = 0.0;
    for j=0:ss-1
        sx = sx + pressureSeconds(i - j);
        sy = sy + pressure(i - j);
    end
    
    sxoss = sx / ss;
    st2 = 0;
    b1 = 0;
    
    for j = 0:ss-1
        t = pressureSeconds(i-j) - sxoss;
        st2 = st2 + t * t;
        b1 = b1 + t * pressure(i-j);
    end
    rawB(i-ss+1) = -b1 / st2;
end
plotyy(lpfPressureDate(ss:end),rawB,lpfPressureDate(ss:end),lpfB)
legend('Raw B', 'LPF B');
