54
PEMP ESD2521 M.S. Ramaiah School of Advanced Studies, Bengaluru Session 3:Time-Domain Filtering Session delivered by: Chandan N. 1

Session 3 DSP Intro

Embed Size (px)

DESCRIPTION

DSP introd

Citation preview

Page 1: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Session 3:Time-Domain Filtering

Session delivered by:

Chandan N.

1

Page 2: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Session Objectives • To discuss several noise reduction examples and experiments to

introduce important time-domain techniques for processing digital signals and analyzing simple DSP systems.

• To understand the fundamental time-domain DSP concepts which is helpful and more interesting to examine real-world DSP applications with the help of interactive MATLAB tools

• To understand the concepts of FIR and IIR filter

2

Page 3: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

• Introduction to Digital systems • Moving-Average Filters • Digital Filters • Realization of FIR Filters • Nonlinear Filters • Examples • Introduction to FIR and IIR • Structures for FIR Systems • Structures for IIR Systems

Session Topics

3

Page 4: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Introduction

• A DSP system (or algorithm) performs operations on digital signals to achieve predetermined objectives.

• In some applications, the single-input, single-output DSP system processes an input signal x(n) to produce an output signal y(n).

• The general relationship between x(n) and y(n) is described as y(n) = F [x(n)],

where F denotes the function of the digital system.

Figure : General block diagram of digital system

4

Page 5: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Introduction

• DSP system consists of the interconnection of adders, multipliers, and delay units.

• A digital filter alters the spectral content of input signals in a specified manner.

• Common filtering objectives include removing noises, improving signal quality, extracting information from signals, and separating signal components that have been previously combined.

• A digital filter is a mathematical algorithm that can be implemented in digital hardware and software and operates on a digital input signal for achieving filtering objectives.

• A digital filter can be classified as being linear or nonlinear, time invariant or time varying.

5

Page 6: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

• To process signals, we have to design and implement systems called filters.

• The filter design issue is influenced by such factors as

• The type of the filter: IIR or FIR

• The form of its implementation: structures

• Different filter structures dictate different design strategies.

Introduction

6

Page 7: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

• Since our filters are LTI systems, we need the following three elements to describe digital filter structures. – Adder – Multiplier (Gain) – Delay element (shift or memory)

x1(n)

x2(n)

x1(n)+x2(n) x(n) ax(n)a

x(n) x(n-1)1/z

Introduction

7

Page 8: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

1;1)(

)()( 011

110

0

0 =++++++

=== −−

−−

=

=

∑a

zazazbzbb

za

zb

zAzBzH N

N

MM

N

n

nn

M

n

nn

The system function of an IIR filter is given by

The difference equation representation of an IIR filter is expressed as

∑ ∑= =

−−−=M

m

N

mmm mnyamnxbny

0 1)()()(

Structures for IIR Systems

8

Page 9: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Three different structures can be used to implement an IIR filter: Direct Form:

In this form, there are two parts to this filter, the moving average part and the recursive part (or the numerator and denominator parts)

Two version: direct form I and direct form II Cascade Form:

The system function H(z) is factored into smaller second-order sections, called biquads. H(z) is then represented as a product of these biquads.

Each biquad is implemented in a direct form, and the entire system function is implemented as a cascade of biquad sections.

Parallel Form: H(z) is represented as a sum of smaller second-order sections. Each section is again implemented in a direct form. The entire system function is implemented as a parallel network of sections.

Structures for IIR Systems

9

Page 10: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Direct Form I Structure:

Consists of the zeros of H(z) Consists of the poles of H(z)

∑ ∑ = =

− − − = M

k

N

k k k k n y a k n x b n y

0 1 ) ( ) ( ) (

Structures for IIR Systems

10

Page 11: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Direct Form I Structure:

Structures for IIR Systems

11

Page 12: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

)2()1()2()1()()( 21210 −−−−−+−+= nyanyanxbnxbnxbny

Direct Form I Structure:

As the name suggests, the difference equation is implemented as given using delays, multipliers, and adders.

For the purpose of illustration, Let M = N = 2,

x( n) y( n)b0

b1

b2

- a1

- a2

1/ z

1/ z

1/ z

1/ z

H1( z) H2( z)

Direct Form I structure

Structures for IIR Systems

12

Page 13: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

)1()()1()( 101 −++−−= nxbnxbnyany

Given a LTI system with a rational transfer function H(z)

11

110

1)( −

−+

=zazbbzH

Direct Form I structure

Structures for IIR Systems

13

Page 14: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

We can implement the system with the following pair of coupled difference equations: )1()()(

)()1()(

10

1

−+=+−−=

nwbnwbnynxnwanw

The commutative law of the convolution

Structures for IIR Systems

14

Page 15: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Direct Form II Structure:

Structures for IIR Systems

15

Page 16: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Direct Form II Structure: x( n) y( n)

H1( z)

- a1

- a2

1/ z

1/ z

H2( z)

b0

b1

b2

1/ z

1/ z

x( n) y( n)

H( z)

- a1

- a2

1/ z

1/ z

b0

b1

b2

The commutative law of the convolution

Structures for IIR Systems

16

Page 17: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Cascade Form:

• In this form the system function H(z) is written as a product of second-order section with real coefficients.

• This is done by factoring the numerator and denominator polynomials into their respective roots and then combining either a complex conjugate root pair or any two real roots into second-order polynomials.

Structures for IIR Systems

17

Page 18: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

We assume that N is an even integer. Then Cascade Form:

22,

11,

22,

11,

10

11

1

0

11

110

11

11

1)(

00

1

−−

−−

=

−−

−−

−−

−−

++++

Π=

+++

+++=

++++++

=

zAzAzBzB

b

zazazz

b

zazazbzbbzH

kk

kkK

k

NN

Nbb

bb

NN

NN

N

Where, K is equal to N/2, and Bk,1, Bk,2, Ak,1,

Ak,2 are real numbers representing the coefficients of second-order section.

Structures for IIR Systems

18

Page 19: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

)()();()(

,,2,1,11

)()()(

101

22,

11,

22,

11,1

zYzYzXbzYwith

KkzAzAzBzB

zYzYzH

K

kk

kk

k

kk

==

=++++

==

+

−−

−−+

Biquad Section:

Is called the k-th biquad section. The input to the k-th biquad section is the output from the (k-1)-th section, while the output from the k-th biquad is the input to the (k+1)-th biquad. Each biquad section can be implemented in direct form II.

Yk(n)=XK+1(n) Yk+1(n)

-Ak,1

-Ak,2

1/z

1/z

Bk,1

Bk,2

Structures for IIR Systems

19

Page 20: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example:

x(n) y(n)

-A1,1

-A1,2

1/z

1/z

B1,1

B1,2

-A2,1

-A2,2

1/z

1/z

B2,1

B2,2

b0

Cascade form structure for N=4

Structures for IIR Systems

20

Page 21: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example:

Determine the cascade structure the following transfer function:

Structures for IIR Systems

21

Page 22: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

( ) ( )( )( )( )

( )( )

( )( )1

1

1

1

11

11

21

21

z25.01z1

z5.01z1

z25.01z5.01z1z1

z125.0z75.01zz21

zH

−−

−−

−−

−−

−+

−+

=

−−++

=+−++

=

Example:

Cascade of Direct Form I

Cascade of Direct Form II

Determine the cascade structure the following transfer function:

Structures for IIR Systems

22

Page 23: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Parallel Form: In this form the system function H(z) is written as a sum of second-

order section using partial fraction expansion.

NMifonly

NM

k

kk

K

k kk

kk

NMifonly

NM

k

kkN

N

NM

NN

MM

zCzAzA

zBB

zCzazazbzbb

zazazbzbb

zAzBzH

=

=−−

=

−−−

−−

−−

−−

∑∑

+++

+=

+++++++

=

++++++

==

012

2,1

1,

11,0,

01

1

110

11

110

1

1

ˆˆˆ1)(

)()(

K=N/2, and

B,A are real numbers

Structures for IIR Systems

23

Page 24: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

The second-order Section:

∑ <==

=++

+== −−

−+

NMzYzYzXzHzYwith

KkzAzA

zBBzYzYzH

kkk

kk

kk

k

kk

),()(),()()(

,,2,1,1)(

)()( 22,

11,

11,0,1

Is the k-th proper rational biquad section.

The filter input is available to all biquad section as well as to the polynomial section if M>=N (which is an FIR part)

The output from these sections is summed to form the filter output.

Each biquad section can be implemented in direct form II.

Structures for IIR Systems

24

Page 25: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Structures for IIR Systems

Parallel form structure for N=4 (M=N=4)

C0 B1,0

-A1,1

-A1,2

B1,1

B2,0

-A2,1

-A2,2

B2,1

x(n) y(n) 1/z 1/z

1/z

1/z 25

Page 26: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example: Determine the parallel structure the following transfer function:

H(z) must be expanded in partial fractions:

Structures for IIR Systems

26

Page 27: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Structures for IIR Systems

Example: (Cont.)

27

Page 28: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Three different structures can be used to implement an FIR filter:

Direct Form.

Cascade Form.

Linear Phase Form.

Frequency Sampling Form.

Lattice Form.

Structures for FIR Systems

28

Page 29: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Direct Form :

The difference equation is implemented as a tapped delay line since there are no feedback paths. Note that since the denominator is equal to unity, there is

only one direct form structure.

Structures for FIR Systems

29

Page 30: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example : Determine the Direct form structure for the following FIR Filter:

Structures for FIR Systems

30

Page 31: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

2/);1(

1

)(

22,

11,10

1

0

11

0

10

11

110

MKzBzBb

zb

bzbbb

zbzbbzH

kk

K

k

MM

MM

=++Π=

+++=

+++=

−−

=

−−−

−−

Cascade Form :

Cascade form FIR structure for 6-order FIR filter

Structures for FIR Systems

31

Page 32: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Linear Phase System :

A LTI system is said to have Linear Phase if the frequency response has the form

where α real is a real number

A system is said to have Generalized Linear Phase if the frequency response has the form where A(ejw) is a

real-valued function of ω, and β is a constant

Often the term linear phase is used to denote a system that has either linear or generalized linear phase.

20,,)( πβππαβ ±=≤<−−=∠ orwweH jw

Structures for FIR Systems

32

Page 33: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

For an FIR filter with a real-valued impulse response of length M, a sufficient condition for this filter to have generalized linear phase is that the h(n) be whether symmetric or anti symmetric.

For a causal FIR filter with M Length and impulse over [0,M-1] interval, the linear-phase conditions

1

0( ) ( )

Mj j k

kH e h k eω ω

−−

=

= ∑1

0( ) ( ) ( )

M

ky n h k x n k

=

= −∑

10,2/);1()(10,0);1()(

−≤≤±=−−−=−≤≤=−−=

MnnMhnhMnnMhnh

πββ

The length of the impulse response of the FIR filter (M) can be even or odd.

Linear Phase System :

Structures for FIR Systems

33

Page 34: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Linear phase filters may be classified into 4 types, depending upon whether h(n) is symmetric or anti symmetric and whether M is even or odd.

Linear Phase System :

1. Type I Linear Phase: Symmetrical and M even 2. Type II Linear Phase: Symmetrical and M odd 3. Type III Linear Phase: Anti-symmetrical and M even 4. Type IV Linear Phase: Anti-symmetrical and M odd

Structures for FIR Systems

34

Page 35: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

16M =

h(1)=h(14)

( )h n

n

h(0)=h(15)

h(2)=h(13)

h(7)=h(8)

Type I Linear Phase:

Symmetric and M even 11 2

2

0

1( ) 2 ( )cos2

MMjj

k

MH e e h k kωω ω

−−−

=

− = −

Symmetrical Impulse Response, M: Even

Structures for FIR Systems

35

Page 36: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Symmetrical Impulse Response, M: Odd ( )h n

n

15M =

h(0)=h(14)

“h(7)=h(7)”

h(1)=h(13)

h(6)=h(8)

Type II Linear Phase:

Symmetric and M odd

H(ejw)

Structures for FIR Systems

36

Page 37: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Antisymmetrical Impulse Response, M: Even 16M =( )h n

n

h(0)=-h(15)

h(7)=-h(8)

h(1)=-h(14)

Type III Linear Phase:

Anti Symmetric and M even

H(ejw)

Structures for FIR Systems

37

Page 38: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Antisymmetrical Impulse Response, M: Odd

n

( )h n 17M =

h(0)=-h(16)

h(1)=-h(15)

h(8)=-h(8)=0

h(7)=-h(9)

!

Type IV Linear Phase:

Anti Symmetric and M odd

H(ejw)

Structures for FIR Systems

38

Page 39: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Structures for FIR Systems

39

Page 40: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

++−+−++−+=+−++−++−+=

)]2()1([)]1()([)1()2()1()()(

10

0110

MnxnxbMnxnxbMnxbMnxbnxbnxbny

Linear Phase Form : Consider the difference equation with a symmetric impulse response.

The linear-phase structure is essentially a direct form draw differently to save on multiplications.

For M odd

Structures for FIR Systems

40

Page 41: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example:

Determine the Linear phase structure for the following FIR Filter:

The length of the filter is 7

Structures for FIR Systems

41

Page 42: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example:

7654321 )0()1()2()3()3()2()1()0()( −−−−−−− +++++++= zhzhzhzhzhzhzhhzH

Determine the Linear phase structure for the following FIR Filter:

The length of the filter is 8

Structures for FIR Systems

42

Page 43: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Moving-Average Filters: Structures And Equations

• As shown in Figure below, the effect of noise causes signal samples to fluctuate from the original values; thus the noise may be removed by averaging several adjacent samples.

• The moving (running)-average filter is a simple example of a digital filter.

• An L-point moving-average filter is defined by the following input/output (I/O) equation

where each output signal y(n) is the average of L consecutive

input signal samples.

43

Page 44: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example

Figure : Original (open circles) and corrupted (x) signals

44

Page 45: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Moving-Average Filters

• Implementation of above Equation requires L − 1 additions and L memory locations for storing signal sequence x(n), x(n − 1), . . . , x(n − L + 1) in a memory buffer.

• As illustrated in Figure below, the signal samples used to compute the output signal y(n) at time n are L samples included in the window at time n. These samples are almost the same as the samples used in the previous window at time n − 1 to compute y(n − 1), except that the oldest sample x(n − L) in the window at time n − 1 is replaced by the newest sample x(n) of the window at time n.

45

Page 46: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Moving-Average Filters • Thus previous equation can be computed as

• Therefore, the averaged signal, y(n), can be computed recursively based on the previous result y(n − 1). This recursive equation can be realized by using only two additions.

• However, we need L + 1 memory locations for keeping L + 1 signal samples {x(n), x(n − 1) . . . x(n − L)} and another memory location for storing y(n − 1).

• The recursive equation given in above equation is often used in DSP algorithms, which involves the output feedback term y(n − 1) for computing current output signal y(n).

46

Page 47: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example • To remove the noise that corrupts the sine wave as shown in Figure we

implement the moving-average filter with L = 5, 10, and 20, using the MATLAB code example.m.

• The original sine wave, noisy sine wave, and filter output for L = 5 are shown in Figure in next slide

• This figure shows that the moving-average filter with L = 5 is able to reduce the noise, but the output signal is different from the original sine wave in terms of amplitude and phase.

• In addition, the output waveform is not as smooth as the original sine wave, which indicates that the moving-average filter has failed to completely remove all the noise components.

• In addition, we plot the filter outputs for L = 5, 10, and 20 in Figure for comparison. This figure shows that the filter with L = 10 can remove more noise than the filter with L = 5 because the filter output is smoother for L = 10; however, the amplitude of the filter output is further attenuated. When the filter length L is increased to 20, the sine wave component is attenuated completely.

47

Page 48: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Moving-Average Filters

Figure : Performance of moving-average filter, L = 5 48

Page 49: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Moving-Average Filters

Figure : Moving-average filter outputs, L = 5, 10, and 20 49

Page 50: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Digital Filters

• The I/O equation given below can be generalized as a difference equation with L parameters, expressed as

where bl are the filter coefficients. • The moving-average filter coefficients are all equal as bl = 1/L. • We can use filter design techniques to determine different sets of

coefficients for a given specification to achieve better performance. • Define a unit impulse function as

FIR Filter Equation

Substituting x(n) = δ(n), the output is called the impulse response of the filter, h(n), and can be expressed as

50

Page 51: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example

• The moving-average filter defined above is an FIR filter of length L (order L − 1) with the same coefficients bl = 1/L.

• Consider an FIR Hanning filter of length L = 5 with the coefficient set {0.1 0.2 0.4 0.2 0.1}.

• Similar to Example , we can implement this filter with MATLAB script example2_4.m and compare the performance with the moving-average filter of the same length.

• The outputs of both filters are shown in Figure . The results show that the five-point Hanning filter has less attenuation than the moving-average filter. Therefore, we show that better performance can be achieved by using different filter coefficients derived from filter design techniques.

51

Page 52: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Example

Figure :Comparison of moving-average and Hanning filters, L = 5

52

Page 53: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Nonlinear Filters

• An efficient technique for reducing impulse noise is the use of a nonlinear filter, median filter.

• An L-point running median filter can be implemented as a first-in first-out buffer of length L to store input signals x(n), x(n − 1), . . . , x(n − L + 1).

• These samples are moved to a new sorting buffer, where the elements are ordered by magnitude.

• The output of the running median filter y(n) is simply the median of the L numbers in the sorting buffer.

• Medians will not smear out discontinuities in the signal if the signal has no other discontinuities within L/2 samples and will approximately follow low-order trends in the signal.

53

Page 54: Session 3 DSP  Intro

PEMP

ESD2521

M.S. Ramaiah School of Advanced Studies, Bengaluru

Session Summary

• Signals represent a message or information and are represented mathematically as a function of one or more independent variables, e.g. time.

• A system is an operation that transforms input signal x into output signal y. • The signals encountered in the real world such as speech, music, and noise

are random signals. • The moving (running)-average filter is a simple example of a digital filter • An efficient technique for reducing impulse noise is the use of a nonlinear

filter, median filter. • Realisation of a digital filter amounts to constructing a block diagram of

the internal structure of the filter. • Realisation of LTI filters need only three blocks.

54