7
$\begingroup$

How do you make sense of the scale of "time" and "sampling" when using LowpassFilter and SampleRate ?

Given the test data with components at 1Hz and 5Hz

data1 = Array[N[Sin[2 Pi #] + Sin[2 Pi 5 #]] &, 100, {-1, 1}];

I expect to apply a low-pass filter at 2Hz and 10Hz

data2 = N @ LowpassFilter[data1, 2, SampleRate -> 50];

data3 = N @ LowpassFilter[data1, 10, SampleRate -> 50];

And see that data3 contains a significant part of the 5Hz component.

What am I doing wrong here?

In Win7 64 and Mathematica 10.2 and 10.1 I get

ListPlot[
  {
   data1
   , data2
   , data3
   }
  , Joined -> True
  , PlotRange -> {-2, 2}
  , PlotStyle -> {Gray, Red, Blue}
  ]

enter image description here

while versions 9.0 and 10.0 behave differently.

enter image description here

Should I understand that these new versions have a bug?

$\endgroup$
  • 1
    $\begingroup$ Results from v9 : !Mathematica graphics $\endgroup$ – Dr. belisarius Jul 30 '15 at 16:01
  • 1
    $\begingroup$ I get belisarius' result on 10.0.1, OSX. $\endgroup$ – N.J.Evans Jul 30 '15 at 16:02
  • $\begingroup$ @belisarius, get your result in 9.0, 10.0, and mine in 10.1 and 10.2. $\endgroup$ – rhermans Jul 30 '15 at 16:29
  • $\begingroup$ @rhermans Should we add a Version10 tag then? $\endgroup$ – Dr. belisarius Jul 30 '15 at 16:39
  • 2
    $\begingroup$ I get the same result as @rhermans in 10.2, but these results all seem correct to me. The issue (to me, it would seem) is that $\omega_c$ is an angular frequency, so $f_c=\omega_c/(2\pi)$. I think the difference people are getting between 10.0 and 10.1/10.2 arises from different filtering techniques. Try: data2 = N@LowpassFilter[data1, Quantity[2, "Hertz"], SampleRate -> 50]; data3 = N@ LowpassFilter[data1, Quantity[10, "Hertz"], SampleRate -> 50]; and that looks to give the correct result. $\endgroup$ – Michael Witt Jul 30 '15 at 16:42
7
$\begingroup$

It looks like your problem comes from the fact that $\omega_c$ will be referring to an angular frequency, so $$\omega_c=2\pi f_c$$ Therefore, you can get the desired result by changing your data2 and data3 definitions:

data2 = N@LowpassFilter[data1, 2*Pi*2, SampleRate -> 50];
data3 = N@LowpassFilter[data1, 2*Pi*10, SampleRate -> 50];

Alternatively, you can define it in terms of Hz:

data2 = N@LowpassFilter[data1, Quantity[2, "Hertz"], SampleRate -> 50];
data3 = N@LowpassFilter[data1, Quantity[10, "Hertz"], SampleRate -> 50];

And you get

Filter Response

Finally, the difference people seem to be getting in pre-10.1 and 10.1/10.2 seems to be different filter types. Specifying LowpassFilter will use whatever lowpass filter Wolfram has programmed in. It wouldn't surprise me to see them change the filter type, if it made sense to them, especially since there are other functions like ButterworthFilterModel that can be used for specifying the filter type explicitly.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.