title: Apply Butterworth filters in time series data
body: <p>I have time series data which are measured in miliseconds (ms) (69300 rows) and I want to apply low-pass, high-pass and band-pass Butterworth filters.</p>
  
  <p>My approach is the following:</p>
  
  <ul>
  <li>Convert ms into Hz 
  
  <ul>
  <li>Find the Nyquist which is sample rate/2 (as sample rate I take the converted Hz value)</li>
  <li>Calculate the sinusoid+noise</li>
  <li>Calculate the cutoff frequencies for low-pass and high-pass filters (by taking the 0.1 of the total Hz and divide with the Nyquist value for the low-pass, and taking the 0.25 of the total Hz)</li>
  <li>For the band-pass filter I calculate the difference of the cut-off frequencies</li>
  <li>Apply the -nth order of the filters </li>
  <li>Passing the filters with the sinusoid+noise.</li>
  </ul></li>
  </ul>
  
  <p>Below is a code snippet I made using R:</p>
  
  <pre><code># 69300 ms are 0.014430014430014Hz
  x &lt;- 1:69300
  
  nyquist &lt;- 0.014430014430014/2 # sampling rate/2
  
  x1 &lt;- sin(2*pi*RF*0.014430014430014) + 0.25*rnorm(length(RF)) 
  # 0.014430014430014 Hz sinusoid+noise, RF is the time series metric
  
  f_low &lt;- 0.001443001/nyquist # 0.1 of total Hz divided by Nyquist
  f_high &lt;- 0.003607504/nyquist # 0.25 of total Hz divided by Nyquist
  
  bf_low &lt;- butter(4, f_low, type="low")
  bf_high &lt;- butter(4, f_high, type = "high")
  bf_pass &lt;- butter(4, 0.3000001, type = "pass") # f_high - f_low
  
  b &lt;- filter(bf_low, x1)
  b1 &lt;- filter(bf_high,x1) 
  b2 &lt;- filter(bf_pass,x1)
  </code></pre>
  
  <p>Is this the correct approach? Should instead of sinusoid+noise to apply the filter to the metric itself?</p>