How to implement a FIR filter with correction of group delay on c#?

I read respect to digital filters, and implemented both IIR and FIR filters and I found that this type of filters have a called "group delay". Now I know that the IIR have a non-linear group delay and the FIR have a linear group delay.

I have a real-time system that require a high-pass filter computed over a computer (good processor and RAM), allways that pass through the filter I'll have a phase distortion, taking advantage of the good processor: What is the best method to correct the phase and faked the response of the filter with the correct phase?

In the image above I extend my input signal with the same number of coefficients at the right and I try to correct the group delay, filtering the first time, invert the response in the time and pass again by through the filter and revert again the response in the time. The result correct the phase but causes other type the distorsion in the last samples. What is wrong? My knowledge about filters is not so wide unfortunately.

Note: The number of coefficients that I am using is 1000, Fs: 6400 samples/second and cutOff: 10 Hz.

I appreciate so much any help and aclaration. Thanks

• Like Ben says, filtering in the forward direction and then the backward direction is a adaptation of filtfilt function in Matlab. My first problem is calculate dynamically that amount of samples, based on sampling frequency and cutOff frequency (maybe the coefficients number - I don't know very well). Secondly, after filtering the signal I need integrate the signal and other operations, so, if I ignore a portion of signal will be a problem. Jul 17, 2017 at 20:43

Any kind of digital filter will cause the the output signal to be delayed by some amount of samples.

From what I gather, you are trying to run a signal through a high pass filter (is it an FIR or IIR?) and correct the group delay by "filtering the first time, inverting the response in time...". I personally have never been taught or have read of such an algorithm to correct for group delay.

One thing that I am confused about is why you want to fix the group delay. You are not ok with the input signal being delayed by a few hundred samples? All you do is have to wait and all will be fine.

The only reason why I would think you'd need to fix the group delay, is to compare the filtered response to the original signal in the time domain. Or do something much more advanced than garden variety filtering. If you are trying to compare time domain responses, you will have to delay the reference signal by the same amount of FIR filter delay your high pass filter has.

If this answers your question, respond and I'll go into more detail on how to delay your reference signal, and how to find the sample delay of an FIR filter. You can also google "sample delay of fir filter".

• Filtering in the forward direction and then the backward direction is implemented as the "filtfilt" function in Matlab. dsp.stackexchange.com/questions/9467/…
– Ben
Jul 17, 2017 at 3:18