Non-Recursive Design Digital Controller Design

Digital Controls & Digital Filters Lectures 23 & 24

M.R. Azimi, Professor

Department of Electrical and Computer Engineering Colorado State University

Spring 2017

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Approximation Methods: FIR Digital Filters

FIR filter are described by convolution summation: N−1 y(n) = P h(k)x(n − k) x(n): Input signal y(n): Output signal k=0 h(n): Impulse response (filter coefficients) N: Filter order Advantages:

1 Inherently stable.

2 characteristic especially useful in applications where frequency dispersion due to non-linear phase is harmful e.g. speech and audio processing.

3 Quantization effects can be made small.

4 Implementation using parallel/pipeline processors because of inherent concurrency. Disadvantages:

1 For a sharp cut-off performance a large order filter is required =⇒ large computation time for implementation.

2 In some cases ”fractional delay” may be needed which can not be realized by physical devices.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Response of FIR Filters

The transfer function of a causal FIR filter is:

N−1 H(z) = P h(n)z−n n=0 Let z = ejΩ (i.e. unit circle) N−1 H(ejΩ) = P h(n)e−jΩn = DTFT {h(n)} n=0 2πk Sampling the frequency scale Ω = N yields the N elements of the DFT of h(n) as:

N−1 − 2πjkn H(k) = P h(n)e N = DFT {h(n)}, k ∈ [0,N − 1] n=0 and N−1 jπjkn 1 P N h(n) = IDFT {H(k)} = N H(k)e , n ∈ [0,N − 1] n=0 Now, consider the following cases.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Response of FIR Filters-Cont.

Case 1: Symmetric: h(n) = h(N − 1 − n) and N odd

(N−1) 2 jΩ −jΩ (N−1) H(e ) = e 2 P α(n) cos Ωn n=0 where h (N−1) i N−1 α(n) , 2h 2 − n , n ∈ [1, 2 ]  (n−1)  α(0) , h 2 (N−1) φ(Ω) = −Ω 2 : linear

dφ(Ω) N−1 Group delay τg = − dΩ = 2 : Integer

Case 2: Symmetric: h(n) = h(N − 1 − n) and N Even

N/2 jΩ −jΩ (N−1) H(e ) = e 2 P β(n) cos [Ω(n − 1/2)] n=1 where, N β(n) , 2h( 2 − n), n ∈ [1,N/2] Note that at Ω = π, H(ejΩ) = 0 i.e HPF can not be approximated.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Response of FIR Filters-Cont.

N−1 Case 3: Anti-Symmetric: h(n) = −h(N − 1 − n), h( 2 ) = 0, and N odd

(N−1) 2 jΩ −jΩ (N−1) jπ/2 H(e ) = e 2 e P γ(n) sin Ωn n=1 where h (N−1) i N−1 γ(n) , 2h 2 − n , n ∈ [1, 2 ]

Case 4: Anti-Symmetric: h(n) = −h(N − 1 − n) and N even

N/2 jΩ −jΩ (N−1) jπ/2 H(e ) = e 2 e P δ(n) sin [Ω(n − 1/2)] n=1 where, N δ(n) , 2h( 2 − n), n ∈ [1,N/2] In the anti-symmetric case at Ω = 0,H(ejΩ) = 0. i.e. suitable for approximating such filters as differentiators and Hilbert transforms

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Sampling Method

Design Methods 1 Windowing 2 Frequency sampling method 3 Computer aided design methods (CAD) Frequency Sampling Method jΩ Idea: Given the frequency response of the desired filter, HDes(e ), sample it to obtain H(k) and then take IDFT of {H(k)} to get {h(n)}.

Let the transfer function of the FIR filter be : N−1 H(z) = P h(n)z−n n=0 we know that N−1 −j2πkn P N H(k) = H(z)|z= j2πk = h(n)e , k ∈ [0,N − 1] N n=0

N−1 j2πkn 1 P N Additionally: h(n) = IDFT {H(k)} = N H(k)e , n ∈ [0,N − 1] k=0 Then, N−1 N−1  N−1 N−1 j2πkn H(k) j2πk P P N −n P P N −1 n H(z) = H(k)e z = N (e z ) n=0 k=0 k=0 n=0

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Sampling Method-Cont.

N−1 P n 1−aN Now using a = 1−a , we get , n=0 N−1 −N N−1 P H(k) (1−ej2πkz−N ) (1 − z ) X H(k) N j2πk = j2πk k=0 (1−e N z−1) N (1 − e N z−1) | {z } k=0 H1(z) | {z } H2(z) which can be realized by cascade of a simple FIR (Comb) filter with an IIR system.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Sampling Method

The term (1 − z−N ) represents an FIR filter with frequency response N h N N i N jΩ −jΩN −jΩ 2 jΩ 2 −jΩ 2 −jΩ 2 ΩN H1(e ) = 1 − e = e e − e = e 2j sin 2 jΩ The plot of |H1(e )| as a function of Ω is shown below.

The IIR part, H2(z), consists of parallel combination of N complex coefficient j2πk 1st order systems with poles at zk = e N on the unit circle. Of course these j2πk poles will be cancelled with the zeros of H1(z) which also occur at zk = e N −N 1/N j2πk since 1 − z = 0 =⇒ z = (1) =⇒ zk = e N , k ∈ [0,N − 1]

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Sampling Method

In order to have H(z) with real coefficients (physical realization) we require that H(k) = |H(k)|ejθ(k) satisfy:

|H(k)| = |H(N − k)| and θ(k) = −θ(N − k), k ∈ [0,N − 1]

N Now each pair of H(k) and H(N − k), k ∈ [0, 2 ] gives a 2nd order system with real coefficients. i.e: −1 2πk H(k) H(N−k) 2|H(k)|[cos θ(k)−z cos (θ(k)− N )] Hk(z) = + = j2πk j2π(N−k) 1−2 cos 2πk z−1+z−2 1−e N z−1 1−e N z−1 N Note that for N odd there is no frequency sample for k = N/2 thus the corresponding term does not exist.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Sampling Method: Design Procedure

jω Given desired frequency response HDes(e ) sample it to yield:

jΩ H(k) = HDes(e )| 2πk , k ∈ [0,N − 1] Ω= N Impose the following conditions on the magnitude |H(k)| and phase θ(k):

(N−1)kπ 1 For linear phase: θ(k) = − N , k ∈ [0,N − 1] 2 For real coefficients: |H(k)| = |H(N − k)| and θ(k) = −θ(N − k)

N Note for N even set H( 2 ) = 0. Example: Design an N = 11 order low-pass FIR filter whose cut-off frequency fc = 2fs/11, where fs is the sampling frequency. Plot the magnitude response of the designed filter. jΩ We start with ideal filter for HDes(e ) and sample it with spacing between samples= Ωs fs 2πN = N . See below figure.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Sampling Method: Design Procedure

We then impose the above conditions i.e.

|H(k)| = |H(N − k)| and

(N−1)kπ 10kπ θ(k) = − N = 11 , k ∈ [0, 10] These combined yield,

 −j 10kπ e 11 k = 0, 1, 2 and k = 9, 10 H(k) = 0 k ∈ [3, 8]

Then take size N = 11 IDFT of H(k) i.e. h(n) = IDFT {H(k)}11 which gives h(0) = 0.06942, h(1) = −0.05403, h(2) = −0.10945, h(3) = 0.04733, h(4) = 0.31938, h(5) = 0.45455, h(6) = 0.31938, h(7) = 0.04733, h(8) = −0.10945, h(9) = −0.05403, h(10) = 0.06942

Note that these are symmetric due to the linear phase condition imposed. Magnitude response of the designed filter is shown (thick line) which exhibits a rather large ripple in both passband and stopband. To reduce the ripple effect, one can add a sample in the transition (wider transition region) region, i.e.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Frequency Sampling Method: Design Procedure

 −j 10kπ  e 11 k = 0, 1, 2 and k = 9, 10 −j 10kπ H(k) = 0.5e 11 k = 3 and k = 8  0 k ∈ [4, 7]

The resulting filter coefficients are: h(0) = 0.00987, h(1) = 0.02244, h(2) = −0.07168, h(3) = −0.03989, h(4) = 0.30643, h(5) = 0.54545, h(6) = 0.30643, h(7) = −0.03989, h(8) = −0.07168, h(9) = 0.02244, h(10) = 0.00987

The magnitude response is shown (thin line) which shows much less ripple effects at a cost of wider transition region (must increase the order). Note that one can try to optimize the choice of the amplitude of the introduced sample.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Design of Digital Controller-Classical method

Goal: Design compensators to achieve certain desired characteristics e.g., steady-state accuracy, transient response, relative stability, sensitivity, etc.

1 Steady-State Accuracy: Desired ess ≈ 0 =⇒ poles at z = 1 =⇒ more lags =⇒ less stable

2 Transient Response: Desired: Reduce tr =⇒ increase BW =⇒ less noise immunity

3 Relative Stability: Desired: Small Mp =⇒ increase in tr, slower response

4 Sensitivity: Variation of system parameters wrt change in temperature, humidity, aging, altitude, etc. T ∂T a G(z) Measured by Sα = ∂α . T where T (z) = 1+G(z) and α is a system parameter, e.g.,

T 1 T 1 SG = 1+G(z) or in frequency domain SG = 1+G(ejΩ) which implies,

T jΩ Reduce sensitivity SG =⇒ Increase open loop gain G(e ) =⇒ Instability problems.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Digital PID Controller

Recall from ECE 411, for PID controller:

Gc(s) = KP + KI /s + KDs

where KP : proportional gain, KI integrator gain, and KD derivative gain. Though bilinear z-mapping can be used for the integrator: T (z+1) 1/s → 2 z−1) it cannot be used for the derivative part. But we can use backward difference method: dx(t) x(t)−x(t−∆T ) y(t) = dt ≈ ∆T , ∆T = 1, t = nT x(n)−x(n−1) (X(z)−z−1X(z)) Y (z) (z−1) y(n) = T =⇒ Y (z) = T =⇒ X(z) = zT (z−1) Thus, the mapping is s → T z which yields digital PID transfer function: 2 T (z+1) (z−1) a0z +a1z+a2 Gc(z) = KP + KI 2 (z−1) + KD T z = z(z−1) : Second order IIR filter

where a0 = KP + KI T/2 + KD/T , a1 = −KP + KI T/2 − 2KD/T , a2 = KD/T , b1 = −1, and b2 = 0

Design of PID controllers involves finding KP , KI , and KD to meet the desired performance criteria.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Digital PID Controller-Cont.

10 Example: Given plant transfer function, Gp(s) = (s+1)(s+2) , design a PID controller D(z) to meet desired specs.

Loop transfer function is,

−1 h 10 i 0.0453(z+0.904) G(z) = D(z)(1 − z )Z s(s+1)(s+2) = D(z) (z−0.905)(z−0.819) First consider the uncompensated case, D(z) = 1, then closed loop transfer function is:

C(z) G(z) 0.0453(z+0.904) T (z) = R(z) = 1+G(z) = z2−1.679−0.782 The CE is, 2 ρ(z) = z − 1.68z + 0.78 = 0 =⇒ z1,2 = 0.84 ± j0.28

Hence |z1,2| ≈ 0.885 < 1 =⇒ i.e. stable However, since the loop transfer function doesn’t have any pole at z = 1, steady-state error is not zero.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Digital PID Controller-Cont.

−1 0.0453(z+0.904) css = lim(1 − z )C(z) = lim 2 = 0.84 z→1 z→1 z −1.679−0.782

Thus, ess = 1 − 0.84 = 0.16. The step response is shown below which reveals this fact.

For ess = 0 we then use an integral controller,

T (z+1) (KI T +2KP )z+(KI T −2KP ) D(z) = KP + KI 2 (z−1) = (z−1) Then, the loop transfer function becomes, KI T −2KP (2KP +KI T )(z+ )(z+0.094) 0.0453(z+0.904) KI T +2Kp G(z) = D(z) (z−0.905)(z−0.819)(z−1) = (z−1)(z−0.905)(z−0.819)

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Digital PID Controller-Cont.

Clearly, ess = 0 because of pole at z = 1. To simplify the design, we choose KI and KP to cancel pole at z = 0.905 (near unit circle) KI −2KP = −0.905 =⇒ KP = 1.0026 KI T +2KP KI

Now, choose KP = 1 =⇒ KI = 0.997 1.05(z−0.905) D(z) = (z−1) The loop transfer function with PI controller: 0.0453(z+0.904) G(z) = (z−1)(z−0.819) Step response for three different values of KP and hence KI are shown. As can be seen the response either has a high Max overshoot or long rise time.

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Digital PID Controller-Cont.

We can achieve both goals while ess = 0 using a PID controller, 2 a0z +a1z+a2 D(z) = z(z−1)

The PID parameters KP ,KI ,KD must be determined to satisfy certain desired specs. First, we choose to cancel both poles of uncompensated system with those of PID. Additionally, we add another requirement that ramp error constant

Kv = 5 =⇒ ess = 1/Kv = 1/5 = 0.2. 1 −1 Kv = lim(1 − z )G(z) = 5KI =⇒ KI = 1 T z→1 2 a0z + a1z + a2 = (z − 0.905)(z − 0.819)  a = K + K T + KD K = 1.45  0 P I 2 T P T 2KD a1 = KI 2 − KP − T =⇒ KD = 0.43  KD K = 1 a2 = T I The open loop and closed-loop transfer functions are, 0.263(z+0.904) G(z) = z(z−1)

0.263(z+0.904) T (z) = z2−0.737z+0.238

M.R. Azimi Digital Control & Digital Filters Non-Recursive Digital Filter Design Digital Controller Design Digital PID Controller-Cont.

For this system CE is, 2 ρ(z) = z − 0.737z + 0.238 = 0 =⇒ z1,2 = 0.37 ± j0.32

Hence |z1,2| ≈ 0.48 < 1 =⇒ i.e. much closer to the origin of the unit circle. The step response is shown which has a max overshoot of 4% while offering a good rise time.

M.R. Azimi Digital Control & Digital Filters