Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data...
-
Upload
rosemary-martin -
Category
Documents
-
view
228 -
download
1
Transcript of Signal Filters Purposes Separate Signals Eliminate interference distortions Remove unwanted data...
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
Filter Characteristics
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
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
Filter Performance
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.
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
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
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
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
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
The Convolution Machine
The Convolution Machine (cont.)
Convolution PropertiesDistributive
CommutativeAssociative
Properties of Convolution (cont.)Shift
Identity
Convolution Examples
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]
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]
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
Filter Examples
31 taps
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; }
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
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
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):
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Effective smoothing and elimination of outliers
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
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
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
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)
Median Filter
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
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
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
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
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
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
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
Window-sync Filter Performance
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
Example of a Custom Filter
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
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
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
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Compute ideal filter
Apply window
Final filter kernel
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Create low pass filter using Blackman window
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Low pass filter comparisons using different window functions
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Compare various Chebyshev window alternatives
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Compare various Kaiser window alternatives
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Control filter parameter tradeoffs using the Parks-McClellan design
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Compare Parks-McClellan, Chebyshev, and Kaiser
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
Shifting a low pass filter
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
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
High Pass Filter Example
Time Domain
Low Pass High Pass
Frequency Domain
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
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
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
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
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
The transition from -1800 to +1800 is not really a discontinuity
Still linear between the discontinuities
Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.
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