Digital Representation of Audio Information

advertisement
EE513
Audio Signals and Systems
Digital Signal Processing
(Synthesis)
Kevin D. Donohue
Electrical and Computer Engineering
University of Kentucky
Filters
Filter are designed based on specifications given by:
 spectral magnitude emphasis
 delay and phase properties through the group delay and
phase spectrum
 implementation and computational structures
Matlab functions for filter design
 (IIR) besself, butter, cheby1, cheby2, ellip, prony, stmcb
 (FIR) fir1, fir2, kaiserord, firls, firpm, firpmord, fircls,
fircls1, cremez
 (Implementation) filter, filtfilt, dfilt
 (Analysis) freqz, FDAtool, SPtool
Filter Specifications
Example:Low-pass filter frequency response
1
Amplitude Scale
Cutoff Frequency
0.8
Passband
Stopband
0.6
0.4
0.2
Transitionband
0
0
0.2
Ripple
0.4
0.6
Normalize Frequency (fs/2 = 1)
0.8
1
Filter Specifications
Example Low-pass filter frequency response (in
dB)
10
Cutoff Frequency
0
Scale in dB
-10
-20
Stopband
Passband
-30
-40
Ripple
-50
-60
-70
0
Transitionband
0.2
0.4
0.6
0.8
Normalized Frequency (fs/2 = 1)
1
Filter Specifications
Example Low-pass filter frequency response (in dB) with
ripple in both bands
Filter Magnitude Response
0
Passband Ripple
Stopband Ripple
-10
dB
-20
-30
Transition
-40
-50
0
0.2
0.4
0.6
Normalize Hz
0.8
1
Filter Specification Functions
The transfer function magnitude or magnitude
response:
H M ( f )  H( z ) z exp( j 2f )
The transfer function phase or phase response:
H P ( f )   H( z ) z exp( j 2f )
The group delay (envelope delay) :
d HP ( f )
GP ( f )  
df
Filter Analysis Example
Consider a filter with transfer
function:
Hˆ ( z ) 
1
z
1  1.2728 z 1  0.81z 2
Compute and plot the
magnitude response, phase
response, and group delay.
Note pole-zero diagram. What
would be expected for the
magnitude response?
1.5
IM
Z-Plane
1
0.5
RE
0
-0.5
-1
-1.5
-1.5
-1
-0.5
0
0.5
1
1.5
Filter Analysis Example
Magnitude Response with FREQZ
8
6
6
TF Magnitude
TF Magnitude
Magnitude Response
8
4
2
0
0
1000
2000
3000
4000
Hz
5000
6000
7000
4
2
0
8000
0
1000
Phase Response
TF Phase in Radians
TF Phase in Radians
-2
-3
0
1000
2000
-4
4000 5000
Hz
Group Delay
6000
7000
5000
6000
7000
8000
7000
8000
7000
8000
-2
-3
0
1000
2000
3000
4000 5000 6000
Hz
Group Delay with GRPDELAY
0
1000
2000
3000
10
2
0
-1
-4
8000
Delay in Samples
Delay in Seconds
x 10
3000
4
0
4000
Hz
0
-1
6
3000
Phase Response with FREQZ
0
-4
2000
1000
2000
3000
4000
Hz
5000
6000
7000
8000
5
0
4000
Hz
5000
6000
Basic Filter Design
The following commands generate filter
coefficients for basic low-pass, high-pass, bandpass, band-stop filters:
For linear phase FIR filters: fir1
For non-linear phase IIR filter: besself, butter,
cheby1, cheby2, ellip
Example: With function fir1, design an FIR high-pass
filter for signal sampled at 8 kHz with cutoff at 500 Hz.
Use order 10 and order 50 and compare phase and
magnitude spectra with freqz command. Use grpdelay
to examine delay properties of the filter. Also use
command filter to filter a frequency swept signal from 20
to 2000 Hz over 4 seconds with unit amplitude.
Basic Filter Design
Example: With function cheby2 design an IIR Chebyshev
Type II high-pass filter for signal sampled at 8 kHz with
cutoff at 500 Hz, and stopband ripple of 30 dB down. Use
order 5 and order 10 for comparing phase and magnitude
spectra with freqz command. Use grpdelay to examine
delay characteristics. Also use command filter to filter a
frequency swept signal from 20 to 2000 Hz over 2 seconds
with unit amplitude.
Example: With function butter, design an IIR Butterworth
band-pass filter for signal sampled at 20 MHz with with a
sharp passband from 3.5 MHz to 9MHz. Use order 5 and
verify design of phase and magnitude spectra with freqz
command. Also use command filter and filtfilt to filter an
ultrasonic signal received from a medical imaging probe.
filtfilt => Zero Phase Filtering
Consider and N point signal x(n) and filter impulse response h(n)
DFT
DFT
x( n)  Xˆ ( k )
h( n)  Hˆ ( k )
Convolve sequences to obtain w(n) and reverse the order of w(n)
DFT
w(n)  Xˆ (k ) Hˆ (k )
DFT
w( N  n)  Hˆ * ( k ) Xˆ * ( k )
Convolve w(N-n) with h(n) and reverse results to obtain y(n)
DFT

y( N  n)  Hˆ ( k ) Hˆ * ( k ) Xˆ * ( k )

DFT


y( n)  Hˆ * ( k ) Hˆ ( k ) Xˆ ( k )
ˆ * (k ) Hˆ (k ) , which has zero phase
Note the effective filter of x(n)
is
H
2
ˆ
and the magnitude of H (k ) .
Filter Design with Spectral Magnitude Criteria
The following commands generate filter coefficients for an
arbitrary filter shape or impulse response.
For linear phase FIR filters: fir2, firls
The frequency points are specified with a vector
containing the normalized frequency axis and a
corresponding vector indicating the amplitude at each
of those points.
For non-linear phase IIR filter: prony, stmcb
The filter is specified in terms an impulse response
and the IIR filter model (numerator and denominator
order specified) is fitted to the response to minimize
mean square error of the impulse response.
Basic Filter Design
Example: Record a voice repeating random speech for about
20 seconds at fs = 22050 Hz, and compute its average
spectrum. From the picture of the average spectrum
magnitude, determine a spectral shape vector for use with
function fir2 to create a filter that approximates the voice
spectrum. Add white noise to another voice signal from the
same person to achieve a 6dB SNR and use filter to see how
well the noise can be reduced with the filter you designed.
Example: Generate an approximate impulse response of a
room and record it with fs=11025 Hz. Use the prony
function to attempt to model the room distortion as an IIR
filter (you have to guess some the orders and test to see if it
works).
Exercise Example
Record room noise (or another interesting noise
process ) for about 10 seconds at fs = 8000 Hz, and
compute its average spectrum (use the pwelch
function). From the picture of the average
spectrum magnitude, determine a spectral shape
vector for use with function fir2 to create a filter
that matches the noise spectrum. Filter a white
noise sequence with the FIR filter you designed and
compare the sound to white noise before and after
filtering with the room noise filter. Briefly describe
your observations, comment on differences and
similarities.
Useful Filter Functions
The sinc function and the rectangular pulse form a Fourier
transform pair.

1
rect( f ; B)  

0
for - B  f  B
2
2
for f elsewhere
sintB
B sinct; B   B
tB
Sketch these functions and label the null points of the sinc
function.
 What would a shift of the rect function in frequency do to the
sinc function in the time domain?
 What would a shift of the sinc function in time do to the rect
function in the frequency domain?
Useful Filter Functions
The sinc function and the rectangular pulse form a
Fourier transform pair.

1
rect(t , T )  

0
for - T  t  T
2
2
for t elsewhere
sinfT 
T sinc( f , T )  T
fT 
Sketch these function and label the null points of
the sinc function. What would a shift of the rect
function in time do to the sinc function in the
frequency domain?
Ideal Low-Pass Filter
The rect function in the frequency domain represents the
ideal low-pass filter.

1
rect( f , B)  

0
for - B  f  B
2
2
for f elsewhere
If the ideal low-pass filter were implemented in the time
domain, what would the convolution kernel look like?
Comment on the causality of this filter.
This is the filter that is required to perfectly reconstruct a
bandlimited signal (sampled above its Nyquist rate) from
its samples.
Ideal Interpolation Function
If the rect function in the frequency domain has B/2 equal
to the Nyquist frequency. Then the time domain sinc nulls
fall on sampling increments and the following convolution
becomes the reconstruction or interpolation filter to restore
a sampled band-limited signal from its samples:


sin
(
t

nT
)




T

y (t ) 
x( nT ) 
x( nT ) sinc(t  nT ) B 

n  
n  
(t  nT )
T

where T = 1/B.

Download