1
votes

I am using a FIR filter in MATLAB to filter a signal. In the figure below, applying my filter to the top plot creates the bottom plot:

enter image description here

The effect this has is to successfully low-pass filter the data, but to shift everything along by 500 msec.

Here is the routine I use to low-pass filter the data:

% (Start with any vector called 'inputData')

samplingRate = 1000;
filterLength = 1000;
filterCutOff = 90;

filterType = fir1(filterLength , filterCutOff/(samplingRate/2), 'low'); % define the low pass filter
inputData = filter(filterType,1,inputData); % filter the data

I'm aware that the 500 msec shift of my data relates to half the filter length (1000ms), but why does this happen, and am I doing something fundamentally wrong? I know that I could just delete the first 500 msec of my filtered data, but I am also missing the last 500 msec of the data.

Note that this example requires the signal processing toolbox.

2
If you don't want the delay, you will need to use an IIR filter zero phase delay (filtfilt). You can't have a FIR without delay. That is, you will need to choose the filter which is best for your situation…Werner
@Werner, thanks for this. If you add this as an answer I can accept it as correct.CaptainProg
There you are, added a book reference that I used, but of course there are many books.Werner

2 Answers

0
votes

If you don't want the delay, you will need to use an IIR filter zero phase delay (use filtfilt).

You can't have a FIR without delay. That is, you will need to choose the filter which is best for your situation…

For more information on filters, use:

Mitra, S. K. Digital Signal Processing: A Computer-Based Approach, 2nd Ed. Mcgraw-Hill College

Of course, you may choose the newest edition if you like.

0
votes

If you want to avoid the delay you can replace

inputData = filter(filterType,1,inputData);

with

inputData = conv(filterType, inputData, 'same');

However your signals won't be in synch anymore and you have to take into account a delay equal to half the length of filter in other parts of code.