Xu Ly Am Thanh
Xu Ly Am Thanh
Xu Ly Am Thanh
You will first need to transfer some sound files to your z:\ECE203
directory from my ftp site. To do this, go to
ftp://ftp.engr.udayton.edu/rhardie/ECE203/
Now, you want to copy the following files for this exercise (but
you might want to copy all the files for later):
road.wav
hootie.wav
lunch.au
flute.wav
tenorsax.wav
mutedtrumpet.wav
We want to read the digital sound data from the .wav file into
an array in our MATLAB workspace. We can then listen to it,
plot it, manipulate, etc. Use the following command at the
MATLAB prompt:
The left and right channel signals are the two columns of the
road array:
left=road(:,1);
right=road(:,2);
Let’s plot the left data versus time. Note that the plot will look
solid because there are so many data points and the screen
resolution can’t show them all. This picture shows you where
the signal is strong and weak over time.
time=(1/44100)*length(left);
t=linspace(0,time,length(left));
plot(t,left)
xlabel('time (sec)');
time=(1/44100)*2000;
t=linspace(0,time,2000);
plot(t,left(1:2000))
xlabel('time (sec)');
Another audio format is the .au file format. These files are read
in using
[lunch,fs2]=auread('lunch.au');
soundsc(lunch,fs2);
Reverse Playing
To play the sound backwards, we simply reverse the order of the numbers in the
arrays. Let’s experiment with a small array. Type in the following commands:
y=[1;2;3;4;5]
y2=flipud(y)
Note that flipud stands for flip upside-down which flips your array y and stores the
inverted array in a new array called y2.
soundsc(left2,fs)
Now let's add an echo to our sound data by adding to each sound sample, the sample from
a previous time:
for n=N+1:length(left)
end
Note that these arrays are large and it may take some time for the processing to be
completed. Compare the input and output by typing the following after the cursor
returns, indicating that the processing is done:
soundsc(left,fs) % original
% Wait until the sound stops before moving to next sound command
This program first sets the output to be the input. This is simply a quick way to initialize
the output array to the proper size (makes it operate faster). The loop starts at n=10001
and goes up to the full length of our array left. The output is the sum of the input at
sample time n plus the input at sample time n-10000 (10000 samples ago, 10000/44100
seconds ago since the samples are spaced by 1/44100 seconds). Try some different delay
amounts.
for n=N+1:length(road)
end
soundsc(road,fs) % original
soundsc(out,fs) % echo
Try the following variation on this theme, which keeps adding to the signal itself from
1000 samples ago slightly softened (multiplied by 0.8). Note that for this sound data the
samples are spaced by T=1/8192 sec (fs2=8192 samples/sec).
[lunch,fs2]=auread('lunch.au');
out=lunch; % set up a new array, same size as old one
for n=N+1:length(lunch)
end
soundsc(out,fs2) % echo
This echo process is like looking into a mirror and seeing a mirror with a reflection of the
first mirror, etc! The echo goes on forever, but gets slightly quieter each time.
The following program (or “digital filter”) is designed to soften high frequency
components from the signal (treble). It retains the low frequency components
(bass). Applying this digital filter has the same effect as turning down the treble tone
control on your stereo. The design of this code is not so obvious. The Electrical
Engineering students will learn more about this type of frequency selective digital
filtering in ECE334 Discrete Signals and Systems.
out=hootie;
for n=2:length(hootie)
out(n,1)=.9*out(n-1,1)+hootie(n,1); % left
out(n,2)=.9*out(n-1,2)+hootie(n,2); % right
end
Compare the input and output as before. Note that the modified signal sounds muffled in
comparison to the input data. This is because the high frequency components have been
suppressed in the output.
soundsc(hootie,fs) % original
A small change in our digital filter allows us to boost high frequencies and suppress low
frequencies:
out=hootie;
for n=2:length(hootie)
out(n,1)=hootie(n,1)-hootie(n-1,1); % left
out(n,2)=hootie(n,2)-hootie(n-1,2); % right
end
The sampling frequency fs tells us how much time goes between each sample
(T=1/fs). If we play the song with more or less time between samples than was originally
there when recorded, the speed will seem off, producing interesting effects...
soundsc(hootie,fs/1.5) % How slow can you go?
In most popular music recordings, the vocal track is the same on the left and right
channels (or very similar). The volume of the various instruments are more unevenly
distributed between the two channels. Since the voice is the same on both channels, what
would happen if we subtract one channel from the other and listen to the result?
You still hear some vocal here because this song uses a stereo reverberation effect and the
echo moves back and forth between left and right channels (like our stereo delay
above). This makes the voice unequal from left to right channels.