#### Transcript LPC, Chapter 12

```Non-Linear Filter
Median of five or seven
Original signal
Median of seven
Moving average
Median Filter
• Definition:
– The middle value of an ordered list
– If there is no middle value, average the two middle values
• Median filter: Yn = medianm=0,M-1 {xn-m}
– Good edge preserving properties
– Preserves sharp discontinuities of significant length
– Eliminates outliers, without blurring the signal
• Applications
– The most effective algorithm to removes sudden impulse noise
– Remove outliers when smoothing a pitch contour
Characteristics: Median Filter
• Linearity
Fails: an * Mn + bn * Mn ≠ (an + bn) * Mn
Succeeds: α (an)*Mn = (α an)*Mn
Succeeds: An * Mn = bn, then An+k * Mn+k = bn+k
• Every output will match one of the inputs (if
the filter length is odd)
• Frequency response
• There is not a well-defined mathematical formula
• Must be determined experimentally
Double Smoothing
1.
2.
3.
4.
Apply a median filter (ex: five point)
Apply a linear filter (Ex: Hanning with values 0, ¼ , ½ , ¼, 0)
Recursively apply steps 1 and 2 to the filtered signal
Add the result of the recursive application back
Single Smoothing
Double Smoothing
Compare Median to Moving
Average Filter
Left: Moving Average, Right: Median
Correlation
Sometimes called a “Matched Filter”
Purpose: identify noisy, scaled, shifted target signal
Application: pitch, radar, edge detection, MRI
Implementation: reversed convolution
How identify similar signal?
• If signal is aligned, we sum the
values squared and y[n] will
contain a spike.
• Result will not resemble
original, but we are testing the
presence, not recreating or
altering.
Auto-correlation
Test if signal delayed i samples correlates with signal delayed j samples
public double autoCorrelate(double[] signal, int i, int j)
{
double sum = 0;
int N = signal.length;
for (int n=0; n<N; n++)
{ try
{ sum += signal[n-i] * signal[n-j]; }
catch (ArrayIndexOutOfBoundsException e) {}
}
return sum;
All-pass filter
Definition: Passes all frequencies
Note: magnitudes remains constant, but the phase and frequencies warped
• Pole of an all-phase filter lies inside the
unit circle and the matching zero is an
equal distance outside.
• The Z-domain magnitudes of the
matching poles and zeros cancel along
the unit circle
• They lie on the same radius line, but with
reciprocal magnitudes
• Example: Assume Pole at p0 = ½+½j
The pole magnitude = (¼+¼)1/2 = 1/2½
The zero magnitude = 2½
Zero z0 = 2½ cos 45 + j(2½ sin 45) = 1 + j
s
z0
r
Φ
p0
All-Pass Transfer Function
• First order all pass filter transfer function:
H(z) = B(z)/A(z)
= (z-1-me-jφ)/(1-1/me-jφz-1) = (z-1-λ)/(1-λz-1)
where m is the magnitude and φ the angle
• Higher order all pass transfer function
• The FIR and IIR coefficients are the same
All pass Filter Visualization
All-pass Filter Phase Response
• H(z) = B(z)/A(z) = (z-1-λ)/(1-λz-1)
2π
λ, controls the location of the
pole (p) and the zero (1/p)
• Notes: Figure to the right
– No phase shift at w = 0, π, 2π
– Phase response:
w+2arctan(λsin(w)/(1- λcos(w))
– π is the cross over point
λ= 0.8
w
2π
Frequency Warping
• Group delay
– Definition: change of phase with respect to change of
frequency
– Interpretation: Different frequencies pass through a filter
at different speeds. Therefore, a frequency warping
operation occurs
– Formula:
Where w is angle of original frequency, w’ is the angle of
the warped frequency, λ is the all-pass coefficient
2)sin(w)
(1λ
w’ = arctan
(1- λ2) cos(w) - 2λ
Illustration
Frequency Warped Mel Scale
Hearing sensitivity corresponds to a non-linear scale
Differentiators
Estimate slope of signal features
• Application: Variations in a adjacent frames of a speech
signal helps to identifies phonemes and syllable changes
• Simple Naïve filter: y[n] = x[n]-x[n-1]
• Central difference filter: y[n] = x[n+1] – x[n-1]
• Higher order differences: using 2M+1 filter coefficients
h(k) = -3k / (M(M+1)(2M+1)
– Example: M=2, then M*(M+1)*(2M+1) = 30
if k = -2, h(k) = -3(-2) / (30) = 0.2
if k = -1, h(k) = -3(-1) / (30) = 0.1
if k = 0, h(k) = -3(0) / (30) = 0
if k = 1, h(k) = -3(1) / (30) = -0.1
if k = 2, h(k) = -3(2) / (30) = -0.2
– Filter: h = { 0.2, 0.1, 0, -0.1, -0.2};
Understanding Digital Signal Processing, Third Edition, Richard Lyons
For some applications, the frequency response is not important
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Understanding Digital Signal Processing, Third Edition, Richard Lyons
IFIR Filters
Interpolated Finite Response Filters
• FIR Filter Disadvantage: too many calculations
• Goal: Reduce the number of taps
• Process
– Create two filters (shaping, image reject) with less taps
– Apply the shaping filter, and then the mage reject filter
• Result: The number of total
calculations are greatly
reduced
The Shaping Filter
Prototype filter: Np = 9 coefficients
Expanded prototype filter: M = 3 and M(Np-1)+1 coefficients
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Original signal
Prototype filter
creates aliases
Low pass image reject
filter attenuates aliases
Resulting signal
Fpass is the end of the pass band fstop is the end of the stop band
Fir = 1/M – fstop is the end of the stop band of the image reject filter
Frequencies measured in percentage of sampling rate
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Designing an IFIR Filter
• General formula: number of taps
Ntaps = Attenuation in decibels
22(M)(fstop – fpass)
• Example: Attenuation 50 db, M = 7, fpass = 0.02, fstop = 0.03
• Taps for shaping filter (33)
Nshape = 50 / {22 (7)(0.03 – 0.02)} ≈ 32.4
• Taps for image reject filter (25)
Nir = 50 / {22 (1/7 – 0.03 – 0.02)} ≈ 24.5
• Taps for original filter (228)
Nfilter = 50 / (22)(.03 - .02) ≈ 227.3
An FIR filter of any length by truncating the window-sync at any length
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Sample Rate Conversion
• Application: Process speech in audio files
that were recorded at different rates
• Algorithm:
1. Find the greatest common denominator (GCD) of
both source and destination sample rates
2. Use the GCD to interpolate the source signal
3. Apply an appropriate low pass filter
4. Use the GCD to decimate the interpolated signal
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Two stage decimation is useful to reduce the taps and number of calculations
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Example
• Description
– Source signal sample rate = 22,050 hz
– Destination signal rate = 10000 hz
• Compute the Greatest Common Denominator
gcd(x,y) = gcd(x%y,y) = 50 // x>=y
• Compute resampling factors
10000/50 = 200 and 22050/50 = 441
• Interpolate source signal by destination factor
22,050 * 200 = 4,410,000
• Apply an appropriate FIR filter
• Decimate expanded signal by source factor
4,410,000 / 441 = 10,000
Understanding Digital Signal Processing, Third Edition, Richard Lyons
• An filter with too wide of a transition band or with too
• The decimation step causes aliases and needs to be
low pass filtered if the frequency band is too small
• Inserting lower tap filters in series are useful to
reduce the number of required steps
• We don’t need to create a huge array in the
interpolation step, but can apply a poly-phase filter to
the original signal, in combination with a ring buffer
(circular queue), and automatically extract the
appropriate outputs.
For each iteration, many of the calculations are zero, so
those can be skipped in the calculations
Understanding Digital Signal Processing, Third Edition, Richard Lyons
Understanding Digital Signal Processing, Third Edition, Richard Lyons
If m is an even
multiple of the
destination signal,
append to the
output array.
Ring Buffer
Insert all outputs into a
ring buffer, length of the
filter taps, for future filter
calculations. A huge array
is not necessary.
Understanding Digital Signal Processing, Third Edition, Richard Lyons