4.13 Extra Exercises
4.1. Taking Figure 4.42 as a reference, decode the DTMF symbols of Figure 4.50,
which correspond to a phone number with eight digits.
4.2. Can a discrete-time random process have infinite power? If yes, under what conditions? Can these conditions be achieved in practice?
4.3. Modify Listing 4.36 to investigate how the sidelobes are decreased in the DTFT of the Hann window by combining three DTFTs of a rectangular window. Then, perform the same analysis for the Hamming window.
1function snip_frequency_testHannDTFT 2N=9; %number of window samples 3[dtftHann,w]=freqz(hann(N)); %get values of the DTFT as reference 4dtftHann2=0.5*rectWinDTFT(w,N)- 0.25*rectWinDTFT(w+(2*pi/(N-1)),N)... 5 -0.25*rectWinDTFT(w-(2*pi/(N-1)),N); %DTFT using expression 6plot(w,real(dtftHann-dtftHann2),w,imag(dtftHann-dtftHann2)) %error 7end 8function D=rectWinDTFT(w,N) %get DTFT of rectangular window 9D=sin(0.5*N*w)./sin(0.5*w).*exp(-j*0.5*w*(N-1)); 10end
4.4. Explore the computation and relationships among convolution, correlation and FFT. Assume a vector x=[0 1 4 8 0] with elements. a) Explain why in Matlab, conv(x,x), the convolution of x with x itself results into a vector with elements. b) Compare the equation of a convolution x[n]h[n]
with the equation of an autocorrelation
Then, prove that x[n]x[n]=R[n] and confirm it in Matlab observing that conv(x,fliplr(x)) and xcorr(x) lead to (approximately) the same result in Matlab. Plot conv(x,x) and xcorr(x). c) The results differ in b) mainly because xcorr uses a FFT to compute the correlation. Try to explain how the following code is used to compute the autocorrelation
% Autocorrelation % Compute correlation via FFT X = fft(x,2^nextpow2(2*M-1)); c = ifft(abs(X).^2);
You may want to use type xcorr and take a look at the source code to see how the vector c
above is modified to give the expected result (i.e., there is a postprocessing step after the
two lines above).
4.5. Short-time energy. Use the same procedure as before to record
the sentence “We were away” or similar. Calculate the speech energy
for each
frame of
milliseconds (ms), without overlap among frames. Use
ms to get four energy trajectories. Estimate the first-derivative of
using
. Estimate the
second-derivative using .
Use subplot to show simultaneously the waveform (subplot(411)) ,
(subplot(412)),
(subplot(413)) and
(subplot(414)). Do
that for each and
choose the value of
that leads to the best plots in terms of distinguishing when it is silence or speech.
4.6. Spectrograms. Use a function such as specgram to plot both the wide and
narrowband spectrograms of the sentence recorded in the previous exercise. In both cases, a)
what were the window lengths and equivalent bandwidths you used? b) What were the
complete commands?
4.7. Linear regression. Assume there are
points
, where
and
. Find the
parameters and
of a first order
polynomial
that best fits the data in terms of the minimum total squared error
. However,
try to write the two final equations using correlations (for example, the autocorrelation
at lag
is one
possible term). Use your equations to fit a line to the following training data: x=rand(1,100);
y=3*x+4+0.5*randn(1,100); plot(x,y,’x’) and plot the line superimposed to the training
data.
4.8. LPC analysis using the autocorrelation method. Assume we want to calculate a LPC
filter of order
for the signal
using the autocorrelation method. The 3-rd order predictor is given by the difference
equation
By convention, the LPC filter is given (in the Z-domain) as
and you can get it using lpc(x,3) in Matlab. a) Try to prove that the coefficients can be found by solving
where is the correlation at lag . b) One can note that the matrix in the equation above is symmetric and, besides, has equal elements along the diagonals. This is called a Toeplitz matrix. The matrix can be inverted with the Levinson-Durbin algorithm below, that is instead of a generic inversion method that is .
1function [a,k,E]=snip_frequency_Levinson_Durbin(R,p) 2% function [a,k,E]=snip_frequency_Levinson_Durbin(R,p) 3%Usage: x=randn(1,100)+linspace(1,5,100); p=10; R=xcorr(x,p); 4% R=R(p+1:end); %keep only values of interest: R(0)...R(p) 5% [a,k,E]=snip_frequency_Levinson_Durbin(R,p) 6%Inputs: 7% p - order of LPC analysis 8% R - p+1 sample correlation function values, R(0)...R(p) 9%Outputs: 10% a - p LPC coefficients, from a(1) to a(p) 11% k - p reflection coefficients, from k(1) to k(p) 12% E - E energies of error, from E(1) to E(p) 13%Initialization 14k(1)=R(1+1)/R(0+1); a(1)=k(1); E(1)=R(0+1)*(1-k(1)^2); 15%Recursion 16for i=2:p 17 k(i)=(R(i+1)-sum(a(1:i-1).*R(i:-1:2)))/E(i-1); 18 a(i)=k(i); 19 a(1:i-1)=a(1:i-1)-k(i)*a(i-1:-1:1); 20 E(i)=E(i-1)*(1-k(i)^2); 21end
The code above has errors, but it should give the same result as the function levinson in Matlab. For example, levinson([202 114 -2 -68],3) gives the right result, but my_durbin([202 114 -2 -68],3) does not. Unfortunately, levinson is a Mex (compiled) file and one cannot see the code. Consult a reference about LPC and fix the code above.