# Application of lowpass Butterworth filter

I'm trying to design a Butterworth lowpass filter with a cutoff frequency of

So far what I did is

ButterworthLPF[data_, dt_, Fcutoff_, Forder_] :=
Block[{LPF, dLPF, z, forwards, backwards},

LPF = ButterworthFilterModel[{Forder, 2 \[Pi] Fcutoff}];
dLPF = ToDiscreteTimeModel[LPF, dt, z];

forwards =
RecurrenceFilter[dLPF,
backwards =
RecurrenceFilter[dLPF,
1000 ;;]];

(forwards + Reverse@backwards)/2
];


To test the filter, I applied it to a set of synthetic data:

f = 500000;
fl = f - 50000;
fh = f + 50000;
dt=10^-7;

data = Table[{t, Sin[2 Pi fl t] + Sin[2 Pi f t] + Sin[2 Pi fh t]}, {t, 0., 0.0025, 7.5 dt}];

ListLinePlot[data,
AspectRatio -> 1/4,
Mesh -> All, MeshStyle -> Directive[PointSize[Small], Red],
Frame -> True]


Periodogram[data[[All, 2]], SampleRate -> 1/(7.5 dt), Frame -> True,
GridLines -> {{fl, f, fh}, None},
FrameTicks -> {{All, All}, {{fl, f, fh}, All}},
GridLinesStyle -> Directive[Red, Dashed], AspectRatio -> 1/4]


dataf = ButterworthLPF[data[[All, 2]], 7.5 dt, f, 7];

Periodogram[dataf, SampleRate -> 1/(7.5 dt), Frame -> True,
GridLines -> {{fl, f, fh}, None},
FrameTicks -> {{All, All}, {{fl, f, fh}, All}},
GridLinesStyle -> Directive[Red, Dashed], AspectRatio -> 1/4]


It looks that the value of sampling period in ToDiscreteTimeModel has a profound effect on the result. I thought as long as "sampling period< 2/fmax" it should be fine.

In general, I want to know what is wrong with my code that I cannot remove certain frequencies with my simple lowpass filter?