fir_nodelay

Delay free filtering


[y,h] =fir_nodelay(x,n,fc,qual)  % Matlab & Octave
list <- fir_nodelay(x, n, fc, qual='low') # R

Delay-free filtering using a linear-phase (symmetric) FIR filter followed by group delay correction. Delay-free filtering is needed when the relative timing between signals is important e.g., when integrating signals that have been sampled at different rates.

Input var Description Units Default value
x is the signal to be filtered. It can be multi-channel with a signal ineach column, e.g., an acceleration matrix. The number of samples (i.e., the number of rows in x) must be larger than the filter length, n. Hz N/A
n is the length of symmetric FIR filter to use in units of input samples (i.e., samples of x). The length should be at least 4/fc. A longer filter gives a steeper cut-off. N/A N/A
fc is the filter cut-off frequency relative to 1=Nyquist frequency. If a single number is given, the filter is a low-pass or high-pass. If fc is a vector with two numbers, the filter is a bandpass filter with lower and upper cut-off frequencies given by fc(1) and fc(2). For a bandpass filter, n should be at least 4/fc(1) or 4/diff(fc) whichever is larger. N/A N/A
qual (optional) is qualifier determining if the filter is:'low' low-pass (the default value if fc has a single number), 'high' high-pass N/A N/A
Output var Description Units
y is the filtered signal with the same size as x. Hz
h is the vector of filter coefficients used by fir_nodelay (a vector). This can be used to plot the filter characteristic using freqz(h,1,1024,fs) N/A
  • h is always an odd length filter even if n is even. This is needed to ensure that filter is both symmetric and has a group delay which is an integer number of samples. The filter has a support of n samples, i.e., it uses n samples from x to compute each sample in y. The input samples used are those n/2 samples before to n/2 samples after the sample number being computed. This means that samples at the start and end of the y vector need input samples before the start of x and after the end of x. These are faked by reversing the first n/2 samples of x and concatenating them to the start of x. The same trick is used at the end of x. As a result, the first and last n/2 samples in y are untrustworthy. This initial condition problem is true for any filter but the FIR filter used here makes it easy to identify precisely which samples are unreliable.

Matlab & Octave

x = sin(2*pi*0.05*(1:100)')+cos(2*pi*0.25*(1:100)');
y = fir_nodelay(x,30,0.2)
plot([x,y])
% Applying the low-pass filter
% removes most of the fifth harmonic so the output appears as a sinewave except for the first
% few samples which are affected by the filter startup transient.

R

#Make a waveform with two harmonics - one at 1/20 and another at 1/4 of the sampling rate.
x <- sin(t(2 * pi * 0.05 * (1:100))+t(cos(2 * pi * 0.25 * (1:100))))
Y <- fir_nodelay(x=x, n=30, fc=0.2, qual='low')
plot(c(1:length(x)),x, type='l', col='grey42',
xlab='index', ylab='input x and output y')
lines(c(1:length(Y$y)),Y$y, lwd=2)  

bugs@animaltags.org Last modified: 10 May 2017

  • tagwiki/tools/processing/fir_nodelay.txt
  • Last modified: 2017/07/27 19:10
  • by das39