Digital Signal Processing II, ET1303 Lab assignment 2

advertisement
Digital Signal Processing II, ET1303
Lab assignment 2
IIR-filters
Spectrum estimation
Task 1
Preparation
This lab assignment consists of two parts; IIR-filters and spectrum estimation. All exercises are to be implemented
in Matlab.
In the first part, digital IIR-filters will be designed using the bilinear transformation of classic analog filters
like Butterworth, Chebyshev type I and II and Cauer filters. The effect on the filter specification when using
quantized filter coefficients and implementing filters in cascade will also be studied. It is of great importance
that quantization effects are considered when implementing recursive filters with limited precision. In this lab
assignment, some different filter types and structures should be designed given a certain frequency specification.
The filters should be constructed using as low order and quantization resolution as possible. The theory behind
this assignment can be found in Proakis & Manolakis, section 7.3, 7.6 and 8.3–8.4.1.
In the second part, spectrum estimation will be performed using Welch’s method. The effect of using different
windows and window lengths regarding frequency resolution, signal dynamics and variance will be investigated.
In the assignment, four different signals are given for classification. These signals consists of an unknown mixture
of different known components, such as wide- and narrow-band noise and tonal components. The theory behind
this assignment can be found in Proakis & Manolakis, section 12.1–12.2.
Task 1-A: Calculate the lowest order N for an IIR lowpass filter using a Butterworth prototype filter.
The filter should fulfill the specification with Rp = 3 dB, Rs = 40 dB, ωp = 0.4π and ωp = 0.6π.
20 · log10 |H(f )|
0
−Rp
−Rs
ω
ωp
ωs
Task 1-B: Calculate the lowest order N for an IIR highpass filter using a Butterworth prototype
filter. The filter should fulfill the specification with Rp = 3 dB, Rs = 40 dB, ωp = 0.2π and ωp = 0.1π.
20 · log10 |H(f )|
0
−Rp
−Rs
ω
ωs
ωp
Task 1-C: Calculate the lowest order N for an IIR bandpass filter using a Butterworth prototype
filter. The filter should fulfill the specification with Rp = 3 dB, Rs = 40 dB, ωp,1 = 0.2π, ωp,2 = 0.4π,
ωs,1 = 0.1π and ωs,2 = 0.5π.
1
20 · log10 |H(f )|
0
−Rp
−Rs
ω
ωs,1
ωp,1
ωp,2
ωs,2
The autocorrelation γx (m) and the power density spectrum Γx (f ) of a wide-sense stationary process x(n) are
defined as
γx (m) = E [x(n)x(n + m)]
X
Γx (f ) =
γx (m)e−j2π·f ·m
(1)
(2)
m
Task 1-D: What is the autocorrelation and the power density spectrum for
• white noise ξ(n) with variance σ 2 ,
• filtered noise x(n) = ξ(n) ∗ h(n), and
• a sinusoid with random phase, x(n) = A · sin(2π · f0 · n + φ), where A is the amplitude, f0 is the
frequency, and φ is a uniformly distributed stochastic variable on the interval [0, 2π].
The expected value of Welch’s estimate PxW (f ) is
Z1/2
E PxW (f ) =
Γx (α)W (f − α)dα
(3)
−1/2
where
2
−1
M
X −j2π·f ·n W (f ) = PM −1
e
w2 (n) 1
(4)
n=0
n=0
and where w(n) is the window and M is the length of every data segment. The total amount of data (no overlap),
using L segments, then becomes L · M
Welch’s power density spectrum estimate is asymptotically unbiased. Therefore the parameters σ 2 , A and f0
for the signals above can be estimated.
Assume that the signal x(n) is colored noise, x(n) = ξ(n) ∗ h(n), where ξ(n) is white noise with variance σξ2 .
Also assume that the maximum of the frequency function |H(f0 )| = 1 at frequency f0 . The maximum of the
power spectral density is then given by Γx (f0 ) = σξ2 ≈ PxW (f0 ).
Task 1-E: Assume that the signal x(n) is a sinusoid
phase,
x(n) = A · sin(2π · f0 ·
with random
n + φ) with an arbitrary window. Calculate E PxW (f ) and E PxW (f0 ) . This assignment shows an
approximation of the relation between a measured spectral peak PxW (f0 ) and the amplitude A for
some window w(n).
Task 1-F: Assume that the signal x(n) is a sinusoid with random phase, x(n) = A · sin(2π ·f0 · n + φ)
and that the window is a rectangular window, w(n) = 1 for n ∈ [0, M − 1]. Calculate E PxW (f0 ) .
This assignment shows that the power spectral density estimate peak value increases proportionally
to the window length M for a sinusoid. This can be used to distinguish a pure sinusoid from a
narrowband noise like x(n) = ξ(n) ∗ h(n).
2
Task 2
Lab assignment
A Butterworth lowpass filter corresponding to preparation task 1-A can be designed as follows.
Wp = 0.4;
Ws = 0.6;
Rp = 3;
Rs = 40;
[N , Wn ] = buttord ( Wp , Ws , Rp , Rs );
[b , a ] = butter (N , Wn );
Note that Wp=0.4 means that ωp = 0.4π in the frequency scale use in Matlab. The corresponding frequency
response can be plotted as follows.
[H , w ] = freqz (b , a );
plot ( w / pi , 20* log10 ( abs ( H )));
grid ( ’ on ’ );
axis ([0 , 1 , -80 , 20]);
To construct a Chebyshev type I or II, or an Cauer (Elliptic) filter, replace buttord and butter with cheby1ord
and cheby1, cheby2ord and cheby2, or ellipord and ellip, respectively.
A Butterworth highpass filter corresponding to preparation task 1-B can be constructed as follows.
Wp = 0.2;
Ws = 0.1;
Rp = 3;
Rs = 40;
[N , Wn ] = buttord ( Wp , Ws , Rp , Rs );
[b , a ] = butter (N , Wn , ’ high ’ );
Note that Ws < Wp in this case.
The construction of bandpass filters are done by specifying the cutoff frequencies as vectors instead. A
butterworth bandpass filter corresponding to preparation task 1-C can be constructed as follows.
Wp = [0.2 , 0.4];
Ws = [0.1 , 0.5];
Rp = 3;
Rs = 40;
[N , Wn ] = buttord ( Wp , Ws , Rp , Rs );
[b , a ] = butter (N , Wn );
The effect of quantizing the filter coefficients will also be studied. To do this, a pre-made Matlab script is
provided that is called as follows.
[b , a , kdir , bqdir , aqdir , kcas , bqcas , aqcas ] = IIRq (b , a , k );
The input parameters are the numerator and denominator coefficients b and a, defined as
H(z) =
B(z)
b0 + b1 z −1 + · · · + bN z −N
=
A(z)
a0 + a1 z −1 + · · · + aN z −N
(5)
and the quantization level k (the number of bits to quantize to). The output parameters kdir , bq,dir and aq,dir
are the quantized coefficients of a direct form filter structure, defined as
Hq (Z) = kdir ·
bq,0 + bq,1 z −1 + · · · + bq,N z −N
aq,0 + aq,1 z −1 + · · · + aq,N z −N
(6)
where the coefficients are quantized using a resolution of k bits, so bq and aq are integers in the range [−2k−1 , 2k−1 ].
The output parameters kcas , bq,cas and aq,cas are the quantized coefficients of a cascaded second-order systems
filter structure, defined as
BN/2 (z)
B1 (z)
Hq (z) = kcas ·
· ··· ·
(7)
A1 (z)
AN/2 (z)
where Bn (z) and An (z) are the numerator and denominator polynomial of the n:th cascaded second-order section.
The coefficients are quantized using a resolution of k bits, so bq and aq are integers in the range [−2k−1 , 2k−1 ]
The function IIRq also draws four plots, in order;
• Figure 1 shows the resulting amplitude response.
3
– Blue solid line: no quantization.
– Red dashed line: quantized direct form.
– Green dashed line: quantized cascaded second-order sections.
• Figure 2 shows a pole-zero plot, no quantization.
• Figure 3 shows a pole-zero plot, quantized direct form.
• Figure 4 shows a pole-zero plot, quantized cascaded second-order sections.
Task 2-A: What order N is needed to fullfill the filter specification in fill resolution? What resolution
(how many bits) are needed to fullfill the filter specification when using direct form and cascaded
second-order sections structure, respectively?
Perform the following filter design exercises and complete the tables.
Task 2-B: Lowpass filter as in preparation task 1-A with ωp = 0.4, ωs = 0.6, Rp = 3 and Rs = 40.
Butterworth
Chebyshev type I
Chebyshev type II
Cauer
Order N
Resolution k, direct form
Resolution k, cascade
Task 2-C: Lowpass filter as in preparation task 1-A with ωp = 0.1, ωs = 0.2, Rp = 3 and Rs = 40.
Butterworth
Chebyshev type I
Chebyshev type II
Cauer
Order N
Resolution k, direct form
Resolution k, cascade
Task 2-D: Highpass filter as in preparation task 1-B with ωp = 0.2, ωs = 0.1, Rp = 3 and Rs = 40.
Butterworth
Chebyshev type I
Chebyshev type II
Cauer
Order N
Resolution k, direct form
Resolution k, cascade
Task 2-E: Bandpass filter as in preparation task 1-C with ωp = 0.2
and Rs = 40.
Butterworth
Chebyshev type I
Order N
Resolution k, direct form
Resolution k, cascade
4
0.4 , ωs = 0.1
Chebyshev type II
0.5 , Rp = 6
Cauer
Task 3
Spectrum estimation
In this lab, Welch’s method will be used to estimate the power spectrum density. Four different, unknown
signals are to be classified.
A zero mean white Gaussian noise x(n) with variance s2 can be generated as follows.
x = s * randn (30000 , 1);
A colored noise, filtered by a lowpass Butterworth filter can be obtained as follows.
[b , a ] = butter (10 , 0.5); % order 10 , cutoff frequency 0.5 pi
y = filter (b , a , x );
The power spectrum density can be estimated using Welch’s method as follows.
M = 256;
win = hamming (M , ’ periodic ’ );
[P , f ] = spectrum (y , M , 0 , win , 2);
plot (f , 10* log10 ( P (: , 1)));
grid ( ’ on ’ );
axis ([0 , 1 , -80 , 10]);
Try to filter the noise using different filters (cutoff frequencies, orders, high- or lowpass, and so on). Plot the
spectrum as above and listen to the signal.
sound (y , 8000); % play the vector y at 8000 samples per second
Also try to filter, perform spectrum estimation and listen to a sequence of music.
load handel
[b , a ] = butter (10 , 0.5);
z = filter (b , a , y );
sound (z , Fs );
A sinusoid with amplitude A and frequency ωs = π · Fs can be generated as follows.
y = A * sin ( pi * Fs *(0:30000 -1) ’);
Experiment, do spectrum estimation and listen to the signals. Use different windows and different block lengths.
The basic principle is that an increased block length M yields a higher frequency resolution and reduced spectral leakage, but increased variance. Different window types yields different frequency resolutions and different
properties regarding signal dynamics. A window with extremely high dynamics (and extremely wide main lobe)
can be constructed in Matlab as follows.
win = kaiser (M , 30);
Task 3-A: Four unknown signals are to be classified. These are stored in the variable y in the
Matlab data files sig1.mat, sig2.mat, sig3.mat and sig4.mat. The signals are constructed using
the following signal components.
• Wideband noise x(n) = ξ(n) ∗ h(n) where ξ(n) is white Gaussian noise with variance σξ2 = 1.
The digital filter h(n) is a bandpass Butterworth, Chebyshev type I or II, or an Cauer filter.
• Narrowband noise x(n) = ξ(n) ∗ h(n) where ξ(n) is white Gaussian noise with variance σξ2 . The
digital filter h(n) is a bandpass Chebyshev type I order 2 filter with unknown center frequency
f0 . Note that |H(f0 )| = 1.
• Sinusoid with random phase x(n) = A · sin(2π · f0 · n + φ).
Classify the four signals by deciding which signal components they consist of. Estimate the signal
parameters. Note whether the wideband noise is derived from a Butterworth, Chebyshev type I or
II, or an Cauer filter. Estimate the peak value σξ2 and center frequency f0 for narrowband noise.
Estimate the amplitude A and frequency f0 for sinusoids.
Note that the combination of signal components are unknown. The signal may contain many sinusoids
and may be very close in frequency. To solve this classification problem, the power spectrum density
must be investigated using varying frequency resolutions, variances and dynamics. The signal may
for example contain components that are very weak and that can only be discovered using a window
with extremely high dynamics (for example a Kaiser window).
Complete the following table.
5
Classification
Wideband noise
Bu/Ch1/Ch2/Ca
Narrowband noise
f0 , σξ2
sig1.mat
sig2.mat
sig3.mat
sig4.mat
6
Sinusoid 1
f0 , A
Sinusoid 2
f0 , A
Download