Digital Signal Processing
Lab 1
Exercise 1
Read and write sounds in .wav format.
Some sound files: piano.wav, alligators.wav, bird.wav
Use the command
[y,fs,bits] = wavread(‘filename.wav’);
to read a WAVE file.
Then use the command to play the sound.
sound(y,Fs);
Finally, output the vector y to a new WAVE file
wavwrite(y,fs,bits,’filename.wav’);
Exercise 2
Discrete-time sequences.
1. Discrete-time impulse (Page 11)
n = -10:20;
y = zeros(1, 31);
n0 = 10;
y(n0-n(1)+1) = 1;
stem(n, y);
2. Unit-step sequence (Page 11)
n = -10:20;
y = zeros(1, 31);
n0 = 10;
y(n0-n(1)+1:31) = 1;
stem(n, y);
3. Exponential sequence (Page 13)
n = -10:20;
y = 2*exp(-0.5*n);
stem(n, y);
4. Sinusoidal sequence (Page 13-14)
n = -10:20;
y = 2*cos(pi/4*n);
stem(n, y);
y = 2*sin(pi/7.3*n);
stem(n, y);
y = exp(j*pi/6*n);
subplot(211)
stem(n, real(y));
subplot(212)
stem(n, imag(y));
5. Combined
n = -10:20;
y = exp(-0.1*n+j*(pi/6*n+pi/4));
subplot(211)
stem(n, real(y));
subplot(212)
stem(n, imag(y));
Exercise 3
Linear constant-coefficient difference equations
1. An accumulator (Page 34, Example 2.14)
n = -10:20;
x = (0.9).^n.*cos(pi/6*n+pi/4);
a = [1 -1];
b = [1];
y = filter(b, a, x);
subplot(211)
stem(n, x);
subplot(212)
stem(n, y);
2. An accumulator with an impulse input
n = -10:20;
x_impulse = zeros(1, 31);
n0 = 0;
x_impulse(n0-n(1)+1) = 1;
a = [1 -1];
b = [1];
y = filter(b, a, x_impulse);
subplot(211)
stem(n, x_impulse);
subplot(212)
stem(n, y);
3. A moving-average system (Page 35, Example 2.15)
n = -10:20;
x = (0.9).^n.*cos(pi/6*n+pi/4);
M2 = 6;
a = [1];
b = (1/(M2+1))*ones(1,M2);
y = filter(b, a, x);
subplot(211)
stem(n, x);
axis([-10 20 –3 3])
subplot(212)
stem(n, y);
axis([-10 20 –3 3])
4. A moving-average system with an impulse input
M2 = 6;
a = [1];
b = (1/(M2+1))*ones(1,M2);
y = filter(b, a, x_impulse);
subplot(211)
stem(n, x_impulse);
subplot(212)
stem(n, y);
5. Recursive computation of difference equations (Page 37, Example 2.16)
n = -10:20;
x = (0.9).^n.*cos(pi/6*n+pi/4);
a = [1 -0.9];
b = [1];
y = filter(b, a, x);
subplot(211)
stem(n, x);
axis([-10 20 -5 5])
subplot(212)
stem(n, y);
axis([-10 20 -5 5])
6. Recursive computation of difference equations with an impulse input
a = [1 -0.9];
b = [1];
y = filter(b, a, x_impulse);
subplot(211)
stem(n, x_impulse);
axis([-10 20 -2 2])
subplot(212)
stem(n, y);
axis([-10 20 -2 2])
Exercise 4
Convolution (Page 24)
n = -10:20;
x = zeros(1, 31);
x(-2+10+1) = 0.8; x(0+10+1) = 1; x(3+10+1) = -0.5;
h = [1 2/3 1/3];
y = conv(h,x);
stem(-10:22, y);
Sources:
Fundamentals of Digital Signal Processing, by Joyce Van de Vegte, Prentice Hall, 2002.