Lab 1 – Matlab
Basics
· Learn to record, save, and playback speech using Matlab.
· Use Matlab to plot the speech waveform.
· Learn the .wav file format.
· Get started using Matlab arrays.
· Listen to what you see.
Double click on the Matlab icon.
When Matlab is open, there is always a command window. That’s all you need for now.
Matlab online help is excellent. There is no need for manuals. The help includes tutorials. I suggest you do at least the array tutorial (outside of class) if you have not worked with Matlab before. Also learn how to use the editor and write and run a simple function.
· Make a recording of yourself saying “We were away a year ago.”
Make sure the microphone is on.
In the Matlab workspace window, type
Fs = 10000;
y = wavrecord(40000,Fs);
Hit return and after a slight pause (.5 second) say the sentence.
· Play the sentence you just recorded.
wavplay(y,Fs);
Now try
wavplay(y,Fs/2);
and
wavplay(y,Fs*2);
What happens? You have just done your first Computer Speech Processing.
wavwrite(y,Fs,'filename'); % creates a .wav file of the signal y.
signal = wavread('filename'); % reads in a signal from a .wav file.
[signal,Fs = wavread('filename');
% reads in a signal and the recording frequency, Fs, from a .wav file.
plot(y);
Then stretch the window so it runs from one side of the screen to the other.
My recording of “We were away a year ago.” is shown here.
Find the range of values for y. Type ‘max(y)’ and hit return with no ‘;’, same for min(y).
Now try mean(y).
You can see from the plot that there is a second of background noise at the start and end of my recording.
z = y(10001:30000); %
Creates a 2 second signal with mostly speech
10001:30000 make the new signal exactly 2 seconds long but any length will do.
Save your cropped signal as ‘YIaway’, where ‘YI’ is replaced by your initials.
· Plot and stretch your cropped signal.
· Guess where you the word boundaries are. There are 10000 samples to a second.
· Use your guesses to create single-word signal arrays for each of the words
‘we’ ‘were’ ‘away’ ‘a’ ‘year’ ‘ago’
From the plot above, I guessed that the word “ago” would be in the array:
ago=z(15500:20000);
But wavplay(ago,Fs); showed that I missed the start of the word.
ago=z(15400:20000);
seems to get the whole word.
· Rearrange your words to synthesize ‘a year away, were we ago?’ You can do this with:
· wavplay(a,Fs);wavplay(year,Fs);wavplay(away,Fs);wavplay(were,Fs);wavplay(we,Fs);wavplay(ago,Fs); % Type it all then hit return.
· A better way:
nonsense = cat(1, a, year, away, we, ago,
were);
wavplay(nonsense,Fs);
Listen to the new sentence and describe its quality. What seems wrong?
· Record, crop, and save these two sentences:
Should we chase those cowboys? (YIcowboy)
Early one morning a man and a woman ambled along a one mile lane.
(YIlane)
· Create words from “Should we chase those cowboys?”
· Synthesize the sentence “Cowboys chase those we should.”
· Synthesize the sentence “Cowboys should chase those away.”
Last Updated: January 14, 2004 5:54 p.m. by