# FIR Filter design, using different filter length than signal length

Given some neurophysiological application I am filtering in real time data of limited length (e.g. in epochs of 100 ms) using a sampling rate of e.g. 100 Hz.

Due to this short time segment I am trying to implement a FIR filter. This filter should be of high order, and therefore have a length of more than 100 samples.

This would lead to the fact that the "to be filtered signal" has a different length than the estimated filter itself. Using the scipy.convolve function I can then specify different methods how to convolve the signal (full, valid, same).

My question is quite trivial, and related to lack of experience in the field, but does it make sense at all to have different filter and signal length? Is there literature how to interpret then the filtered signal? Since the convolution needs to define some padding for the signal itself the filtered signal should be only in a certain range interpretable right?

EDIT: Hereby I want to present an example. I plot a random signal in orange, and a FIR filter with a filter length of 10 s (estimated using mne.create_filter):

My understanding problem is visualized in this context: the signal itself is much shorter than the filter. This leads obviously to the fact that the filtered signal has a longer length. How can I now interprete the filtered signal with respect to the timing of the original signal that had fs=128 Hz? Which time points of the filtered signal correspond to the original signal?

The length of the total non-zero signal after the filter will be the sum of the filter length and signal length as given by what we would expect with convolution, with the signal content within the bandwidth of the filter delayed by the filters group delay (which is the derivative of the filters phase response with respect to frequency and can be computed using the grpdelay function in Matlab/Octave and Python's scipy.signal). With linear phase FIR filters (which occur when the filter's coefficients are symmetric or antisymmetric such as [1 2 3 4 3 2 1] or [1 2 3 4 -4 -3 -2 -1]) the group delay is constant for all frequencies and easy to compute (It will be half the length of the filter).

However if the OP's goal is to align the original signal in time with the filtered signal, I recommend using the filtfilt command available in Matlab/Octave and Python's scipy.signal which is a (post-processing) zero-phase filter; the output samples in time will be aligned with the input samples as given from the alignment of the first samples out of the filter compared to the first samples into the filter. As explained further in the documentation, filtfilt applies the same FIR filter both forward and backward resulting in zero phase delay (this is non-causal so can only be for a post processing applications where actual delay in processing is of no consequence) and a magnitude response that is the cascade of the filter twice , so a square-root filter is used to get the same magnitude response. For further details on filtfilt see What is the advantage of MATLAB's filtfilt

There's no requirement that the signal to be filtered has to have the same length as the filter - in fact, that's practically never the case.

So, there's no problem here; convolution doesn't need to "define some padding"; you'll find discrete convolution is just defined as finite sum over the available lengths.

The length difference between signal and filter isn't of relevance to "track back" a phenomen in the input signal: the time is always the time in the output signal, minus the filter's group delay. Assuming your filter is linear phase / time-symmetric, that's simply half the filter length.

• Thanks a lot for the quick answer. I edited my question above. My main understanding problem is related to the interpretability of the filtered signal, especially if I want to "track back" the sample time points of the filtered and original signal, since this would be quite important for my analysis.
– Merk
Apr 28 at 10:11