You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: others/Firfilt_FAQ.md
+21-15Lines changed: 21 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -189,15 +189,17 @@ How can we address these problems?
189
189
### Q. When should causal filters be used? (3/15/2021)
190
190
191
191
Causal filters typically should only be used if the application explicitly requires this. For example, if causality matters as in the detection of onset latencies (even if the problem is overestimated as it mainly affects ultra-sharp transients typically not observed in EEG/ERP), the analysis of small fast components before large slow components (e.g. if higher high-pass cutoff frequencies are required), or in the analysis of pre-stimulus activity, that is, your case. The difference between a linear causal and linear non-causal filter is exclusively the time axis. The output of the non-causal filter equals the delay corrected output of the causal filter. It is sufficient to change the EEG.times time axis. That is, if your signal of interest is further away from stimulus onset than the group delay, you can simply use a linear non-causal filter.
192
-
% Example:
193
192
194
-
sig = [ 0 0 0 0 0 1 0 0 0 0 0 ]; % test signal (impulse)
195
-
b = [ 1 1 1 1 1 ] / 5; % some crude boxcar filter for demonstration purposes only, linear-phase, length = 5, order = 4, group delay = 2
196
-
fsig = filter( b, 1, sig ); % causal filter
197
-
plot( -5:5, [ sig; fsig ]', 'o' ) % the filtered impulse in the output does not start before the impulse in the input
fsig = fsig( 3:end ); % delay correction by group delay, this is what makes the filter non-causal and zero-phase
200
-
plot( -5:5, [ sig; fsig ]', 'o' ) % the filtered impulse in the output starts before the impulse in the input BUT everything before x = -2 is unaffected
193
+
% Example:
194
+
```matlab
195
+
sig = [ 0 0 0 0 0 1 0 0 0 0 0 ]; % test signal (impulse)
196
+
b = [ 1 1 1 1 1 ] / 5; % some crude boxcar filter for demonstration purposes only, linear-phase, length = 5, order = 4, group delay = 2
197
+
fsig = filter( b, 1, sig ); % causal filter
198
+
plot( -5:5, [ sig; fsig ]', 'o' ) % the filtered impulse in the output does not start before the impulse in the input
fsig = fsig( 3:end ); % delay correction by group delay, this is what makes the filter non-causal and zero-phase
201
+
plot( -5:5, [ sig; fsig ]', 'o' ) % the filtered impulse in the output starts before the impulse in the input BUT everything before x = -2 is unaffected
202
+
```
201
203
202
204
### Q. Should I use a linear causal FIR filter with delay correction or a non-linear causal filter (e.g. minimum-phase)?
203
205
@@ -214,8 +216,9 @@ For filter order = 1650 -> N = 1651 samples (N taps = filter length = filter ord
214
216
Yes, firfilt automatically corrects for the group delay, that is, implements a zero-phase FIR filter. But firfilt is a low-level function and you should know what you are doing when using it. If you want to do this on the command line I would rather recommend using fir_filterdcpadded. There is a 'causal‘ flag and you can do causal and non-causal (linear phase only) filtering. fir_filterdcpadded must be used with continuous segments only. firfilt also works with boundaries. firfilt was designed long time ago when memory was a limited resource and is memory optimized but complex. It will be sooner than later be fully replaced by fir_filterdcpadded (as in Fieldtrip) which is simple and fast but memory consuming.
215
217
Note: fir_filterdcpadded always operates (pads, filters) along first dimension.
216
218
So, with EEG.data (chans x times) it is necessary to transpose (twice):
### Q. What about IIR filters and causal filtering?
220
223
221
224
Note that you cannot delay correct an IIR filter (the impulse response is infinite and the phase response non-linear) and order has a very different meaning. Indeed, backward-forward filtering will result in a non-causal zero-phase filter (actually, the order of backward-forward or forward-backward doesn’t matter). As an IIR filter is used there is no temporal limit for non-causal effects (here post-stimulus on pre-stimulus time ranges) as with FIR filters.
@@ -254,13 +257,16 @@ Sorry, I cannot comment on this. Just a general note: I’m sometimes lazily wri
254
257
### Q. Are there other Matlab/EEGLAB options I could use to design filters from the command line?
0 commit comments