3
$\begingroup$

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, 
      ArrayPad[data, {1000, 0}, Padding -> "Fixed"]][[1000 ;;]];
   backwards = 
    RecurrenceFilter[dLPF, 
      ArrayPad[Reverse@data, {1000, 0}, Padding -> "Fixed"]][[
     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]

enter image description here

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]

enter image description here

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]

enter image description here

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?

Appreciate your help.

$\endgroup$
  • $\begingroup$ I guess the order of my filter is too high. $\endgroup$ – Mahdi Razaz Oct 5 '15 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.