clear all
close all

x=load('us.txt');
time = x(:,1);
gdp = x(:,2);
lgdp = log(gdp);

% estimation of trend/gap by Hodrick Prescott filter
[lgdp_trend, lgdp_gap] = hp(lgdp,1600); % alternative way

% estimation of gap by Bandpass filter (Christiano Fitzgerald)
pl = 6;  % minimum periods of oscillation, less than 6 = measurement errors
pu = 32; % maximum periods of oscillation, more than 32 = trend growth
         % between 6  and 32  = business cycle frequency

[lgdp_gap_bp] = bpass(lgdp,pl,pu);


figure
subplot(211)
plot(time,lgdp_gap*100)
title('Hodrick prescott filter')
grid
subplot(212)
plot(time,lgdp_gap_bp*100)
title('Band pass filter')
grid

figure
plot(time,[lgdp_gap lgdp_gap_bp]*100)
title('Comparison')
legend('HP filter','BP filter')
grid

