Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

reverse filtering IIR with matlab func filtfilt()

Status
Not open for further replies.

sam_manchali

Member level 4
Joined
Jun 14, 2003
Messages
69
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,288
Location
sharjah
Activity points
735
filtfilt matlab

hi,
has anyone tried to replicate the matlab filtfilt() in c or some other HLL. i tried for a couple of days and i am not sure of the results.
Can someone be kind enough to explain in detail how the algorithm works in "c"??
thanks a lot

sam

Note: i am desigining a HP iir filter with zero phase error. i cant afford a FIR filter ( i am eliminating the DC offset ).
 

matlab filtfilt

Hi sam_manchali,

I have not implemented filtfilt in C but Iknow in general the idea.

Several remarks:

1. You know that filtfilt is implemented as m Matlab function socan see the code
2. If you have analof the matlab filt in C it should be strighforward to implement the rest. Just some padding at bot ends and filtering in foreward and backward direction
3. If you have some doubts just compare the matlab and c version for the simple test vector.

If you have some troubles of interpretation of the filtfilt.m function please
let me what exactly is not clear for you and I'll try to help you

Luck!
dora
 

filtfilt

Hi sam_manchali,

Imagine you have a sequence x[n] with Z-transform X(z). Let us pass it by a filter with impulse response h[n], but taking x[n] in reversed order, say x[-n], whose Z-transform is X(z^-1). The obtained sequence has Z-transform X(z^-1)*H(z). If you take this output in reversed order, the result is Y(z)=X(z)*H(z^-1). Otherwise stated, it is the result of filtering the original sequence with a filter with transfer function H(z^-1), or impulse response h[-n], that is, h[n] reversed in time.
If the filter h[n] is causal, h[-n] is anticausal. The amplitudes of H(z^-1) and H(z) are the same, but the phases are opposite. If H(z) has a pole (or zero) at Zp (say inside the unit circle), H(z^-1) has a pole (or zero) at Zp^-1 (outside the unit circle).
Now, take Y(z) and apply to it the filter H(z) again. You obtain X(z)*H(z^-1)*H(z). You get the original sequence X(z) filtered by a filter H(z^-1)*H(z), that has zero-phase becuase the phases of H(z) and H(z^-1) compensate. The resulting impulse response is the convolution of h[n] with h[-n], that is symmetrical in time (as expected for a funcion with zero phase). The resulting transfer funcion is |H(z)|^2 (with zero phase).
Clearly, the two stages (filtering forward and backward) can be performed in any order.

This is the kind of processing filtfilt() performs.

Pay attention that if you use an IIR filter, the sequence obtained after the first filtering (y[-n]) extends to infinite in time, and when you take it in reverse order you have to truncate it in time, and an error arises if you don’t compensate the initial conditions. The filtfilt() function takes into account this effect.

The problem is that this technique can be applied only to finite sequences, and not in real-time, because you need to be able to take a sequence in both orders (forward and reversed). This is a serious limitation for many applications.

I hope this is useful.
Regards

Z
 

reverse filtering

hi zorro and dora,
that was v nice. :) i have got it how it works and as u have said i cant implement it for real time(v difficult even if the data is taken in frames)

Is there an algo or paper for real time zero phase iir filters ??
can u suggest some links for the same??

thanks a lot
sam
 

reverse filtering

Hi sam,

any HP IIR filter has zero phase at frequencies much higher than the cut-off frequency. If your goal is to eliminate the DC offset and your signal has not components aroun DC, you could use a simple HP filter. Why not?
Regards

Z
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top