<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div markdown-here-wrapper-content-modified="true" style=""
data-md-original="Hi%2C%20I%20wanted%20to%20use%20Fieldtrip%20to%20recreate%20the%20methodology%20used%20in%20a%20paper%20by%20%5BLeopold%20et%20al.%2C%202003%5D%5B1%5D%20--%20the%20relevant%20methods%20section%20is%20the%20following%3A%3Cbr%3E%3Cbr%3E_%22The%20LFP%20signals%20were%20resampled%20to%201%20kHz%2C%20and%20then%20band-pass%20filtered%20into%20seven%20frequency%20ranges%20using%20a%20second%20order%2C%20bi-direc-%20tional%2C%20zero-phase%20Chebyshev%20type-1%20filter.%20The%20frequency%20ranges%2C%20as%20well%20as%20their%20rough%20mapping%20onto%20classically%20defined%20electroencephalographic%20conventions%2C%20were%20the%20following%3A%20%CE%B4%20(1%E2%80%934%20Hz)%2C%20%CE%B8%20(5%E2%80%938%20Hz)%2C%20%CE%B1%20(9%E2%80%9314%20Hz)%2C%20%CE%B2%20(15%E2%80%9330%20Hz)%2C%20%CE%B3L%20(30%E2%80%9350%20Hz)%2C%20%CE%B3H%20(50%E2%80%93100%20Hz)%2C%20and%20%CE%B3VH%20(100%E2%80%93150%20Hz).%20The%20resulting%20band-limited%20signals%20were%20full-wave%20rectified%20by%20taking%
20their%20absolute%20value.%20They%20were%20then%20resampled%20to%2020%20Hz%20after%20low-pass%20filtering%20with%20an%20eighth%20order%20Chebyshev%20type-1%20filter%20(cutoff%20%3D%208%20Hz).%22_%3Cbr%3E%3Cbr%3EMy%20LFP%20data%20is%20sampled%20at%201kHz%2C%20and%20I%20manually%20pad%20with%20data%20either%20side%20of%20the%20event%20triggered%20region%20of%20interest.%20Fieldtrip%20doesn't%20have%20a%20%60chebyshev%20type-1%60%20filter%2C%20but%20would%20a%20second%20order%20two-pass%20butterworth%20be%20good%20enough%20considering%20the%20frequency%20bands%20used%3F%20I'm%20using%20the%20following%20cfg%20passed%20to%20%60ft_preprocessing%60%20for%20the%20initial%20bandpass%20filtering%20and%20rectification%3A%3Cbr%3E%3Cbr%3E%60%60%60matlab%3Cbr%3Efreq%20%3D%20%7B%5B1%204%5D%2C%20%5B5%208%5D%2C%20%5B9%2014%5D%2C%20%5B15%2030%5D%2C%20%5B30%2050%5D%2C%20%5B50%20100%5D%2C%20%5B100%20150%5D%7D%3B%3Cbr%3Efor%20j%20%3D%201%3Alength(freq)%3Cbr%3E%C2%A0cfg%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A
0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20%5B%5D%3B%3Cbr%3E%C2%A0cfg.padding%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%200%3B%3Cbr%3E%C2%A0cfg.bpfilter%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20'yes'%3B%3Cbr%3E%C2%A0cfg.bpfilttype%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20'but'%3B%3Cbr%3E%C2%A0cfg.bpfreq%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20freq%7Bj%7D%3B%3Cbr%3E%C2%A0cfg.bpfiltdir%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20'twopass'%3B%3Cbr%3E%C2%A0cfg.bpfiltord%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%202%3B%3Cbr%3E%C2%A0cfg.bpinstabilityfix%C2%A0%C2%A0%C2%A0%20%3D%20'reduce'%3B%3Cbr%3E%C2%A0cfg.rectify%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%
A0%C2%A0%C2%A0%20%3D%20'yes'%3B%3Cbr%3E%C2%A0bp%7Bj%7D%20%3D%20ft_preprocessing(cfg%2Cft)%3B%3Cbr%3Eend%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3EAs%20far%20as%20I%20can%20see%20in%20%60ft_preprocessing%60%20rectification%20occurs%20after%20filtering%2C%20so%20this%20is%20as%20specified%20by%20Leopold%20_et%20al.%2C_%3Cbr%3E%3Cbr%3EThen%20for%20downsampling%2Fresampling%3A%3Cbr%3E%3Cbr%3E%60%60%60matlab%3Cbr%3Ecfg%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20%5B%5D%3B%3Cbr%3Ecfg.padding%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%200%3B%3Cbr%3Ecfg.lpfilter%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20'yes'%3B%3Cbr%3Ecfg.lpfreq%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%208%3B%3Cbr%3Ecfg.lpfilttype%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%2
0%3D%20'but'%3B%3Cbr%3Ecfg.lpfiltdir%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20'twopass'%3B%3Cbr%3Ecfg.lpfiltord%C2%A0%C2%A0%C2%A0%20%C2%A0%C2%A0%C2%A0%20%C2%A0%C2%A0%C2%A0%20%3D%208%3B%3Cbr%3Ecfg.lpinstabilityfix%C2%A0%C2%A0%C2%A0%20%3D%20'reduce'%3B%3Cbr%3Ebp%7Bj%7D%20%3D%20ft_preprocessing(cfg%2Cbp%7Bj%7D)%3B%3Cbr%3Ecfg%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20%5B%5D%3B%3Cbr%3Ecfg.resample%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20'yes'%3B%3Cbr%3Ecfg.resamplefs%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%2020%3B%3Cbr%3Ecfg.detrend%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%20%3D%20'no'%3B%3Cbr%3Ebp%7Bj%7D%20%3D%20ft_resampledata(cfg%2Cbp%7Bj%7D)%3B%3Cbr%3E%60%60%60%3Cbr%3E%3Cbr%3EDoes%20this%20seem%20a%20correct%20translation%20of%20this%20me
thod%20in%20Fieldtrip%3F%20Are%20there%20any%20caveats%20other%20than%20the%20filter%20differences%3F%3Cbr%3E%3Cbr%3EThanks%2C%20Ian%3Cbr%3E%3Cbr%3E%5B1%5D%3A%20http%3A%2F%2Fdx.doi.org%2F10.1093%2Fcercor%2F13.4.422%20%3Cbr%3E"
      class="markdown-here-wrapper" data-md-url="Thunderbird"
      id="markdown-here-wrapper-473407">
      <p style="margin: 1.2em 0px ! important;">Hi, I wanted to use
        Fieldtrip to recreate the methodology used in a paper by <a
          href="http://dx.doi.org/10.1093/cercor/13.4.422">Leopold et
          al., 2003</a> — the relevant methods section is the following:</p>
      <p style="margin: 1.2em 0px ! important;"><em>“The LFP signals
          were resampled to 1 kHz, and then band-pass filtered into
          seven frequency ranges using a second order, bi-directional,
          zero-phase Chebyshev type-1 filter. The frequency ranges, as
          well as their rough mapping onto classically defined
          electroencephalographic conventions, were the following: δ
          (1–4 Hz), θ (5–8 Hz), α (9–14 Hz), β (15–30 Hz), γL (30–50
          Hz), γH (50–100 Hz), and γVH (100–150 Hz). The resulting
          band-limited signals were full-wave rectified by taking their
          absolute value. They were then resampled to 20 Hz after
          low-pass filtering with an eighth order Chebyshev type-1
          filter (cutoff = 8 Hz).”</em></p>
      <p style="margin: 1.2em 0px ! important;">My LFP data is sampled
        at 1kHz, and I manually pad with data either side of the event
        triggered region of interest. Fieldtrip doesn’t have a <code
          style="font-size: 0.85em; font-family:
          Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em;
          padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid
          rgb(234, 234, 234); background-color: rgb(248, 248, 248);
          border-radius: 3px 3px 3px 3px; display: inline;">chebyshev
          type-1</code> filter, but would a second order two-pass (aka
        zero phase?) butterworth be good enough considering the
        frequency bands used? I’m using the following cfg passed to <code
          style="font-size: 0.85em; font-family:
          Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em;
          padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid
          rgb(234, 234, 234); background-color: rgb(248, 248, 248);
          border-radius: 3px 3px 3px 3px; display: inline;">ft_preprocessing</code>
        for the initial bandpass filtering and rectification:</p>
      <pre style="font-size: 0.85em; font-family: Consolas,Inconsolata,Courier,monospace;font-size: 1em; line-height: 1.2em;margin: 1.2em 0px;"><code style="font-size: 0.85em; font-family: Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px 3px 3px 3px; display: inline;white-space: pre; overflow: auto; border-radius: 3px 3px 3px 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em;display: block; padding: 0.5em; color: rgb(51, 51, 51); background: none repeat scroll 0% 0% rgb(248, 248, 255);" class="language-matlab">freq = <span class="cell">{[<span style="color: rgb(0, 153, 153);" class="number">1</span> <span style="color: rgb(0, 153, 153);" class="number">4</span>], [<span style="color: rgb(0, 153, 153);" class="number">5</span> <span style="color: rgb(0, 153, 153);" class="number">8</span>], [<span style="color: rgb(0, 153, 153
);" class="number">9</span> <span style="color: rgb(0, 153, 153);" class="number">14</span>], [<span style="color: rgb(0, 153, 153);" class="number">15</span> <span style="color: rgb(0, 153, 153);" class="number">30</span>], [<span style="color: rgb(0, 153, 153);" class="number">30</span> <span style="color: rgb(0, 153, 153);" class="number">50</span>], [<span style="color: rgb(0, 153, 153);" class="number">50</span> <span style="color: rgb(0, 153, 153);" class="number">100</span>], [<span style="color: rgb(0, 153, 153);" class="number">100</span> <span style="color: rgb(0, 153, 153);" class="number">150</span>]}</span>;
<span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">for</span> <span style="color: rgb(0, 134, 179);" class="built_in">j</span> = <span style="color: rgb(0, 153, 153);" class="number">1</span>:<span style="color: rgb(0, 134, 179);" class="built_in">length</span>(freq)
 cfg                        = <span class="matrix">[]</span>;
 <span class="transposed_variable">cfg.</span>padding                = <span style="color: rgb(0, 153, 153);" class="number">0</span>;
 <span class="transposed_variable">cfg.</span>bpfilter            = <span style="color: rgb(221, 17, 68);" class="string">'yes'</span>;
 <span class="transposed_variable">cfg.</span>bpfilttype            = <span style="color: rgb(221, 17, 68);" class="string">'but'</span>;
 <span class="transposed_variable">cfg.</span>bpfreq                = freq<span class="cell">{j}</span>;
 <span class="transposed_variable">cfg.</span>bpfiltdir            = <span style="color: rgb(221, 17, 68);" class="string">'twopass'</span>;
 <span class="transposed_variable">cfg.</span>bpfiltord            = <span style="color: rgb(0, 153, 153);" class="number">2</span>;
 <span class="transposed_variable">cfg.</span>bpinstabilityfix    = <span style="color: rgb(221, 17, 68);" class="string">'reduce'</span>;
 <span class="transposed_variable">cfg.</span>rectify                = <span style="color: rgb(221, 17, 68);" class="string">'yes'</span>;
 bp<span class="cell">{j}</span> = ft_preprocessing(cfg,ft);
<span style="color: rgb(51, 51, 51); font-weight: bold;" class="keyword">end</span>
</code></pre>
      <p style="margin: 1.2em 0px ! important;">As far as I can see in <code
          style="font-size: 0.85em; font-family:
          Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em;
          padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid
          rgb(234, 234, 234); background-color: rgb(248, 248, 248);
          border-radius: 3px 3px 3px 3px; display: inline;">ft_preprocessing</code>
        rectification occurs after filtering, so this is as specified by
        Leopold <em>et al.,</em></p>
      <p style="margin: 1.2em 0px ! important;">Then for
        downsampling/resampling:</p>
      <pre style="font-size: 0.85em; font-family: Consolas,Inconsolata,Courier,monospace;font-size: 1em; line-height: 1.2em;margin: 1.2em 0px;"><code style="font-size: 0.85em; font-family: Consolas,Inconsolata,Courier,monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-radius: 3px 3px 3px 3px; display: inline;white-space: pre; overflow: auto; border-radius: 3px 3px 3px 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em;display: block; padding: 0.5em; color: rgb(51, 51, 51); background: none repeat scroll 0% 0% rgb(248, 248, 255);" class="language-matlab">cfg                        = <span class="matrix">[]</span>;
<span class="transposed_variable">cfg.</span>padding                = <span style="color: rgb(0, 153, 153);" class="number">0</span>;
<span class="transposed_variable">cfg.</span>lpfilter            = <span style="color: rgb(221, 17, 68);" class="string">'yes'</span>;
<span class="transposed_variable">cfg.</span>lpfreq                = <span style="color: rgb(0, 153, 153);" class="number">8</span>;
<span class="transposed_variable">cfg.</span>lpfilttype            = <span style="color: rgb(221, 17, 68);" class="string">'but'</span>;
<span class="transposed_variable">cfg.</span>lpfiltdir            = <span style="color: rgb(221, 17, 68);" class="string">'twopass'</span>;
<span class="transposed_variable">cfg.</span>lpfiltord            = <span style="color: rgb(0, 153, 153);" class="number">8</span>;
<span class="transposed_variable">cfg.</span>lpinstabilityfix    = <span style="color: rgb(221, 17, 68);" class="string">'reduce'</span>;
bp<span class="cell">{j}</span> = ft_preprocessing(cfg,bp<span class="cell">{j}</span>);
cfg                        = <span class="matrix">[]</span>;
<span class="transposed_variable">cfg.</span>resample            = <span style="color: rgb(221, 17, 68);" class="string">'yes'</span>;
<span class="transposed_variable">cfg.</span>resamplefs            = <span style="color: rgb(0, 153, 153);" class="number">20</span>;
<span class="transposed_variable">cfg.</span>detrend                = <span style="color: rgb(221, 17, 68);" class="string">'no'</span>;
bp<span class="cell">{j}</span> = ft_resampledata(cfg,bp<span class="cell">{j}</span>);
</code></pre>
      <p style="margin: 1.2em 0px ! important;">Does this seem a correct
        translation of this method in Fieldtrip? Are there any caveats
        other than the filter differences?</p>
      <p style="margin: 1.2em 0px ! important;">Thanks, Ian</p>
    </div>
  </body>
</html>