You are on page 1of 11

Department of Electrical and Computer Engineering

Digital Speech Processing


Problem Set No. 1 Solutions

Problem 1

Consider the sequence of values described by the difference equation:

y[n] = 2y[n 1] 0.5y[n 2]


with initial conditions:

y[1] = 0 (1)
y[2] = 2

(a) Solve for y[0], y[1], y[2], y[3]


(b) Determine an analytic solution for y[n] for all n
(c) If the limit of sequential terms is given by the factor G, i.e.,
 
y[n]
lim =G
n y[n 1]

determine G.

Solution

(a) Solve for y[0], y[1], y[2], y[3] as:

y[0] = 2 0 0.5 (2) = 1 (2)


y[1] = 2 1 0.5 (0) = 2
y[2] = 2 2 0.5 1 = 3.5
y[3] = 2 3.5 0.5 2 = 6

(b) We find the homogeneous solution of the difference equation by first de-
termining the z-transform and then solving for the roots of the second order
polynomial as follows:

Y (z)[1 2z 1 + 0.5z 2 ] = 0
with homogeneous solution of the form:

y[n] = a1 z1n + a2 z2n


Solving for the roots of the polynomial, z1,2 we get:

1
1 2
1 2z1,2 + 0.5z1,2 = 0 (3)
2
z1,2 2z1,2 + 0.5 = 0

We now solve for z1,2 as:


2
42
z1,2 = = 1 2/2 (4)
2
z1 = 1 + 2/2

z2 = 1 2/2

We now solve for a1 , a2 using the conditions on y[0] and y[1] giving:

y[0] = 1 a1 z10 + a2 z20 = a1 + a2 (5)



y[1] = 2 a1 z1 + a2 z2 = a1 (1 + 2/2) + a2 (1 2/2) = a1 + a2 + ( 2/2)(a1 a2 )

We can now solve for a1 , a2 as:

a1 + a2 = 1 (6)

a1 a2 = 2/ 2 = 2

1+ 2
a1 =
2
1 2
a2 =
2
giving the final solution as:
! !n ! !n
1+ 2 2 1 2 2
y[n] = 1+ + 1
2 2 2 2
(c) We solve for G as:

 
y[n]
G = lim (7)
n y[n 1]
 
2y[n 1] 0.5y[n 2]
= lim
n y[n 1]
 
0.5
= 2 lim
n y[n 1]/y[n 2]

= 2 0.5/G

giving the solution for G as (the positive root):

2
G2 2G + 0.5 = 0 (8)

G = 1 2/2 G = 1 + 2/2 = 1.707

Problem 2

An input signal, x[n], defined over the region < n < , is passed through
a cubic non-linearity yielding the output signal

y[n] = (x[n])3
(a) If the input to the system is of the form

x1 [n] = cos(0 n), < n <


determine the output spectrum, Y1 (ej ), and plot the magnitude of Y1 (ej )
(assuming 0 << S , the radian sampling frequency of the digital system).
Hint: recall the trigonometric relationships

1 cos(2x)
cos2 (x) = +
2 2
cos(3x) 3 cos(x)
cos3 (x) = +
4 4
(b) If the input to the system is the signal

x2 [n] = rn cos(0 n)u[n], |r| < 1


j
plot the magnitude of Y2 (e ) (again assuming 0 << S ) and assuming a value
of 0 = 2 500, r = 0.9 and FS = 10000 Hz.

Solution

(a) Using the trigonometric relationships we get:

y1 [n] = x[n]3 = cos3 (0 n)


1 3
= cos(30 n) + cos(0 n)
4 4
ej30 n ej30 n 3ej0 n 3ej0 n
= + + +
8 8 8 8
1 3
Y1 (ej ) = [( 30 ) + ( + 30 )] + [( 0 ) + ( + 0 )]
8 8
A plot of the magnitude response of Y1 (ej ) is shown in Figure 1.

3
Figure 1: Magnitude spectrum of cubed cosine wave.

(b) For the input x2 [n] we get an output of the form:

y2 [n] (rn cos(0 n)u[n])3 = (r3n u[n]) [cos3 (0 n)]


=
1
= (r3n u[n])[ [cos(30 n) + 3 cos(0 n)]
4
j 1
Y2 (e ) = Y1 (ej )
1 r3 ej
The resulting log magnitude plots are shown in Figure 2, where we show log
magnitude spectra for the original signal (top panel), the modulation signal,
1
(middle panel), and the cubed signal, Y2 (ej ) (bottom panel).
1 r3 ej

Figure 2: Log magnitude spectrum of modulated and cubed cosine wave.

4
Problem 3

Consider the first order system:

y[n] = y[n 1] + x[n]

(a) Find the system function, H(z), for this system.


(b) Find the causal impulse response of this system.
(c) For what values of will the system be stable?
(d) Assume that the input is obtained by sampling with period T . Find the
value of such that

h[n] < e1 for nT > 2 msec


i.e., find the value of that gives a time constant of 2 msec.

Solution

(a) The system function is found by taking z-transforms of the difference equa-
tion giving:

Y (z) = z 1 Y (z) + X(z)


Y (z)(1 z 1 ) = X(z)
Y (z) 1
H(z) = =
X(z) 1 z 1
1
(b) Note that the term can have two different inverse transforms
1 z 1
depending on the region of convergence. Since the difference equation indicates
a causal (right-sided) sequence, the appropriate inverse z-transform is:

h[n] = n u[n]
where we used the fact that


X 1
rn = , |r| < 1
n=0
1r

X
X
n
H(z) = x[n]z = (z 1 )n
n=0 n=0

(c) BIBO stability requires || < 1.


2 103 0.002
(d) h[n] = n u[n] = e1 , n = = . Solving for we get
T T

5
()0.002/T = e1
T
ln =
2 103
= exp[500T ]

Problem 4

(a) An analog signal, xa (t) = A cos(2200t), is sampled at a rate of FS =


10, 000 Hz, giving the digital signal x1 [n]. Sketch the resulting digital frequency
response, X1 (ej ).
(b) A second analog signal, xb (t) = B cos(2201t) is also sampled at a rate
of FS = 10, 000 Hz, giving the digital signal x2 [n]. Again sketch the resulting
digital frequency response, X2 (ej ).
(c) Are either (or both) digital signals, x1 [n] or x2 [n], periodic digital signals,
and if so, what are their periods?

Solution

(a) The digital signal,x1 [n], resulting from sampling xa (t), with sampling
rate FS = 10000 Hz, can be written in the form:

x1 [n] = A cos(2200n/FS ) (9)


A
= [ej2200n/10000 + ej2200n/10000 ] (10)
2
A
= [ej2n/50 + ej2n/50 ] (11)
2
which has a frequency response, X1 (ej ), consisting of impulses at frequencies
200 Hz. A sketch of the digital frequency response is shown in the top panel
of Figure 3.
(b) In a similar manner, we can solve for the digital frequency response,
X2 (ej ), resulting from sampling xb (t), with sampling rate FS = 10000 Hz,
resulting in:
B
x2 [n] = [ej2201n/FS + ej2201n/FS ] (12)
2
which has a frequency response X2 (ej ), consisting of impulses at frequencies
201 Hz. A sketch of the digital frequency response is shown in the bottom
panel of Figure 3.
(c) A digital signal, x[n], is periodic with period P samples, if it obeys the
relation:
x[n + P ] = x[n] for all n and for P > 0 (13)
It is clear that x1 [n] is periodic and of period P = 50 samples. It is somewhat
more difficult to see that the signal x2 [n] is also periodic but of period P = 10000

6
Figure 3: Frequency responses of the two signals.

samples since the cosine function satisfies the relationship:

cos(a + b) = cos(a) cos(b) sin(a) sin(b) (14)


x2 [n + 10000] = cos(2201(n + 10000)/10000) (15)
= cos(2201n/10000) cos(2201) (16)
sin(2201n/10000) sin(2201) (17)
= cos(2201n/10000) = x2 [n] (18)

since cos(2201) = 1 and sin(2201) = 0 in the above equation.

Problem 5

Write a MATLAB program to do the following:

1. accept an arbitrary speech filename and load the file (filename.wav) using
the loadwav command given on the webpage, or the native MATLAB
wavload command.

2. listen to the speech file using the MATLAB sound command. (Pay atten-
tion to the required scaling for the speech file). Write down the sentence
that you heard.

7
3. plot the sample values of the speech at N msec/line, 4 lines/page, where
N is specified at run time.

Use the file s3.wav (from the website) as your test, with N equivalent to 250
msec of speech per line.

Solution

The following MATLAB code achieves the goals listed above:

% homework 1--plot_speech_file.m
% speech_waveform_plotting_program.m
% read in waveform for a speech file and plot the samples, 4 lines to a page
%
% [xin,fs,mode,format]=loadwav(ah_truncated.wav);xin)
filename=input(enter speech filename:,s);
[xin,fs,mode,format]=loadwav(filename);

% normalize input to [-1,1] range and play out sound file


xinn=xin/max(xin);
sound(xinn,fs);
xin=xinn;

% clear graphics screen and plot waveform


clf;
[nrows ncol]=size(xin);
stitle=sprintf(file: %s, number of samples in file: %d,filename,nrows);
plot(xin), title(stitle),ylabel(amplitude), xlabel(sample number);

% print out number of samples in file, read in plotting parameters


fprintf( number of samples in file: %7.0f \n, nrows);
n=input(enter number of samples of speech file to plot:);
vstart=input(enter starting sample in file:);
m=input(enter number of samples per line for plotting:);

% store speech to be plotted and plot at 4 lines per page


xins=xin(vstart:vstart+n-1);
ymin=min(xin(vstart:vstart+n-1));
ymax=max(xin(vstart:vstart+n-1));
ymin=-1;
ymax=1;

% append m zeros at end of file to fill out lines


xins(vstart+n:vstart+n+m-1)=0;

8
% create vector of indices for each line
ns=(vstart:vstart+n-1);

% append indices for appended zeros


ns=[ns vstart+n:vstart+n+m-1];

% determine the number of lines to plot


nlines=ceil(n/m);
figure;
% clf;
for i=0:nlines-1;
subplot(4,1,mod(i,4)+1), plot(ns(i*m+1:(i+1)*m),xins(i*m+1:(i+1)*m));
axis([i*m+1 (i+1)*m ymin ymax]);
if (mod(i,4) == 0)
stitle1=sprintf(file: %s, starting sample: %d,filename,i*m+1);
title(stitle1);
end
if(mod(i,4) == 3)
if (i ~= nlines-1)
figure;
end
end
end

The speech utterance in the file s3.wav is the sentence Add the sum to the
product of these three, spoken by a female talker. Plots of the waveform
with 250 msec per line are shown below, along with a strips plot of the entire
waveform on a single plot.

9
file: s3, starting sample: 1
1

1
200 400 600 800 1000 1200 1400 1600 1800 2000
1

1
2200 2400 2600 2800 3000 3200 3400 3600 3800 4000
1

1
4200 4400 4600 4800 5000 5200 5400 5600 5800 6000
1

1
6200 6400 6600 6800 7000 7200 7400 7600 7800 8000

file: s3, starting sample: 8001


1
0
1
8200 8400 8600 8800 9000 9200 9400 9600 9800 10000

1
0
1
1.02 1.04 1.06 1.08 1.1 1.12 1.14 1.16 1.18 1.2
4
x 10
1
0
1
1.22 1.24 1.26 1.28 1.3 1.32 1.34 1.36 1.38 1.4
4
x 10
1
0
1
1.42 1.44 1.46 1.48 1.5 1.52 1.54 1.56 1.58 1.6
4
x 10

10
file: s3, starting sample: 16001
1
0
1
1.62 1.64 1.66 1.68 1.7 1.72 1.74 1.76 1.78 1.8
4
x 10
1
0
1
1.82 1.84 1.86 1.88 1.9 1.92 1.94 1.96 1.98 2
4
x 10
1
0
1
2.02 2.04 2.06 2.08 2.1 2.12 2.14 2.16 2.18 2.2
4
x 10
1
0
1
2.22 2.24 2.26 2.28 2.3 2.32 2.34 2.36 2.38 2.4
4
x 10

file: s3, sampling rate: 8000, starting sample: 1 number of samples 24000

2000

4000

6000

8000
samples offset

10000

12000

14000

16000

18000

20000

22000

0 500 1000 1500 2000


sample number

11

You might also like