Initial conditions for the filter delays
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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) ;
y=[y1;y2];
Is that what it should be?
0 Commenti
Risposte (1)
Vasishta Kanthi
il 24 Set 2018
Modificato: Vasishta Kanthi
il 24 Set 2018
Short Answer: Yes and No
Long Answer: It depends on y1 and y2... lets say:
x=randn(1,10000);
and you want to filter this signal, but instead of the whole signal, you do it in blocks, such that:
x1=x(1:5000);
x2=x(5001:end);
then your code will definitely work, because in order to have continuity, the delay of block x1 shud be given to block x2. Although,
[y1,zi]=filter(b,a,x1);
y2=filter(b,a,x2,zi);
y=[y1;y2];
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:
x=randn(2,10000);
y1=x(1,:);
y2=x(2,:);
y=[y1;y2];
Then this becomes a stereo signal. So,
[b,a]=butter(n,w0,'low')
filtered_signal=filter(b,a,y);
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:
Cheers!!!
0 Commenti
Vedere anche
Categorie
Scopri di più su Filter Design in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!