Initial conditions for the filter delays

32 views (last 30 days)
hoda kazemzadeh
hoda kazemzadeh on 22 Jun 2018
Edited: Vasishta Kanthi on 24 Sep 2018
How can I use initial conditions for the filter delays when I have to use filter function in matlab?
[y1,zi] = filter(b,a,x1);
[y2]=filter(b,a, x2,zi) ;
Is that what it should be?

Answers (1)

Vasishta Kanthi
Vasishta Kanthi on 24 Sep 2018
Edited: Vasishta Kanthi on 24 Sep 2018
Short Answer: Yes and No
Long Answer: It depends on y1 and y2... lets say:
and you want to filter this signal, but instead of the whole signal, you do it in blocks, such that:
then your code will definitely work, because in order to have continuity, the delay of block x1 shud be given to block x2. Although,
the 'y=[y1;y2]' is a bit strange to me... in the sense, im not sure how your vectors are called upon... if 'x' is a column vector, then this works, otherwise, this is definitely odd to use. Instead, it should be y=[y1,y2]. This way, you preserve the continuity by having a vector, instead of a matrix.
if your signal is a stereo signal, then you definitely shouldn't introduce any intitialization …. the sound will be completely odd... lets say:
Then this becomes a stereo signal. So,
is the right way, and both the channels will have the same filter delay. I hope this is what you're looking for :-)
I used the 'butter' filter type as an example. In general, all filters, regardless, FIR or IIR, they all introduce delay, and so, if you really want to keep the output phase response the same as the input phase response, then for FIR, use the grpdelay() function to calculate the delay samples, and shift your time signal accordingly, and for IIR, use filtfilt() function instead of filter(), because IIR filter delay is frequency dependent.
Check out this link for more information on delay compensation:


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!