Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data...

67
Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model a physical system (stock market behavior) Enhance desired components (speech recognition) Examples Breathing interference on heartbeat sound Poor quality recordings Background Noise Categories Analog: electronic circuits with resistors and capacitors Digital: Numerical calculations on signal samples

Transcript of Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data...

Page 1: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Signal Filters

Purposes• Separate Signals• Eliminate interference

distortions• Remove unwanted data• Restore to its original form

(after transmission)• Model a physical system

(stock market behavior)

• Enhance desired components

(speech recognition)

Examples• Breathing interference on

heartbeat sound• Poor quality recordings• Background Noise

Categories• Analog: electronic circuits with

resistors and capacitors• Digital: Numerical calculations

on signal samples

Page 2: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Filter Characteristics

Page 3: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Analog Filter Characteristics

• Ripple: wave in the pass frequencies

• Roll off: transition from pass to fail

• Step response: response to quick signal changes

• Overshoot: increased amplitude at the point of roll off

• Ringing: decreasing oscillations

The analog filter determines what frequencies we see in the computer

Flat FrequencyResponse

SharpRoll-off

Page 4: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Filter Jargon

• Rise time: Time for step response to go from 10% to 90%• Linear phase: Rising edges match falling edges. Constant

phase change in the frequency response.• Overshoot: amount amplitude exceeds the desired value• Pass band: the allowed frequencies• Stop band: the blocked frequencies• Transition band: frequencies between pass or stop bands• Cutoff frequency: point between pass and transition bands• Roll off: slope of the transition area• Pass band ripple: oscillations in the pass band• Stop band attenuation: reduction of stop band amplitude

Page 5: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Filter Performance

Page 6: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Analyzing a unknown filter

• Impulse response: Feed a delta function and see what comes out. Reverse engineer what the filter does. (δ(t) = 1 if t = 0; 0 otherwise)

• Step response: Feed in a step function and see what comes out. Good for determining change points in the signal. (µ(t) = { 1 if t>=0; 0 otherwise})

• Frequency response: Perform a spectral analysis. Separate a signal into its component sinusoids. Example: separate light frequencies in a signal.

Page 7: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 8: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Digital Filters in Electronics

1. Sample and digitize a signal of voltages or current fluctuations with an analog to digital converter resulting in an array of numbers

2. Perform an algorithm that performs linear numerical calculations on the signal

3. Output the resulting array of filtered samples through digital to analog converter

Originalanalog

Originaldigitized

Filtereddigital

Filteredanalog

Implementation Steps

Page 9: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Time Domain Filters• Finite Impulse Response

– Filter only affects the data samples, hence the filter only effects a fixed number of data points

– y[n] = b0 sn+ b1 sn-1+ …+ bM-1 sn-M+1=∑k=0,M-1bk sn-k

• Infinite Impulse Response (also called recursive)– Filter affects the data samples and previous filtered output,

hence the effect can be infinite

– t[n] = ∑k=0,M-1bk sn-k + ∑k=0,M-1 ak tn-k

• If a signal was linear, so is the filtered signal– Why? Because we summed samples multiplied by constants,

we did not multiply different samples or raise samples to a power

Page 10: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Convolution

• The Convolution algorithm generates output by applying a convolution kernel to a signal– Input is a set of samples– Output from each sample is scaled and shifted

according to the convolution kernel – Outputs add together to get the overall output

• Convolution implementations– The shift and scaling operations preserve linearity for

signals that we deal with– The number of calculations per input sample can be

prohibitive

The heart of designing and implementing digital filters

Page 11: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Convolution Example• Apply h to each index (i) of the input signal• Sample calculation when i=4

y[4] = x[4]*h[0] + x[3]*h[1] + x[2]*h[2] + x[1]*h[3] = (1.4*1.0) + (2*-.5) + (-1.4 *-.35) + (-1*-.1) = +1.4 -1.0 +0.49 +0.1 = 0.99

Assumex = {0, -1, -1.4, 2, 1.4, 1.4, .8, 0, -.6}h = {1, -0.5, -0.35, -0.1}

Filter Kernel

Traditional convolution symbol

Page 12: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

The Convolution Machine

Page 13: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

The Convolution Machine (cont.)

Page 14: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Convolution PropertiesDistributive

CommutativeAssociative

Page 15: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Properties of Convolution (cont.)Shift

Identity

Page 16: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Convolution Examples

Page 17: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Identity and Amplify

• Top Figure– The signal remains

unchanged

• Bottom Figure– The signal’s amplitude is

multiplied by 1.6– Attenuation can occur

by picking a magnitude that is less than one

y[n] = k δ[n]

Page 18: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Shift and Echo

• Top Figure– Delay the output by four

samples

– An advance is possible using the negative indices

• Bottom Figure– Produce an echo that has an

amplitude of 60% of the original signal

y[n] = x[n] * δ [n-s]

Page 19: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Band Limiting Filters

• Goal: Attenuate undesired frequencies

• Low-pass: Attenuate high frequencies

• High-pass: Attenuate low frequencies

• Band-pass: Attenuate “out of band” frequencies

• Design Considerations– Number taps (length of the filter kernel array)– Transition band width– Pass band ripple and stop band attenuation

Page 20: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Filter Examples

31 taps

Page 21: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Convolution Code/** @param x input signal @param h convolution kernel @result convolved signal*/

int[] convolve(int[] x, int[] h){ int[] y = new int[x.length+h.length-1];

for (int k=0; k<y.length; k++) { for (int j=0; j<h.length; j++) { try { y[k] += x[k-j]*h[j]; }

catch (Exception e) {}} }

return y; }

Page 22: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Moving Average Filter• Usage

– smooth a signal and reduce noise– curves sharp angles in the time domain

• Disadvantages– It overreacts to outlier samples– Slow roll-off destroys frequency resolution– Horrible stop band attenuation

• Evaluation– An exceptionally good smoothing filter– An exceptionally bad low-pass filter

Page 23: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Moving Average Filter• Formula: Yn = 1/L ∑i=0, M-1 xn-I

• Filter Kernel: {1/4, 1/4, 1/4, 1/4} if L = 4• Notes

– All of the kernel coefficients are equal– The divide by 4 eliminates the gain

• Example: {1,2,3,4,5,4,3,2,1,2,3,4,5}; M = 4– Starting filtered values up to index 3: {¼ , ¾, 1 ½, 2 ½, … }– Next value: Y4 = (5/4+4/4+3/4+2/4) = 3 ½

• Speech Applications– Disadvantages

• Blurs transitions between voiced/unvoiced sounds• Negatively impacts the frequency domain

– Advantage: Useful to smooth the pitch contour

Page 24: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Moving Average FIR Filter

int[] average(int x[]) { int[] y[x.length]; for (int i=50; i<x.length-50; i++) { for (int j=-50; j<=50; j++) { y[i] += x[i + j]; } y[i] /= 101;} }

Convolution using a simple filter kernel

Formula:

Example Point:

Example Point (Centered):

Page 25: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Effective smoothing and elimination of outliers

Page 26: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 27: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Note: the newest values show on the left side, which is opposite to what we might expect when viewing data as an array

Page 28: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 29: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 30: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Characteristics of Moving Average

Filters

• Longer filters gets rid of more noise

• Long filters lose edge sharpness

• Terrible frequency resolution• Frequency response is the

sync function we’ve seen before (sin(x)/x)

Page 31: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Median Filter

Page 32: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Multiple Pass Moving Average

• Pass the signal through the filter more than once to improve stop band attenuation

• Convolve the filter kernel together to provide the combined filter in one step

Page 33: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Note: Moving average attenuates the maximum value; amplifies the others

Page 34: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

NoteDFT of a moving average filter is the sync function (sin(x)/x). We saw this before when discussing the rectangular window

Page 35: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Convolution Theorem

• Multiplication in the time domain is equivalent to convolution in the frequency domain

• Multiplication in the frequency domain equivalent to convolution in the time domain

• Application: We can design a filter by creating its desired frequency response and then perform an inverse FFT to derive the filter kernel

• Theoretically, we can create an ideal (“perfect”) low pass filter with this approach

Page 36: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 37: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 38: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 39: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Time/Frequency Domain Duality

• Rectangular window multiplies time domain elements by 1, resulting in sin(x)/x in the frequency domain

• Proof with calculus∫-∞,∞ x(t)e-jtkw

0dt = ∫-1/2,1/2 x(t)e-jtkw0dt = ∫-1/2,1/2 e-jtkw

0dt = (1/jw)e-jwt|-1/2,1/2

= (1/jw)(e-jw½ –e-jw(-½)) = (1/jw)(ejw/2–e-jw/2) = sin(jw/2)/(jw/2)

-1/2 1/2

Page 40: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

The Perfect Frequency Filter

• Window-Sync Filter: h[k] = sin(2fc π k) / kπ

• Convolving with this filter provides a perfect low pass filter• Requires infinite length, abrupt transition edge, excessive ripple

Page 41: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Window-sync Filter Performance

Page 42: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Custom Filters

1. Create the desired frequency response

2. Perform an inverse Fast Fourier Transforma. Can't use this directly because of the abrupt edgesb. A perfect filter requires infinite impulse response

3. Shift to center the filter about time=0, truncate, and apply a window function to the result

4. Use the result as the filter kernel

5. Application: Remove undesired frequency patterns

For any frequency response

Page 43: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Example of a Custom Filter

Page 44: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

The Ideal Frequency Filter

• Inverse Fourier transform on a square wave: h[k] = sin(2fc π k) / kπ

• Convolving with this filter provides a perfect low pass filter• Problems (infinite length, abrupt edge, excessive ripple

Page 45: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 46: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

A low pass filter kernel coefficients can varyThe values chosen affect the transition band, ripple, and roll off

-0.040.04

-0.1

Page 47: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 48: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Compute ideal filter

Apply window

Final filter kernel

Page 49: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Create low pass filter using Blackman window

Page 50: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Low pass filter comparisons using different window functions

Page 51: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Compare various Chebyshev window alternatives

Page 52: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Compare various Kaiser window alternatives

Page 53: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Control filter parameter tradeoffs using the Parks-McClellan design

Page 54: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 55: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Compare Parks-McClellan, Chebyshev, and Kaiser

Page 56: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Shifting a low pass filter

Page 57: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

NoteShifting a low pass filter affects roll off and ripples

Page 58: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

High Pass Spectral Inversion Filter

• Two step solution– Filter the signal– Subtract the low pass signal from the original

• One step solution– Requires:

• A point of symmetry (N/2), the center of an odd number of points• The filter kernel must be symmetric

– Flip the sign of every filter kernel point; add one at index N/2• Why does it work?

– A filter with unity at the point of symmetry is the identity function (an all pass filter) which passes the entire signal

– 1 - h[n] applied to the signal is all pass minus the low pass system, resulting in passing only the high frequency components

First create a low pass filter

Page 59: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

High Pass Filter Example

Time Domain

Low Pass High Pass

Frequency Domain

Page 60: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

High Pass Spectral Reversal Filter

• Change the sign of every other sample.• Why does it work?

– This has the effect of multiplying every other sample by sin(2πfs/2), the Nyquist frequency

– Aliasing then shifts the frequencies where the top frequencies wrap around to the start creating a mirror image

– Example: suppose the Nyquist frequency is 4000. frequency 0 becomes 4000, frequency 50 becomes (50+4050) which aliases 3950

First create a low pass filter

Page 61: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 62: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Band Pass Filters

1. Create a low pass filter2. Create a high pass filter3. Convolve the filters together to get a band pass filter4. Use spectral inversion or reversal for a band reject filter

Page 63: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Convolve low pass and high pass to derive band pass

Page 64: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Group Delay

• Definition: The negative slopeof phase angle with respect to frequency

• FIR filters have a linear group delay (the slope is a straight line. In the pass band, there are also no discontinuities.

• A non linear delay can distort output (e.g. music audio).• IIR filters introduce degrees of non-linear group delay.

The tradeoff is much faster computation, and sometimes better filter quality, versus the degree of non-linearity

Page 65: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

The transition from -1800 to +1800 is not really a discontinuity

Still linear between the discontinuities

Page 66: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Page 67: Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data Restore to its original form (after transmission) Model.

Implementation

• Create a convolution method• Create an array with appropriate

filter kernel coefficients• Call the convolution method with

the signal frame, and filter kernel array as calling arguments

Conclusion: Lots of mathematical theory, very little code needed