Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter

Signal processing: numerical filtering

Matthieu Kowalski

Univ Paris-Sud L2S (GPI)

Matthieu Kowalski : numerical filtering 1 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter

1 Introduction

2 Ideal Filtering Definitions Ideal filters

3 Numerical filtering : Z transform

4 Finite Impulse Response Filters (FIR) Definition FIR filter synthesis

5 Infinite Impulse Response Filter (IIR) General method

6 Choice of the numerical filter Specifications Classical filters

Matthieu Kowalski Signal processing: numerical filtering 2 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Plan

2 Ideal Filtering Definitions Ideal filters

Matthieu Kowalski Signal processing: numerical filtering 3 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Filtering

Definition A filter is a linear time invariant system. It can be written as a .

Impulse response Let S a filter. The impulse response h of S is the system output to the unit impulse (Dirac). Hence h = S(δ)

Analogical signals. For all signal x

Z +∞ y = S(x) = h ? x = x ? h y(t) = h(u)x(t − u) du −∞ Numerical signals. For all signal x

+∞ X y = S(x) = h ? x = x ? h yn = hk xn−k k=−∞

For finite signals, the convolution is circular : the signals are periodic with the same period. Matthieu Kowalski Signal processing: numerical filtering 4 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Realizable filters – 1

Realizable filter A filter with impulse respons h is realizable iff it is stable and causal.

Remark 1 If a filter is stable, then it admits a Fourier transform. Reciprocally, if a filter admit an invertible Fourier transform, then it is stable. If a filter admits an invertible Fourier transform, it can be non causal (and then non realizable).

Matthieu Kowalski Signal processing: numerical filtering 5 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Realizable filters – 2

Stable filters A filter with an impulse response h is stable iff

+∞ X = |hk | < +∞ k=−∞

Causal filter A filter with an impulse response h is causal iff h is causal, ie

hk = 0 ∀k < 0

Realizable filter A filter with an impulse response h is causal iff h is realizable iff it is stable and caucal.

Matthieu Kowalski Signal processing: numerical filtering 6 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Filtering and Fourier transform

Frequency response or complex Gain The frequency response, or complex gain, of a filter is its Fourier transform (when it exists).

Filtering in the frequency domain Let S a filter with an impulse response h and x a signal. One has

y = S(x) = h ? x

if h and x admit a Fourier transform, we have in the frequency domain

yˆ = hˆ · xˆ

Filtering a signal acts directly on its spectrum

Matthieu Kowalski Signal processing: numerical filtering 7 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Plan

2 Ideal Filtering Definitions Ideal filters

Matthieu Kowalski Signal processing: numerical filtering 8 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal low pass filter – 1

Definition

The frequency response of an ideal low pass filter with cutting frequency ν0 is given by : ( pb 1 si |ν| < ν0 hˆ(ν) ν0 = 0 sinon

Frequency response

1

0.8

0.6

0.4 Amplitude

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Frequence (Hz)

Matthieu Kowalski Signal processing: numerical filtering 9 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal low pass filter – 2

Impulse response

pb sin(2πν n) h ν0 = 0 n πn

Impulse response

0.2

0.15

0.1

0.05 Amplitude

0

-0.05 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Temps (s)

Matthieu Kowalski Signal processing: numerical filtering 10 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal low pass filter – 2

1 ν pb Z 2 Z 0 ν0 i2πnν i2πnν hn = hˆ(ν)e dν = e dν 1 − 2 −ν0  1 ν0 = ei2πnν i2πn −ν0 ei2πnν0 − e−i2πnν0 = i2πn sin(2πν n) = 0 πn

Impulse response

0.2

0.15

0.1

0.05 Amplitude

0

-0.05 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Temps (s)

Matthieu Kowalski Signal processing: numerical filtering 11 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal high pass filter – 1

Definition

The frequency response of an ideal high pass filter with cutting frequency ν0 is given by : ( ph 0 si |ν| < ν0 hˆ(ν) ν0 = 1 sinon pb = 1 − hˆ(ν) ν0

Frequency response

1

0.8

0.6

0.4 Amplitude

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Frequence (Hz)

Matthieu Kowalski Signal processing: numerical filtering 12 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal high pass filter – 2

Impulse response

ph ν0 h0 = 0 ph pb sin(2πν n) h ν0 = −h ν0 = − 0 n 6= 0 n k πn

Impulse response

0.3

0.25

0.2

0.15

0.1

Amplitude 0.05

0

-0.05

-0.1 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Temps

Matthieu Kowalski Signal processing: numerical filtering 13 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal band pass filter – 1

Definition

The frequency response of an ideal high pass filter with cutting frequencies ν0 and ν1 is given by :  1 si ν < ν < ν  0 1 pbandeν ;ν hˆ(ν) 0 1 = 1 si − ν0 < −ν < −ν1 0 sinon pb pb = hˆ(ν) ν1 − hˆ(ν) ν0

Frequency response

1

0.8

0.6

0.4 Amplitude

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Frequence (Hz)

Matthieu Kowalski Signal processing: numerical filtering 14 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal band pass filter – 2

Impulse response

pbande pb pb sin(2πν n) sin(2πν n) h ν0;ν1 = h ν1 − h ν0 = 1 − 0 k k k πn πn

Impulse response

0.3

0.2

0.1

0 Amplitude -0.1

-0.2

-0.3 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Temps (s)

Matthieu Kowalski Signal processing: numerical filtering 15 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal band cut pass filter – 1

Definition

The frequency response of an ideal high pass filter with cutting frequencies ν0 and ν1 is given by :  0 si ν < ν < ν  0 1 cbandeν ;ν hˆ(ν) 0 1 = 0 si − ν0 < −ν < −ν1 1 sinon pbande = 1 − hˆ(ν) ν0;ν1 pb pb = 1 − hˆ(ν) ν1 + hˆ(ν) ν0

Frequency response

1

0.8

0.6

0.4 Amplitude

0.2

0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Frequence (Hz)

Matthieu Kowalski Signal processing: numerical filtering 16 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definitions Ideal filters Ideal band cut pass filter – 2

Impulse response

pbande cbandeν0;ν1 ν0;ν1 hk = 1 − hk pb pb ν0 ν1 = 1 − hk + hk sin(2πν n) sin(2πν n) = 1 − 1 + 0 πn πn

Impulse response

1.3

1.2

1.1

1

0.9 Amplitude 0.8

0.7

0.6 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 Temps (s)

Matthieu Kowalski Signal processing: numerical filtering 17 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Z-transform : definition

z transform

Let s = {sn}n∈Z be a numerical signal (i.e. a sequence). The z transform of s is the series +∞ X −n S(z) = snz , z ∈ C n=−∞

defined in a crown of convergence r1 < |z| < r2.

Matthieu Kowalski Signal processing: numerical filtering 18 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Reminder on integer series

convergence radius ∞ P n The convergence radius ρ of the integer series z 7→ anz is given by n=0

( ∞ ) X n ρ = sup |z|, z ∈ C anz converge n=0

Lemma ∞ P n The convergence radius ρ of the integer series z 7→ anz is given by n=0

1 1/n = lim sup |an| ρ n→∞

Matthieu Kowalski Signal processing: numerical filtering 19 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter z-transform and causality

Theorem : causality and disk of convergency A signal s is causal if its z transform is defined at the exterior of a disk of radius r1, ie if r2 = +∞. Likewise, s is anti-causal if r1 = 0, ie. if S(z) is defined at the interior of a disk of radius r2.

Matthieu Kowalski Signal processing: numerical filtering 20 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Properties

Let x a numerical signal and Z(xn) = X (z) its z transform. The z transform is linear −k Translation : Z(xn−k ) = z X (z) n z Scaling change Z(a xn) = X ( a ) k d k Derivation : Z(n xn)) = −z dz X (z) Convolution : Z(u ∗ v)(z) = U(z)V (z) Link with the Discrete Time Fourier transform :u ˆ(ν) = U(ei2πν ) only if r1 < 1 < r2 ! Otherwise the TFD is not defined.

Matthieu Kowalski Signal processing: numerical filtering 21 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Usual transform

Table: Usual z transform

xn X (z) R

δn 1 C 1 Hn 1−z−1 |z| > 1 z−1 nHn (1−z−1)2 |z| > 1 n 1 a Hn 1−az−1 |z| > |a| n az−1 na Hn (1−az−1)2 |z| > |a| n 1 −a H−n−1 1−az−1 |z| < |a| n az−1 −na H−n−1 (1−az−1)2 |z| < |a| −1 1−z cos(ω0) cos(ω0n)Hn −1 −2 |z| > 1 1−2z cos(ω0)+z −1 1−z sin(ω0) sin(ω0n)Hn −1 −2 |z| > 1 1−2z cos(ω0)+z −1 n 1−az cos(ω0) a cos(ω0n)Hn −1 2 −2 |z| > |a| 1−2az cos(ω0)+a z −1 n 1−az sin(ω0) a sin(ω0n)Hn −1 2 −2 |z| > |a| 1−2az cos(ω0)+a z

Matthieu Kowalski Signal processing: numerical filtering 22 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Transfer function

Let S be a discrete filter with an impulse response h. X y[k] = S(x)[k] = h ? x[k] = x[k − n]h[n] n

Transfer function The transfer function of a numerical filter is the z transform of its impulse response. For a filter with impulse response h, we denote its transfer function by H(z).

Frequency response or complex gain It is the restriction of the transfer function to the unit circle. It corresponds to the Fourier transform of the impulse response (when it exists). We denote it by G(ν) = hˆ(ν).

Matthieu Kowalski Signal processing: numerical filtering 23 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Plan

4 Finite Impulse Response Filters (FIR) Definition FIR filter synthesis

Matthieu Kowalski Signal processing: numerical filtering 24 / 50 Remarks A FIR filter is necessary stable. It is not necessary causal. A FIR filter is realizable iff it is causal.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis FIR filter (or MA filter)

Definition Let a filter with an impulse response h. The filter is said to be with a ”Finite impulse response” (FIR) or ”mooving average” (MA) if h is finite :

h = {h−k1 ,..., h0,..., hk2 } The filtering equation can then be written :

k X2 yn = hk xn−k

k=−k1 The order of the filter is the number of samples of its impulse response.

Matthieu Kowalski Signal processing: numerical filtering 25 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis FIR filter (or MA filter)

Definition Let a filter with an impulse response h. The filter is said to be with a ”Finite impulse response” (FIR) or ”mooving average” (MA) if h is finite :

h = {h−k1 ,..., h0,..., hk2 } The filtering equation can then be written :

k X2 yn = hk xn−k

k=−k1 The order of the filter is the number of samples of its impulse response.

Remarks A FIR filter is necessary stable. It is not necessary causal. A FIR filter is realizable iff it is causal.

Matthieu Kowalski Signal processing: numerical filtering 26 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Plan

4 Finite Impulse Response Filters (FIR) Definition FIR filter synthesis

Matthieu Kowalski Signal processing: numerical filtering 27 / 50 ideal 2 Truncation of the impulse response h

tronc ideal ideal h = {h−N/2,..., hN/2 }

tronc 3 Apply a delay on h , in order to shift indices and get a causal filter

RIF tronc hn = hn−N/2

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Truncation method

Let an ideal filter with an impulse response hideal (unknown) defined thanks to its transfer function Hideal. It can be approximated by a realizable FIR filter of order N + 1 by the following : ideal 1 Compute the impulse response h by Fourier inversion :

Z 1/2 ideal i2πnν hn = H(ν)e dν −1/2

Matthieu Kowalski Signal processing: numerical filtering 28 / 50 tronc 3 Apply a delay on h , in order to shift indices and get a causal filter

RIF tronc hn = hn−N/2

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Truncation method

Let an ideal filter with an impulse response hideal (unknown) defined thanks to its transfer function Hideal. It can be approximated by a realizable FIR filter of order N + 1 by the following : ideal 1 Compute the impulse response h by Fourier inversion :

Z 1/2 ideal i2πnν hn = H(ν)e dν −1/2

ideal 2 Truncation of the impulse response h

tronc ideal ideal h = {h−N/2,..., hN/2 }

Matthieu Kowalski Signal processing: numerical filtering 29 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Truncation method

Let an ideal filter with an impulse response hideal (unknown) defined thanks to its transfer function Hideal. It can be approximated by a realizable FIR filter of order N + 1 by the following : ideal 1 Compute the impulse response h by Fourier inversion :

Z 1/2 ideal i2πnν hn = H(ν)e dν −1/2

ideal 2 Truncation of the impulse response h

tronc ideal ideal h = {h−N/2,..., hN/2 }

tronc 3 Apply a delay on h , in order to shift indices and get a causal filter

RIF tronc hn = hn−N/2

Matthieu Kowalski Signal processing: numerical filtering 30 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Gibbs phenomenon

Shortcoming of the previous approach The truncation (i.e. the multiplication by a rectangular window) make appears a Gibbs phenomenon.

Phénomène de Gibbs

1

0.5 Fonction de transfert originale

Amplification Ordre: 100 Ordre: 1000 Ordre: 50 0 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 Fréquence (Hz) ×104

Matthieu Kowalski Signal processing: numerical filtering 31 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Windowing – 1

Solution Apply a ”smooth” window to avoid hard truncation, responsible of the Gibbs phenomenon.

Some windows Bartlett (or triangular)

 2 N−1  N−1 0 ≤ n ≤ 2  2n N−1 w(n) = 2 − N−1 2 ≤ n ≤ N − 1 0 sinon

Hann (   0.5 − 0.5 cos 2πn 0 ≤ n ≤ N − 1 w(n) = N−1 0 sinon

Matthieu Kowalski Signal processing: numerical filtering 32 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Windowing – 2

Some windows Hamming (   0.54 − 0.46 cos 2πn 0 ≤ n ≤ N − 1 w(n) = N−1 0 sinon

Blackman (     0.42 − 0.5 cos 2πn + 0.08 cos 4πn 0 ≤ n ≤ N − 1 w(n) = N−1 N−1 0 sinon

Matthieu Kowalski Signal processing: numerical filtering 33 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Windowing – 3

1 Rectangle Bartlett 0.8 Hann Hamming 0.6 Blackman

0.4 Amplitude 0.2

0 0 10 20 30 40 50 60 70 Echantillons Popular windows, temporal representation.

Matthieu Kowalski Signal processing: numerical filtering 34 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Windowing – 4

Bartlett Hann Rectangle 0 0 0

-20 -20 -20

-40 -40 -40

-60 -60 -60 Gain (dB) Gain (dB) Gain (dB)

-80 -80 -80

-100 -100 -100 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 Fréquences Fréquences Fréquences Hamming 0 Blackman 0 -20 -50 -40

-100 -60 Gain (dB) Gain (dB)

-80 -150

-100 -200 0 1 2 3 4 5 6 7 8 0 2 4 6 8 10 12 14 16 Fréquences Fréquences Popular windows, frequency representation.

Matthieu Kowalski Signal processing: numerical filtering 35 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis Windowing – 5

main characteristics Width of the main lobe. Amplitude ratio between the main lobe and the secondary lobe. Minimal attenuation in the attenuation band. Window Width of the main Amplitude ratio Minimal attenua- lobe tion Rectangular 4π/N -13 dB -21 dB Bartlett 8π/N -25 dB -25 dB Hann 8π/N -31 dB -44 dB Hamming 8π/N -41 dB -53 dB Blackman 12π/N -57 dB -74 dB

Matthieu Kowalski Signal processing: numerical filtering 36 / 50 ideal 2 Windowing of the impulse response h

win ideal ideal h = w ·{h−N/2,..., hN/2 }

win 3 Apply a delay on h , in order to shift indices and get a causal filter

RIF win hn = hn−N/2

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis FIR synthesis by windowing

ideal 1 Compute the impulse response h by Fourier inversion :

Z 1/2 ideal i2πnν hn = H(ν)e dν −1/2

Matthieu Kowalski Signal processing: numerical filtering 37 / 50 win 3 Apply a delay on h , in order to shift indices and get a causal filter

RIF win hn = hn−N/2

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis FIR synthesis by windowing

ideal 1 Compute the impulse response h by Fourier inversion :

Z 1/2 ideal i2πnν hn = H(ν)e dν −1/2

ideal 2 Windowing of the impulse response h

win ideal ideal h = w ·{h−N/2,..., hN/2 }

Matthieu Kowalski Signal processing: numerical filtering 38 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Definition FIR filter synthesis FIR synthesis by windowing

ideal 1 Compute the impulse response h by Fourier inversion :

Z 1/2 ideal i2πnν hn = H(ν)e dν −1/2

ideal 2 Windowing of the impulse response h

win ideal ideal h = w ·{h−N/2,..., hN/2 }

win 3 Apply a delay on h , in order to shift indices and get a causal filter

RIF win hn = hn−N/2

Matthieu Kowalski Signal processing: numerical filtering 39 / 50 1 The coefficients decrease in n . For an error of 10−6, we need one million coefficients ! Ten billion of operations per second to process a speech signal sampled at 10 kHz.

Low pass example sin(2πξ n) hideal = 0 . n πn

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method FIR approach analysis

Let an approximation of an ideal filter by a FIR filter

+∞ K−1 X X yn = hk xn−k ' hk xn−k . k=−∞ k=0

Matthieu Kowalski Signal processing: numerical filtering 40 / 50 1 The coefficients decrease in n . For an error of 10−6, we need one million coefficients ! Ten billion of operations per second to process a speech signal sampled at 10 kHz.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method FIR approach analysis

Let an approximation of an ideal filter by a FIR filter

+∞ K−1 X X yn = hk xn−k ' hk xn−k . k=−∞ k=0

Low pass example sin(2πξ n) hideal = 0 . n πn

Matthieu Kowalski Signal processing: numerical filtering 41 / 50 For an error of 10−6, we need one million coefficients ! Ten billion of operations per second to process a speech signal sampled at 10 kHz.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method FIR approach analysis

Let an approximation of an ideal filter by a FIR filter

+∞ K−1 X X yn = hk xn−k ' hk xn−k . k=−∞ k=0

Low pass example sin(2πξ n) hideal = 0 . n πn

1 The coefficients decrease in n .

Matthieu Kowalski Signal processing: numerical filtering 42 / 50 Ten billion of operations per second to process a speech signal sampled at 10 kHz.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method FIR approach analysis

Let an approximation of an ideal filter by a FIR filter

+∞ K−1 X X yn = hk xn−k ' hk xn−k . k=−∞ k=0

Low pass example sin(2πξ n) hideal = 0 . n πn

1 The coefficients decrease in n . For an error of 10−6, we need one million coefficients !

Matthieu Kowalski Signal processing: numerical filtering 43 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method FIR approach analysis

Let an approximation of an ideal filter by a FIR filter

+∞ K−1 X X yn = hk xn−k ' hk xn−k . k=−∞ k=0

Low pass example sin(2πξ n) hideal = 0 . n πn

1 The coefficients decrease in n . For an error of 10−6, we need one million coefficients ! Ten billion of operations per second to process a speech signal sampled at 10 kHz.

Matthieu Kowalski Signal processing: numerical filtering 44 / 50 The output coefficient yn depends of the previous (already computed) ones !

The coefficient yn is obtained by filtering of xm with m ≤ n et filtering of ym with m ≤ n by using two FIR filters of impulse response {b0,..., bM } and {a1,..., aN }. If this equation has a unique solution, then it is a recursive filter. We suppose that M ≤ N. N is the order of the filter.

We look for y like : M N X X yn = bk xn−k − ak yn−k k=0 k=1

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive Filters

Idea : use recursive filters !

Matthieu Kowalski Signal processing: numerical filtering 45 / 50 The output coefficient yn depends of the previous (already computed) ones !

The coefficient yn is obtained by filtering of xm with m ≤ n et filtering of ym with m ≤ n by using two FIR filters of impulse response {b0,..., bM } and {a1,..., aN }. If this equation has a unique solution, then it is a recursive filter. We suppose that M ≤ N. N is the order of the filter.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive Filters

Idea : use recursive filters !

We look for y like : M N X X yn = bk xn−k − ak yn−k k=0 k=1

Matthieu Kowalski Signal processing: numerical filtering 46 / 50 The coefficient yn is obtained by filtering of xm with m ≤ n et filtering of ym with m ≤ n by using two FIR filters of impulse response {b0,..., bM } and {a1,..., aN }. If this equation has a unique solution, then it is a recursive filter. We suppose that M ≤ N. N is the order of the filter.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive Filters

Idea : use recursive filters !

We look for y like : M N X X yn = bk xn−k − ak yn−k k=0 k=1

The output coefficient yn depends of the previous (already computed) ones !

Matthieu Kowalski Signal processing: numerical filtering 47 / 50 If this equation has a unique solution, then it is a recursive filter. We suppose that M ≤ N. N is the order of the filter.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive Filters

Idea : use recursive filters !

We look for y like : M N X X yn = bk xn−k − ak yn−k k=0 k=1

The output coefficient yn depends of the previous (already computed) ones !

The coefficient yn is obtained by filtering of xm with m ≤ n et filtering of ym with m ≤ n by using two FIR filters of impulse response {b0,..., bM } and {a1,..., aN }.

Matthieu Kowalski Signal processing: numerical filtering 48 / 50 We suppose that M ≤ N. N is the order of the filter.

Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive Filters

Idea : use recursive filters !

We look for y like : M N X X yn = bk xn−k − ak yn−k k=0 k=1

The output coefficient yn depends of the previous (already computed) ones !

The coefficient yn is obtained by filtering of xm with m ≤ n et filtering of ym with m ≤ n by using two FIR filters of impulse response {b0,..., bM } and {a1,..., aN }. If this equation has a unique solution, then it is a recursive filter.

Matthieu Kowalski Signal processing: numerical filtering 49 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive Filters

Idea : use recursive filters !

We look for y like : M N X X yn = bk xn−k − ak yn−k k=0 k=1

The output coefficient yn depends of the previous (already computed) ones !

The coefficient yn is obtained by filtering of xm with m ≤ n et filtering of ym with m ≤ n by using two FIR filters of impulse response {b0,..., bM } and {a1,..., aN }. If this equation has a unique solution, then it is a recursive filter. We suppose that M ≤ N. N is the order of the filter.

Matthieu Kowalski Signal processing: numerical filtering 50 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive filters. Analyze

M N X X yn = bk xn−k − ak yn−k k=0 k=1 N M X X ⇔ ak yn−k = bk xn−k k=0 k=0 After z transform :

N ! M ! X −k X −k Y (z) ak z = X (z) bk z ⇔ V (z) = H(z)U(z) . k=0 k=0 with PM b z−k H(z) = k=0 k . PN −k k=0 ak z

The transfer function is a rational fraction. The filter exists iff the denominator never vanish.

Matthieu Kowalski Signal processing: numerical filtering 51 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Recursive filter : AR vs ARMA

Autoregressive filter (AR) 1 H(z) = . PN −k k=0 ak z N X yn = xn − ak yn−k k=1

Autoregressive Mouving Average filter (ARMA)

PM b z−k H(z) = k=0 k . PN −k k=0 ak z M N X X yn = bk xn−k − ak yn−k k=0 k=1

Matthieu Kowalski Signal processing: numerical filtering 52 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Realizable ARMA Filters

Causality A filter is causal iff H is defined for all |z| > r

Stability A filter is stable iff H is defined for all |z| = 1.

An ARMA filter is stable iff its poles zd are such that |zd |= 6 1

Realizable ARMA filters An ARMA filter is realizable iff H is defined for all |z| > r with r < 1.

Matthieu Kowalski Signal processing: numerical filtering 53 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Plan

5 Infinite Impulse Response Filter (IIR) General method

Matthieu Kowalski Signal processing: numerical filtering 54 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter General method Main steps

Define a template of an analogical filter Approximate this template by the transfer function of a given family of filters (Butterworth, Tchebychev, . . . ) Translate the analogical transfer function to a numerical transfer function

Matthieu Kowalski Signal processing: numerical filtering 55 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Plan

6 Choice of the numerical filter Specifications Classical filters

Matthieu Kowalski Signal processing: numerical filtering 56 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Specification

General specification Choice of the type : low pass, high pass, band pass, cut band . . . Choice of the template

Particular Specifications

Bandwidth [fp−, fp+]

Attenuated band [0, fa−][fa+, 0.5]

Ripple in the bandwidth ε1

Ripple in the attenuation band ε2

Matthieu Kowalski Signal processing: numerical filtering 57 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Specification

Particular Specifications

Bandwidth [fp−, fp+]

Attenuated band [0, fa−][fa+, 0.5]

Ripple in the bandwidth ε1

Ripple in the attenuation band ε2

Matthieu Kowalski Signal processing: numerical filtering 58 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Plan

6 Choice of the numerical filter Specifications Classical filters

Matthieu Kowalski Signal processing: numerical filtering 59 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters 3 main families

Butterworth Tchebychev I and II Elliptical (+ Bessel)

Matthieu Kowalski Signal processing: numerical filtering 60 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Butterworth

Main characteristics Transfert function Cutting frequency fc 1 |H(f )|2 = Order N  2N 1 + f fc Monotonicity of the Modulus of the transfer function

1.2

1

0.8

0.6

0.4

0.2

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fréquences

Matthieu Kowalski Signal processing: numerical filtering 61 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Tchebychev I

Transfert function Main characteristics Bandwidth fp 2 1 |H(f )| =   2 2 f Ripple in the en Bandwidth ε 1 + ε TN f p Order N with T Tchebychev polynomial of N Monotonicity in the degree N attenuation band

1.2

1

0.8

0.6

0.4

0.2

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fréquences

Matthieu Kowalski Signal processing: numerical filtering 62 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Tchebychev II

Transfert function Main characteristics

Attenuated band fs 1 |H(f )|2 = 1 − Monotonicity in the bandwidth 1 + ε2T 2 fs  N f Ripple in the attenuation band

with TN a Tchebychev polynomial ε if degree N Order N

1.2

1

0.8

0.6

0.4

0.2

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fréquences

Matthieu Kowalski Signal processing: numerical filtering 63 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters Elliptics

Main characteristics Transfert function Bandwidth fp 1 Attenuation band fs |H(f )|2 = 1 −   Ripple in the bandwidth and in 2 2 f 1 + ε RN √ fp fs the attenuation band ε Order N

1

0.8

0.6

0.4

0.2

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Fréquences

Matthieu Kowalski Signal processing: numerical filtering 64 / 50 Introduction Ideal Filtering Numerical filtering : Z transform Finite Impulse Response Filters (FIR) Infinite Impulse Response Filter (IIR) Choice of the numerical filter Specifications Classical filters FIR or IIR ?

Properties of the FIR filters Slow transition between the bandwidth and the attenuation band Simplicity if the synthesis Stability Easy to implement

Properties of the IIR filters Fast transition between the bandwidth and the attenuation band Synthesis from an analogical filter Can be unstable

Matthieu Kowalski Signal processing: numerical filtering 65 / 50