lab9b

download lab9b

of 8

Transcript of lab9b

  • 8/8/2019 lab9b

    1/8

    Purdue University: ECE438 - Digital Signal Processing with Applications 1

    ECE438 - Laboratory 9:Speech Processing (Week 2)October 10, 2008

    1 Introduction

    This is the second part of a two week experiment. During the rst week we discussed basicproperties of speech signals, and performed some simple analyses in the time and frequencydomain.

    This week, we will introduce a system model for speech production. We will cover somebackground on linear predictive coding , and the nal exercise will bring all the prior materialtogether in a speech coding exercise.

    1.1 A Speech Model

    DT ImpulseTrain

    WhiteNoise

    Voiced Sounds

    Unvoiced Sounds

    Vocal TractLTI, all-pole filter

    V(z)

    x(n) s(n)

    speechsignal

    Tp

    G

    Figure 1: Discrete-Time Speech Production Model

    From a signal processing standpoint, it is very useful to think of speech production interms of a model, as in Figure 1. The model shown is the simplest of its kind, but it includesall the principal components. The excitations for voiced and unvoiced speech are represented

    Questions or comments concerning this laboratory should be directed to Prof. Charles A. Bouman,School of Electrical and Computer Engineering, Purdue University, West Lafayette IN 47907; (765) 494-0340; [email protected]

    http://www.purdue.edu/VISE/ee438L/lab9/pdf/lab9a.pdfhttp://www.purdue.edu/VISE/ee438L/lab9/pdf/lab9a.pdf
  • 8/8/2019 lab9b

    2/8

    Purdue University: ECE438 - Digital Signal Processing with Applications 2

    by an impulse train and white noise generator, respectively. The pitch of voiced speech iscontrolled by the spacing between impulses, T p, and the amplitude (volume) of the excitationis controlled by the gain factor G .

    As the acoustical excitation travels from its source (vocal cords, or a constriction), theshape of the vocal tract alters the spectral content of the signal. The most prominent effectis the formation of resonances, which intensies the signal energy at certain frequencies(called formants ). As we learned in the Digital Filter Design lab, the amplication of certainfrequencies may be achieved with a linear lter by an appropriate placement of poles in thetransfer function. This is why the lter in our speech model utilizes an all-pole LTI lter.A more accurate model might include a few zeros in the transfer function, but if the orderof the lter is chosen appropriately, the all-pole model is sufficient. The primary reasonfor using the all-pole model is the distinct computational advantage in calculating the ltercoefficients, as will be discussed shortly.

    Recall that the transfer function of an all-pole lter has the form

    V (z) =

    1

    1 P k =1 a k z k (1)where P is the order of the lter. This is an IIR lter that may be implemented with arecursive difference equation. With the input G x(n ), the speech signal s (n ) may be writtenas

    s (n ) =P

    k =1a k s(n k) + G x(n ) (2)

    Keep in mind that the lter coefficients will change continuously as the shape of the vocaltract changes, but speech segments of an appropriately small length may be approximatedby a time-invariant model.

    This speech model is used in a variety of speech processing applications, including meth-ods of speech recognition, speech coding for transmission, and speech synthesis. Each of theseapplications of the model involves dividing the speech signal into short segments, over whichthe lter coefficients are almost constant. For example, in speech transmission the bit ratecan be signicantly reduced by dividing the signal up into segments, computing and sendingthe model parameters for each segment (lter coefficients, gain, etc.), and re-synthesizingthe signal at the receiving end, using a model similar to Figure 1. Most telephone systemsuse some form of this approach. Another example is speech recognition. Most recognitionmethods involve comparisons between short segments of the speech signals, and the ltercoefficients of this model are often used in computing the difference between segments.

    1.2 Synthesis of Voiced Speech

    Download coeff.mat

    Download the le coeff.mat and load it into the Matlab workspace using the load command. This will load three sets of lter coefficients: A1, A2, and A3 for the vocal tract

    http://www.ece.purdue.edu/VISE/ee438L/lab9/data/coeff.ziphttp://www.ece.purdue.edu/VISE/ee438L/lab9/data/coeff.ziphttp://www.ece.purdue.edu/VISE/ee438L/lab9/data/coeff.ziphttp://www.ece.purdue.edu/VISE/ee438L/lab9/data/coeff.zip
  • 8/8/2019 lab9b

    3/8

    Purdue University: ECE438 - Digital Signal Processing with Applications 3

    model in equations (1) and (2). Each vector contains coefficients {a 1 , a 2 , . . . , a 15 } for anall-pole lter of order 15.

    We will now synthesize voiced speech segments for each of these sets of coefficients. Firstwrite a Matlab function x=exciteV(N,Np) which creates a length N excitation for voicedspeech, with a pitch period of Np samples. The output vector x should contain a discrete-time impulse train with period Np (e.g. [1 0 0 0 1 0 0 ]).

    Assuming a sampling frequency of 8 kHz (0.125 ms/sample), create a 40 millisecond-long excitation with a pitch period of 8 ms, and lter it using equation (2) for each set of coefficients. For this, you may use the command

    s = filter(1,[1 -A],x)where A is the row vector of lter coefficients (see Matlabs help on lter for details). Ploteach of the three ltered signals. Use subplot() and orient tall to place them in thesame gure.

    We will now compute the frequency response of each of these lters. The frequencyresponse may be obtained by evaluating Eq. (1) at points along z = e j . Matlab willcompute this with the command [H,W]=freqz(1,[1 -A],512) , where A is the vector of coefficients. Plot the magnitude of each response versus frequency in Hertz. Use subplot()and orient tall to plot them in the same gure.

    The location of the peaks in the spectrum correspond to the formant frequencies. Foreach vowel signal, estimate the rst three formants (in Hz) and list them in the gure.

    Now generate the three signals again, but use an excitation which is 1-2 seconds long.Listen to the ltered signals using soundsc . Can you hear qualitative differences in thesignals? Can you identify the vowel sounds?

    INLAB REPORT:

    Hand in the following: A gure containing the three time-domain plots of the voiced signals.

    Plots of the frequency responses for the three lters. Make sure to label the frequencyaxis in units of Hertz.

    For each of the three lters, list the approximate center frequency of the rst threeformant peaks.

    Comment on the audio quality of the synthesized signals.

  • 8/8/2019 lab9b

    4/8

    Purdue University: ECE438 - Digital Signal Processing with Applications 4

    2 Linear Predictive Coding

    The lter coefficients which were provided in the previous section were determined using atechnique called linear predictive coding (LPC). LPC is a fundamental component of manyspeech processing applications, including compression, recognition, and synthesis.

    In the following discussion of LPC, we will view the speech signal as a discrete-timerandom process.

    2.1 Forward Linear Prediction

    Suppose we have a discrete-time random process {..., S 1 , S 0 , S 1 , S 2 ,... } whose elements havesome degree of correlation. The goal of forward linear prediction is to predict the sample S nusing a linear combination of the previous P samples.

    S n =P

    k =1

    a k S n k (3)

    P is called the order of the predictor. We may represent the error of predicting S n by arandom sequence en .

    en = S n S n (4)

    en = S n P

    k =1a k S n k (5)

    An optimal set of prediction coefficients a k for (5) may be determined by minimizing themean-square error E [e2n ]. Note that since the error is generally a function of n , the predictioncoefficients will also be functions of n . To simplify notation, let us rst dene the following

    column vectors. a = [a 1 a 2 a P ]T

    Sn,P = [S n 1 S n 2 S n P ]T

    Then,

    E [e2n ] = E S n P

    k =1a k S n k

    2

    (6)

    = E S n aT Sn,P 2

    (7)

    = E S 2n 2S n aT Sn,P + aT Sn,P aT Sn,P (8)

    = E S 2n 2aT E [S n Sn,P ] + aT E Sn,P ST n,P a (9)

    The second and third terms of equation (9) may be written in terms of the autocorrelationsequence r SS (k, l ).

    E [S n Sn,P ] =

    E [S n S n 1 ]E [S n S n 2 ]

    ...E [S n S n P ]

    =

    r SS (n, n 1)r SS (n, n 2)

    ...r SS (n, n P )

    r S (10)

  • 8/8/2019 lab9b

    5/8

    Purdue University: ECE438 - Digital Signal Processing with Applications 5

    E Sn,P ST n,P = E

    S n 1 S n 1 S n 1 S n 2 S n 1 S n P S n 2 S n 1 S n 2 S n 2 S n 2 S n P

    ...... . . .

    ...S

    n

    P S

    n 1 S

    n

    P S

    n 2 S

    n

    P S

    n

    P

    =

    r SS (n 1, n 1) r SS (n 1, n 2) r SS (n 1, n P )r SS (n 2, n 1) r SS (n 2, n 2) r SS (n 2, n P )

    ...... . . .

    ...r SS (n P, n 1) r SS (n P, n 2) r SS (n P, n P )

    R S (11)

    Substituting into equation (9), the mean-square error may be written as

    E e2n = E S 2n 2a

    T r S + aT R S a (12)

    Note that while a and r S are vectors, and R S is a matrix, the expression in (12) is still ascalar quantity.

    To nd the optimal a k coefficients, which we will call a , we differentiate equation (12)with respect to the vector a (compute the gradient), and set it equal to the zero vector.

    a E e2n = 2r S + 2 R S a 0 (13)

    Solving,R S a = r S (14)

    The vector equation in (14) is a system of P scalar linear equations, which may be solvedby inverting the matrix R S .

    Note from (10) and (11) that r S and R S are generally functions of n . However, if S nis wide-sense stationary, the autocorrelation function is only dependent on the difference

    between the two indices, r SS (k, l ) = r SS (|k l|). Then R S and r S are no longer dependenton n , and may be written as follows.

    r S =

    r SS (1)r SS (2)

    ...r SS (P )

    (15)

    R S =

    r SS (0) r SS (1) r SS (P 1)r SS (1) r SS (0) r SS (P 2)

    r SS (2) r SS (1) r SS (P 3)...... . . .

    ...r SS (P 1) r SS (P 2) r SS (0)

    (16)

    Therefore, if S n is wide-sense stationary, the optimal a k coefficients do not depend on n .In this case, it is also important to note that R S is a Toeplitz (constant along diagonals)and symmetric matrix, which allows (14) to be solved efficiently using the Levinson-Durbinalgorithm (see [2]). This property is essential for many real-time applications of linearprediction.

  • 8/8/2019 lab9b

    6/8

  • 8/8/2019 lab9b

    7/8

  • 8/8/2019 lab9b

    8/8

    Purdue University: ECE438 - Digital Signal Processing with Applications 8

    1. Check if current frame is voiced or unvoiced.

    2. Generate the frame of speech by using the appropriate excitation into the lter speciedby the LPC coefficients (you did this in section 1.2). For voiced speech, use a pitchperiod of 7.5 ms. Make sure your synthesized segment is the same length as the original

    frame.3. Scale the amplitude of the segment so that the synthesized segment has the same

    energy as the original.

    4. Append the frame to the end of the output vector.

    Listen to the original and synthesized phrase. Can you recognize the synthesized versionas coming from the same speaker? What are some possible ways to improve the quality of the synthesized speech? Subplot the two speech signals in the same gure.

    INLAB REPORT:Hand in the following:

    Your analysis and synthesis code.

    The compression ratio.

    Plots of the original and synthesized words.

    Comment on the quality of your synthesized signal. How might the quality be im-proved?

    References

    [1] J. R. Deller, Jr., J. G. Proakis, J. H. Hansen, Discrete-Time Processing of Speech Signals,Macmillan, New York, 1993.

    [2] J. G. Proakis and D. G. Manolakis, Digital Signal Processing, 3rd edition , Prentice-Hall,Englewood Cliffs, New Jersey, 1996.