• No results found

(1)Determining the initial states in forward-backward ltering Fredrik Gustafsson Submitted to IEEE Trans

N/A
N/A
Protected

Academic year: 2021

Share "(1)Determining the initial states in forward-backward ltering Fredrik Gustafsson Submitted to IEEE Trans"

Copied!
8
0
0

Loading.... (view fulltext now)

Full text

(1)

Determining the initial states in forward-backward ltering

Fredrik Gustafsson

Submitted to IEEE Trans. on Signal Processing

Abstract

Forward-backward ltering is a common tool in o-line ltering. Filtering

rst forwards and then backwards and the other way around do not give the same result generally. Here we propose a method to choose the initial state in the lter to eliminate this discrepancy. The objectives are to obtain uniqueness and to remove transients in both ends.

1 Introduction

In batchwise signal processing one has the possibility not only to lter a signal forwards in time as usual, but also apply a lter backwards on the ltered signal. Forward- backward ltering is needed in the following applications for example:

Zero-phase ltering using IIR lters.

Implementation of non-causal Wiener lters or other lters with poles both inside and outside the unit circle.

The rst trick to obtain zero-phase lters is used in many software packages, see for instance the function filtfilt in Matlab 2], although it is not much discussed in

Department of Electrical Engineering, Linkoping University, S-58183 Linkoping, Sweden

1

(2)

standard text books. The design of non-causal Wiener lters leads to a lter with one stable part and one unstable one as discussed in for instance 1]. The unstable part must be implemented using backward ltering. In both cases, there might be a problem with transients when applied to nite signals.

A lter G(q) becomes all-pass, or zero phase, when applied rst forwards, yf(t) =

G(q)u(t), and then backwards on the reversed ltered signal, yRfb(t) = G(q)yRf(t), and

nally the output is reversed again. The superindex R stands for reversed sequences, the indexes f for forward andb for backward and q denotes the shift operatorqu(t) =

u(t+1). We can also rst lter backwards and then forwards and obtainybf(t). In both cases, the total eect is a zero phase lter with transfer function jG(ei!)j2. However, we have yfb(t) 6= ybf(t) generally due to unknown initial conditions, and this is not satisfactory from the logical point of view. Besides, the FB (forward-backward) ltered sequence has visible transients in the end and the BF ltered sequence at the beginning.

One way to obtain symmetry is to implement a lter with poles both inside and outside the unit circle by using the partial fractions of the stable poles and unstable poles respectively. This is the standard way in non-causal Wiener ltering. The stable lter is applied forwards on the input and the unstable lter backwards and the lter output is the sum of these terms. Since both lters are applied to the input, the result is of course independent of the order of computations. However, there still is a problem with transients, this time in both ends, due to unknown initial conditions.

We will here determine the initial conditions that makesybf(t) =yfb(t) and at the same time removes the transients. That is, the initial condition of one lter is chosen to match the end of the other lter. Instead of solving the system of equations arising from the conditionybf(t) =yfb(t), we will work in a least squares framework, which immediately gives a feasible implementation. The method is illustrated on ltered white noise. The improvement for short data records or long lter impulse responses is obvious.

2 Determining the initial state

A linear lter can always be expressed as

Y =H U +Ox0

whereY = (y0y1::yN;1)T is the vector of outputs,U = (u0u1::uN;1)T is the vector of inputs to the lter andx0 its initial state. His a Toeplitz matrix of impulse response

2

(3)

coecients

H=

0

B

B

B

B

B

B

@ h

0 0  0

h

1 h

0 0 ...

... ...

h

N;1

 h

1 h

0 1

C

C

C

C

C

C

A

(1)

where N is the number of inputs, and O is an \observability" matrix. If the lter is written in state space form

x(t+ 1) = Fx(t) +Gu(t)

y(t) = Hx(t) +Du(t) then

H =

0

B

B

B

B

B

B

@

D 0  0

HG D 0 ...

... ...

HF N;2

G  HG D 1

C

C

C

C

C

C

A

(2)

O =

0

B

B

B

B

B

@ H

HF...

HF N;1

1

C

C

C

C

C

A

(3)

We introduce the row and column reversing operators R and C with the following easily checked properties:

A = BC )

A

R = BRC

A

C = BCC

BC

R = BCC (BCRC)RC = BRCC

A

RC = AT if AToeplitz

The forward and backward lters are characterized by the pairs (HfOf) and (HbOb).

Using the notation x0 and xN;1 for the initial conditions for forward and backward

lters, the result of forward-backward and backward-forward ltering can be written as

Y

fb = (HbYfR+ObxN;1)R

= HRb(HfU +Ofx0)R+ObRxN;1

= HRbHRfU +HbROfRx0+ObRxN;1 3

(4)

and

Y

bf = HfYbR+Ofx0

= Hf(HbUR+ObxN;1)R+Ofx0

= HCfHCb U+HfORb xN;1+Ofx0 respectively. Note thatHRbHfR6=HCfHCb .

It turns out that there always is a solution to Yfb ;Ybf = 0. We will not prove this statement. Instead we formulate the problem as minimizingkYfb;Ybfk22, which turns out to be easier to solve. We have

Y

fb

;Y

bf = (HbRHRf ;HCfHCb )U + (HRbORf ;Of)x0+ (I;Hf)ORb xN;1 Since this is a linear expression inx0 and xN;1, the minimizing arguments are given by the least squares estimate

d 0

@ x

0

x

N;1 1

A=h(HRb OfR;Of) (I;Hf)ObRi#HRbHRf ;HCfHCb U

Here # denotes pseudo-inverse. By substituting these estimated initial states into the FB and BF lters we get

^

Y

fb = HbRHRfU+hHbROfR ObRih(HRb OfR;Of) (I;Hf)ObRi#HRbHRf ;HCfHCb U

^

Y

bf = HfCHbCU +hOf  HfORb ih(HRbOfR;Of) (I;Hf)ORbi#HRbHRf ;HCfHCb U The expressions given above are not useful for implementation, since N N matrices are involved. Next we seek a feasible implementation without computingH explicitely.

3 Fast implementation

In this section we describe how Yfb, without proof claimed to be the same as Ybf, can be computed eciently. First an exact method is detailed, where the initial states are computed with linear in time complexity, and then a constant complexity approximation is proposed.

We rst compute the nominal values of Yfb and Ybf for zero initial conditions using standard lter routines. That is, we have

Y 0

fb = HRbHfRU

Y 0

bf = HCfHCbU 4

(5)

We also need arbitrary state space realizations of the lters, (FfGfHfDf) and (FbGbHbDb). The \observability" matrixes Of and Of are computed according to (3). Now, we just have to compute the quantities Sbf =4 HbORf and Sfb =4 HfORb and we can express the least squares estimate as

d 0

@ x

0

x

N;1 1

A=h(SfbR ;Of) ORb ;Sbfi#(Ybf0 ;Yf0b): Thus, we have

Y

fb = Yf0b+hSbfR  ObRih(SfbR ;Of) ORb ;Sbfi#(Ybf0 ;Yf0b): (4) Next is shown that Sfb can be computed without forming the N N matrix Hf. The vectors of impulse response coecients can be expressed in hf as

h

f =

2

4

D

f

O

f(1 :N ;1:)Gf

3

5

:

Here Of(1 :N ;1:) means rows 1 to N;1 of Of. Note that hf is the rst column of

H

f. Let Sfb(t: :) denote the t'th row of Sfb and hf(t) the t'th component of hf. From (1), (2) and (3) we have

S

fb(N:) = (hRf)TObR= (hTf)CObR=hTfOb

S

fb(N ;1:) = Sfb(N:)Fb;hf(N)HbFbN;1

S

fb(t;1:) = Sfb(t:)Fb;hf(t)HbFbN;1 Thus, Sfb can be computed by the recursion

S

fb(N:) = hTfOb

S

fb(t;1:) = Sfb(t:)Fb;hf(t)HbFbN;1 t=NN ;1:::2:

and Sbf is computed similarly. In this way, we do not have to compute the N N matrix H explicitely, but only the N2n matrices O and S.

4 Fixed complexity approximation

For long signals, it seems to be overkill to work with the complete impulse response h and observability matrix O. If we assume that the impulse response is approximately

5

(6)

zero for t > M a logical approximation in (4) is to replace Ft by 0 if t > M. This leads to an ^O having non-zero elements in its rstM rows only, and ^S having non-zero elements in its lastM rows. Thus, we are faced with a least squares problem with 2M equations and 2n unknowns, so all that is needed is to compute the pseudo-inverse of a 2M 2n matrix in (4).

5 Simulations

In this section, a band-pass Butterworth lter applied to a white noise sequence1 will be examined. The lter is of tenth order with (normalized) cut-o frequencies 0.2 and 0.25 and the noise sequence is of length 200. Figure 1 shows rstYfb andYbf using the initial states in Matlab's filtfilt2 function in the signal processing toolbox and second the result using zero inital states x0 and xN;1, i.e. Yfb = HRHRU and Ybf = HCHCU. Then follows the signals (4) using optimized initial states. Finally, the result using partial fractions,

jH(q)j2= B(q)

A(q)

B(q;1)

A(q;1) =

C(q)

A(q) +

D(q)

A(q;1)

is shown. As seen, the last two curves are identical showing the symmetry of the proposed initialization method. The 2-norms are as follows:

kY fil tfil t

fb

;Y fil tfil t

fb k

2 = 1:6

kY 0

fb

;Y 0

fb k

2 = 1:0

kY^fb ;Y^fbk2 = 810;13

Thus, there is a signicant dierence depending on the order of forward and backward

ltering for the rst two choices of initial conditions. The transient from the lter is clearly visible either in the beginning or the end. The proposed method and the partial fraction method are perfectly symmetric.

To highlight the transients due to unknown initial conditions in the partial fraction method, a very simple zero-phase high-pass lter is used,

y(t) =

1

q+ 0:8

2

u(t) = 125=36

q+ 1:25; 20=9

q+ 0:8

1The result can be reproduced using Matlab's Gaussian distribution with seed 0

2Version 4.1 and earlier of Matlab has a bug. With the following de nition of the initial statezi, the function works as intended: zi = (eye(nfilt-1) + aa(2:nfilt)' -eye(nfilt-2) zeros(1,nfilt-2)]])n (bb(2:nfilt)-bb(1)*aa(2:nfilt))'

6

(7)

0 20 40 60 80 100 120 140 160 180 200

−0.5

−0.4

−0.3

−0.2

−0.1 0 0.1 0.2 0.3 0.4 0.5

Forward−backward filtering using Matlab‘s filtfilt

0 20 40 60 80 100 120 140 160 180 200

−0.5

−0.4

−0.3

−0.2

−0.1 0 0.1 0.2 0.3 0.4 0.5

Forward−backward filtering using zero initial conditions

0 20 40 60 80 100 120 140 160 180 200

−0.5

−0.4

−0.3

−0.2

−0.1 0 0.1 0.2 0.3 0.4 0.5

Forward−backward filtering using optimized initial conditions

0 20 40 60 80 100 120 140 160 180 200

−0.5

−0.4

−0.3

−0.2

−0.1 0 0.1 0.2 0.3 0.4 0.5

Forward−backward filtering using partial fractions

Figure 1: The forward-backward and backward-forward ltered signal using rst Mat- labs ltlt, then zero initial condition, optimized initial conditions and nally using partial fractions.

7

(8)

0 20 40 60 80 100 120 140 160 180 200 5

10 15 20 25 30 35 40 45 50

Forward−backward filtering using optimized initial conditions

0 20 40 60 80 100 120 140 160 180 200

−100

−50 0 50 100 150 200

Forward−backward filtering using partial fractions

Figure 2: The ltered signal using optimized initial conditions and partial fractions.

and a DC oset of 100 is added to the u(t) used in the previous example. The result is shown in Figure 2. The transients for the partial fraction method are obvious. Of course, some ad-hoc rules can be used to determine initial conditions to compensate for the DC oset in this example. The point is, that the proposed method computes the initial conditions for each lter to match the end of the other lter response when the transient hopefully is gone.

6 Conclusion

We have here detailed a method to choose the initial conditions for lters to be applied forwards and backwards to a signal. The objectives were to get the same result inde- pendently of the order of ltering and to minimize transients due to osets and trends in the data. Zero initial conditions or other ad-hoc initializations can by examples eas- ily be shown to give undesired transients at the beginning or end of the data sequence depending on the order of application of the forward and backward lters. Transients are also a problem when using partial fractions of the stable and unstable parts. The proposed method gives no transients and is symmetric, which was exemplied by a simulation.

References

1] T. Kailath. Lectures on Wiener and Kalman ltering. Springer-Verlag, Wien, 1981.

2] MATLAB. Signal Processing Toolbox User's Guide. The MathWorks, Inc, 1993.

8

References

Related documents

The EU exports of waste abroad have negative environmental and public health consequences in the countries of destination, while resources for the circular economy.. domestically

Under the Aktiengesetz (German Stock Corporation Act), the dividends distributable to the shareholders are based solely on Continental AG’s net retained earnings, which amounted

46 Konkreta exempel skulle kunna vara främjandeinsatser för affärsänglar/affärsängelnätverk, skapa arenor där aktörer från utbuds- och efterfrågesidan kan mötas eller

The increasing availability of data and attention to services has increased the understanding of the contribution of services to innovation and productivity in

Av tabellen framgår att det behövs utförlig information om de projekt som genomförs vid instituten. Då Tillväxtanalys ska föreslå en metod som kan visa hur institutens verksamhet

Närmare 90 procent av de statliga medlen (intäkter och utgifter) för näringslivets klimatomställning går till generella styrmedel, det vill säga styrmedel som påverkar

På många små orter i gles- och landsbygder, där varken några nya apotek eller försälj- ningsställen för receptfria läkemedel har tillkommit, är nätet av

While firms that receive Almi loans often are extremely small, they have borrowed money with the intent to grow the firm, which should ensure that these firm have growth ambitions even