\(\(SetDirectory["C:\Documents and Settings\My Documents\HP_Filter"];\)\)

y = N[
          Log[Transpose[Import["datafile.csv"]]]][[1]]

mdim = Dimensions[y][[1]];
w = 1600;
  Print[
        If[mdim < 
            6, "Are you sure there is a trend?", "H-P filtering the \
data..."]];
m1 = {w, -4 w, 6 w + 1, -4 w, 
          w};
m2 = PadRight[m1, mdim];
m = {m2};
Do[
        m = Append[m, m2 = RotateRight[m2]], {mdim - 
            5}];
mrow1 = {w + 1, -2 w, w};
mrow2 = {-2 w, 5 w + 1, -4 w, 
          w};
mrowlast = {w, -2 w, w + 1};
mrownextlast = {w, -4 w, 
          5 w + 1, -2 w};
mrow1 = PadRight[mrow1, mdim];
mrow2 = PadRight[mrow2, mdim];
mrownextlast = 
        PadLeft[mrownextlast, mdim];
mrowlast = PadLeft[mrowlast, mdim];
m = Append[m, mrownextlast];
m = Append[m, mrowlast];
m = Prepend[m, mrow2];
m = Prepend[m, mrow1];
trend = LinearSolve[m, y];
ListPlot[trend];
ListPlot[y];
ListPlot[
        y - trend];
  
Export["trend.csv", 
        Transpose[{trend}]];
Export["deviations.csv", Transpose[{y - trend}]];